Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstantTimer; enter non-numeric throws NumberFormatException #763

Closed
asfimport opened this issue Sep 15, 2001 · 9 comments
Closed

ConstantTimer; enter non-numeric throws NumberFormatException #763

asfimport opened this issue Sep 15, 2001 · 9 comments

Comments

@asfimport
Copy link
Collaborator

khammond25 (Bug 3638):
For the ConstantTimer element, if you enter a non-numeric in the "Constant
Delay" field, a java.lang.NumberFormatException error is thrown.

Also, a java.lang.NumberFormatException can be thrown when editing the field.

For example, enter 100 in the "Constant Delay" field. Next, use the BACKSPACE
key to delete 100 and enter 300. When you deleted 100, the field was
automatically converted to a number. Of course, the field was empty because we
just deleted the 100. So, an exception was thrown.

Also, if you enter a number that exceeds the maximum allowable integer, you get
a java.lang.NumberFormatException.

Severity: normal
OS: All

@asfimport
Copy link
Collaborator Author

khammond25 (migrated from Bugzilla):
This also applies to the Gaussian Random and Uniform Random Timers.

@asfimport
Copy link
Collaborator Author

khammond25 (migrated from Bugzilla):
Created attachment patch.ConstantTimer.diff: Patch for ConstantTimer.java; file contains the diff

patch.ConstantTimer.diff
--- \jakarta-jmeter-cvs\jakarta-jmeter\src\org\apache\jmeter\timers\ConstantTimer.java	Fri Aug 31 00:46:46 2001
+++ \jakarta-jmeter-nightly\2001.09.15\jakarta-jmeter\src\org\apache\jmeter\timers\ConstantTimer.java	Tue Sep 18 14:04:42 2001
@@ -77,7 +77,8 @@
 public class ConstantTimer implements Timer, JMeterComponentModel, Saveable,
 		Serializable
 {
-	private long delay = 300;
+	private final long DEFAULT_DELAY = 300;
+	private long delay = DEFAULT_DELAY;
 	private String name;
 	private static List addableList = new LinkedList();
 
@@ -135,6 +136,16 @@
 	public long getDelay()
 	{
 		return delay;
+	}
+
+	/************************************************************
+	 *  !ToDoo (Method description)
+	 *
+	 *@return    !ToDo (Return description)
+	 ***********************************************************/
+	public long getDefaultDelay()
+	{
+		return DEFAULT_DELAY;
 	}
 
 	/************************************************************

@asfimport
Copy link
Collaborator Author

khammond25 (migrated from Bugzilla):
Created attachment patch.ConstantTimerGui.diff: Patch for ConstantTimerGui.java; file contains the diff

patch.ConstantTimerGui.diff
--- \jakarta-jmeter-cvs\jakarta-jmeter\src\org\apache\jmeter\timers\gui\ConstantTimerGui.java	Thu Jul 26 00:34:52 2001
+++ \jakarta-jmeter-nightly\2001.09.15\jakarta-jmeter\src\org\apache\jmeter\timers\gui\ConstantTimerGui.java	Tue Sep 18 14:08:54 2001
@@ -124,7 +124,24 @@
 			}
 			else
 			{
-				model.setDelay(Long.parseLong(delayField.getText()));
+				try
+				{
+					model.setDelay(Long.parseLong(delayField.getText()));
+				}
+				catch (NumberFormatException nfe)
+				{
+					if (delayField.getText().length() > 0)
+					{
+						JOptionPane.showMessageDialog(this, "You must enter a valid number",
+								"Invalid data", JOptionPane.WARNING_MESSAGE);
+						model.setDelay(model.getDefaultDelay());
+						delayField.setText("");
+					}
+					else
+					{
+						model.setDelay(model.getDefaultDelay());
+					}
+				}
 			}
 		}
 
@@ -135,4 +152,4 @@
 	public void keyTyped(KeyEvent e)
 	{
 	}
-}
\ No newline at end of file
+}

@asfimport
Copy link
Collaborator Author

khammond25 (migrated from Bugzilla):
Created attachment patch.GaussianRandomTimerGui.diff: Patch for GaussianRandomTimerGui.java; file contains the diff

patch.GaussianRandomTimerGui.diff
--- \jakarta-jmeter-cvs\jakarta-jmeter\src\org\apache\jmeter\timers\gui\GaussianRandomTimerGui.java	Thu Jul 26 00:34:52 2001
+++ \jakarta-jmeter-nightly\2001.09.15\jakarta-jmeter\src\org\apache\jmeter\timers\gui\GaussianRandomTimerGui.java	Tue Sep 18 14:13:18 2001
@@ -109,11 +109,45 @@
 		}
 		else if (temp.equals("Timer Delay"))
 		{
-			model.setDelay(Long.parseLong(delayField.getText()));
+			try
+			{
+				model.setDelay(Long.parseLong(delayField.getText()));
+			}
+			catch (NumberFormatException nfe)
+			{
+				if (delayField.getText().length() > 0)
+				{
+					JOptionPane.showMessageDialog(this, "You must enter a valid number",
+							"Invalid data", JOptionPane.WARNING_MESSAGE);
+					model.setDelay(model.getDefaultDelay());
+					delayField.setText("");
+				}
+				else
+				{
+					model.setDelay(model.getDefaultDelay());
+				}
+			}
 		}
 		else if (temp.equals("Timer Delay Range"))
 		{
-			model.setRange(Double.parseDouble(rangeField.getText()));
+			try
+			{
+				model.setRange(Double.parseDouble(rangeField.getText()));
+			}
+			catch (NumberFormatException nfe)
+			{
+				if (rangeField.getText().length() > 0)
+				{
+					JOptionPane.showMessageDialog(this, "You must enter a valid number",
+							"Invalid data", JOptionPane.WARNING_MESSAGE);
+					model.setRange(model.getDefaultRange());
+					rangeField.setText("");
+				}
+				else
+				{
+					model.setRange(model.getDefaultRange());
+				}
+			}
 		}
 	}
 

@asfimport
Copy link
Collaborator Author

khammond25 (migrated from Bugzilla):
Created attachment patch.RandomTimer.diff: Patch for RandomTimer.java; file contains the diff

patch.RandomTimer.diff
--- \jakarta-jmeter-cvs\jakarta-jmeter\src\org\apache\jmeter\timers\RandomTimer.java	Fri Aug 31 00:46:46 2001
+++ \jakarta-jmeter-nightly\2001.09.15\jakarta-jmeter\src\org\apache\jmeter\timers\RandomTimer.java	Tue Sep 18 14:16:18 2001
@@ -76,8 +76,10 @@
 		JMeterComponentModel, Saveable, Serializable
 {
 	protected Random random;
-	protected long delay = 300;
-	protected double range = 100.0;
+	protected final long DEFAULT_DELAY = 300;
+	protected final double DEFAULT_RANGE = 100.0;
+	protected long delay = DEFAULT_DELAY;
+	protected double range = DEFAULT_RANGE;
 	private String name;
 	private static List addableList = new LinkedList();
 
@@ -142,6 +144,16 @@
 	 *
 	 *@return    !ToDo (Return description)
 	 ***********************************************************/
+	public double getDefaultRange()
+	{
+		return DEFAULT_RANGE;
+	}
+
+	/************************************************************
+	 *  !ToDoo (Method description)
+	 *
+	 *@return    !ToDo (Return description)
+	 ***********************************************************/
 	public Class getTagHandlerClass()
 	{
 		return org.apache.jmeter.save.handlers.TimerHandler.class;
@@ -159,6 +171,15 @@
 		return delay;
 	}
 
+	/************************************************************
+	 *  !ToDoo (Method description)
+	 *
+	 *@return    !ToDo (Return description)
+	 ***********************************************************/
+	public long getDefaultDelay()
+	{
+		return DEFAULT_DELAY;
+	}
 
 	/************************************************************
 	 *  !ToDoo (Method description)

@asfimport
Copy link
Collaborator Author

khammond25 (migrated from Bugzilla):
The four patches fix all parts of this bug. Additionally, a dialog is
displayed if the user enters an invalid number. No more NumberFormatExceptions
in the console.

ConstantTimer and RandomTimer now have default constants, and GET methods that
the GUI can use to reset numeric fields to the default values if the user
enters an invalid number.

[See also: patches for https://github.com//issues/752 and https://github.com//issues/766]

@asfimport
Copy link
Collaborator Author

khammond25 (migrated from Bugzilla):
Fixed 2001.09.27.

@asfimport
Copy link
Collaborator Author

Jordi Salvat i Alabart (migrated from Bugzilla):
Marking all bugs RESOLVED before JMeter 1.8's release date as VERIFIED.
Yes, it's pretty poor QA procedure, but there's bugs here lingering since JMeter
1.6, and we need to clean up a little.

@asfimport
Copy link
Collaborator Author

Jordi Salvat i Alabart (migrated from Bugzilla):
Bulk-closing all bugs RESOLVED before JMeter 1.8 release date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant