From c371fa4396c7bc3e62636885fe12f09c28a98226 Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Wed, 21 Aug 2013 10:02:54 -0400 Subject: [PATCH] lttng: fix empty string handling in dialogs (bug 415580) Change-Id: I9839ec7d8238556809cad48a39e44d72736c4544 Signed-off-by: Bernd Hufmann Reviewed-on: https://git.eclipse.org/r/15713 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam IP-Clean: Matthew Khouzam Tested-by: Matthew Khouzam --- .../control/dialogs/EnableChannelDialog.java | 34 ++++++++++--------- .../dialogs/EnableKernelEventComposite.java | 24 ++++++------- .../dialogs/EnableUstEventsComposite.java | 18 +++++----- .../control/dialogs/GetEventInfoDialog.java | 2 +- .../control/messages/messages.properties | 6 ++-- 5 files changed, 43 insertions(+), 41 deletions(-) diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableChannelDialog.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableChannelDialog.java index 6dbf51ecd3..9a927d0f06 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableChannelDialog.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableChannelDialog.java @@ -506,46 +506,48 @@ public class EnableChannelDialog extends Dialog implements IEnableChannelDialog @Override protected void okPressed() { // Set channel information - fChannelInfo = new ChannelInfo(fChannelNameText.getText()); - fChannelInfo.setSubBufferSize(fSubBufferSizeText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fSubBufferSizeText.getText())); - fChannelInfo.setNumberOfSubBuffers(fNumberOfSubBuffersText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fNumberOfSubBuffersText.getText())); - fChannelInfo.setSwitchTimer(fSwitchTimerText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fSwitchTimerText.getText())); - fChannelInfo.setReadTimer(fReadTimerText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fReadTimerText.getText())); - fChannelInfo.setOverwriteMode(fOverwriteModeButton.getSelection()); + ChannelInfo channelInfo = new ChannelInfo(fChannelNameText.getText()); + channelInfo.setSubBufferSize(fSubBufferSizeText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fSubBufferSizeText.getText())); + channelInfo.setNumberOfSubBuffers(fNumberOfSubBuffersText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fNumberOfSubBuffersText.getText())); + channelInfo.setSwitchTimer(fSwitchTimerText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fSwitchTimerText.getText())); + channelInfo.setReadTimer(fReadTimerText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fReadTimerText.getText())); + channelInfo.setOverwriteMode(fOverwriteModeButton.getSelection()); if (fTargetNodeComponent.isTraceFileRotationSupported()) { - fChannelInfo.setMaxSizeTraceFiles(fMaxSizeTraceText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fMaxSizeTraceText.getText())); - fChannelInfo.setMaxNumberTraceFiles(fMaxNumberTraceText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fMaxNumberTraceText.getText())); + channelInfo.setMaxSizeTraceFiles(fMaxSizeTraceText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fMaxSizeTraceText.getText())); + channelInfo.setMaxNumberTraceFiles(fMaxNumberTraceText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fMaxNumberTraceText.getText())); } if (fTargetNodeComponent.isBufferTypeConfigSupported()) { if (fSharedBuffersButton.getSelection()) { - fChannelInfo.setBufferType(BufferType.BUFFER_SHARED); + channelInfo.setBufferType(BufferType.BUFFER_SHARED); } else if (fPIDBuffersButton.getSelection()) { - fChannelInfo.setBufferType(BufferType.BUFFER_PER_PID); + channelInfo.setBufferType(BufferType.BUFFER_PER_PID); } else if (fUIDBuffersButton.getSelection()) { - fChannelInfo.setBufferType(BufferType.BUFFER_PER_UID); + channelInfo.setBufferType(BufferType.BUFFER_PER_UID); } else { - fChannelInfo.setBufferType(BufferType.BUFFER_TYPE_UNKNOWN); + channelInfo.setBufferType(BufferType.BUFFER_TYPE_UNKNOWN); } } fIsKernel = fKernelButton.getSelection(); // Check for invalid names - if (!fChannelInfo.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ + if (!channelInfo.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ MessageDialog.openError(getShell(), Messages.TraceControl_EnableChannelDialogTitle, - Messages.TraceControl_InvalidChannelNameError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ + Messages.TraceControl_InvalidChannelNameError + " (" + channelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ return; } // Check for duplicate names - if (fDomain != null && fDomain.containsChild(fChannelInfo.getName())) { + if (fDomain != null && fDomain.containsChild(channelInfo.getName())) { MessageDialog.openError(getShell(), Messages.TraceControl_EnableChannelDialogTitle, - Messages.TraceControl_ChannelAlreadyExistsError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ + Messages.TraceControl_ChannelAlreadyExistsError + " (" + channelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ return; } + fChannelInfo = channelInfo; + // validation successful -> call super.okPressed() super.okPressed(); } diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableKernelEventComposite.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableKernelEventComposite.java index 812e5cfb45..3f7c1cb0a8 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableKernelEventComposite.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableKernelEventComposite.java @@ -269,7 +269,9 @@ public class EnableKernelEventComposite extends Composite implements IEnableKern if (fIsDynamicProbe) { String temp = fProbeEventNameText.getText(); - if (!temp.matches("^[\\s]{0,}$") && !temp.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (temp.isEmpty() || + fProbeText.getText().matches("\\s*") || //$NON-NLS-1$ + (!temp.matches("^[\\s]{0,}$") && !temp.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$ MessageDialog.openError(getShell(), Messages.TraceControl_EnableEventsDialogTitle, Messages.TraceControl_InvalidProbeNameError + " (" + temp + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -277,11 +279,9 @@ public class EnableKernelEventComposite extends Composite implements IEnableKern return false; } - if(!fProbeText.getText().matches("\\s*")) { //$NON-NLS-1$ - fProbeEventName = temp; - // fProbeString will be validated by lttng-tools - fProbeString = fProbeText.getText(); - } + fProbeEventName = temp; + // fProbeString will be validated by lttng-tools + fProbeString = fProbeText.getText(); } // initialize function string @@ -289,7 +289,9 @@ public class EnableKernelEventComposite extends Composite implements IEnableKern fFunctionString = null; if (fIsDynamicFunctionProbe) { String functionTemp = fFunctionEventNameText.getText(); - if (!functionTemp.matches("^[\\s]{0,}$") && !functionTemp.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (functionTemp.isEmpty() || + functionTemp.matches("\\s*") || //$NON-NLS-1$ + (!functionTemp.matches("^[\\s]{0,}$") && !functionTemp.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$ MessageDialog.openError(getShell(), Messages.TraceControl_EnableEventsDialogTitle, Messages.TraceControl_InvalidProbeNameError + " (" + functionTemp + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -297,11 +299,9 @@ public class EnableKernelEventComposite extends Composite implements IEnableKern return false; } - if(!fFunctionText.getText().matches("\\s*")) { //$NON-NLS-1$ - fFunctionEventName = functionTemp; - // fFunctionString will be validated by lttng-tools - fFunctionString = fFunctionText.getText(); - } + fFunctionEventName = functionTemp; + // fFunctionString will be validated by lttng-tools + fFunctionString = fFunctionText.getText(); } return true; diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableUstEventsComposite.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableUstEventsComposite.java index 15f0eb93a4..3e7329aff0 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableUstEventsComposite.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/EnableUstEventsComposite.java @@ -282,7 +282,9 @@ public class EnableUstEventsComposite extends Composite implements IEnableUstEve } String temp = fLogLevelEventNameText.getText(); - if (!temp.matches("^[\\s]{0,}$") && !temp.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (temp.isEmpty() || + temp.matches("\\s*") || //$NON-NLS-1$ + (!temp.matches("^[\\s]{0,}$") && !temp.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$ MessageDialog.openError(getShell(), Messages.TraceControl_EnableEventsDialogTitle, Messages.TraceControl_InvalidLogLevelEventNameError + " (" + temp + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -290,9 +292,7 @@ public class EnableUstEventsComposite extends Composite implements IEnableUstEve return false; } - if(!temp.matches("\\s*")) { //$NON-NLS-1$ - fLogLevelEventName = temp; - } + fLogLevelEventName = temp; TraceLogLevel[] levels = TraceLogLevel.values(); int id = fLogLevelCombo.getSelectionIndex(); @@ -311,7 +311,9 @@ public class EnableUstEventsComposite extends Composite implements IEnableUstEve fWildcard = null; if (fIsWildcard) { String tempWildcard = fWildcardText.getText(); - if (!tempWildcard.matches("^[\\s]{0,}$") && !tempWildcard.matches("^[a-zA-Z0-9\\-\\_\\*]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (tempWildcard.isEmpty() || + tempWildcard.matches("\\s*") || //$NON-NLS-1$ + (!tempWildcard.matches("^[\\s]{0,}$") && !tempWildcard.matches("^[a-zA-Z0-9\\-\\_\\*]{1,}$"))) { //$NON-NLS-1$ //$NON-NLS-2$ MessageDialog.openError(getShell(), Messages.TraceControl_EnableEventsDialogTitle, Messages.TraceControl_InvalidWildcardError + " (" + tempWildcard + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -319,9 +321,7 @@ public class EnableUstEventsComposite extends Composite implements IEnableUstEve return false; } - if(!tempWildcard.matches("\\s*")) { //$NON-NLS-1$ - fWildcard = tempWildcard; - } + fWildcard = tempWildcard; } // initialize filter with null @@ -329,7 +329,7 @@ public class EnableUstEventsComposite extends Composite implements IEnableUstEve if (fProviderGroup.isEventFilteringSupported()) { String tempFilter = fFilterText.getText(); - if(!tempFilter.matches("\\s*")) { //$NON-NLS-1$ + if(!tempFilter.isEmpty() && !tempFilter.matches("\\s*")) { //$NON-NLS-1$ fFilterExpression = tempFilter; } } diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/GetEventInfoDialog.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/GetEventInfoDialog.java index 28ebd7fb4c..15fcadc9d9 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/GetEventInfoDialog.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/GetEventInfoDialog.java @@ -271,7 +271,7 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog { if (fSessions[0].isEventFilteringSupported() && !fIsKernel) { String tempFilter = fFilterText.getText(); - if(!tempFilter.matches("\\s*")) { //$NON-NLS-1$ + if(!tempFilter.isEmpty() && !tempFilter.matches("\\s*")) { //$NON-NLS-1$ fFilterExpression = tempFilter; } } diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/messages.properties b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/messages.properties index 4d2dcad4ef..89de0b4eed 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/messages.properties +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages/messages.properties @@ -177,9 +177,9 @@ TraceControl_EnableEventsLoglevelEventNameTooltip=Event name for enabling log le TraceControl_EnableEventsFilterGroupName=Filter Expression TraceControl_EnableEventsFilterTooltip=Filter expression on event field. -TraceControl_InvalidProbeNameError=The probe name is invalid -TraceControl_InvalidWildcardError=The wild card name is invalid -TraceControl_InvalidLogLevelEventNameError=The event name for log level is invalid +TraceControl_InvalidProbeNameError=The probe name is invalid or empty +TraceControl_InvalidWildcardError=The wild card name is invalid or empty +TraceControl_InvalidLogLevelEventNameError=The event name for log level is invalid or empty TraceControl_InvalidLogLevel=No log level selected TraceControl_AddContextDialogTitle=Add Contexts -- 2.34.1