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

JMXetricAgentIT fails with NumberFormatException #22

Closed
ngzhian opened this issue May 10, 2014 · 3 comments
Closed

JMXetricAgentIT fails with NumberFormatException #22

ngzhian opened this issue May 10, 2014 · 3 comments

Comments

@ngzhian
Copy link
Contributor

ngzhian commented May 10, 2014

Below is the complete output of the test.
The problem is that in the configureJMXetricFromXML method call of XMLConfigurationService, while reading the first composite data, the missing dmax attribute results in an empty string "" being passed to Integer.parseInt on line 250.

Still investigating why this happens, on first look it looks like the default value of "0" should have been passed in instead.

java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:504)
    at java.lang.Integer.parseInt(Integer.java:527)
    at info.ganglia.jmxetric.XMLConfigurationService.configureJMXetricFromXML(XMLConfigurationService.java:249)
    at info.ganglia.jmxetric.XMLConfigurationService.configure(XMLConfigurationService.java:69)
    at info.ganglia.jmxetric.JMXetricAgentIT.testRun(JMXetricAgentIT.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
    at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
    at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
    at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
    at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
    at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
@ngzhian
Copy link
Contributor Author

ngzhian commented May 10, 2014

It seems like this line

String sampleDMax = selectParameterFromNode(sample, "dmax", "0");

is causing trouble, its return value should be "0", since dmax isn't in the sample jmxetric_text.xml file. For somehow it returns "".

@ngzhian
Copy link
Contributor Author

ngzhian commented May 10, 2014

Think I've found the problem. In jmxetric_test.xml, we have the following doctype

   <!ELEMENT sample (mbean)*>
      <!ATTLIST sample delay CDATA #REQUIRED>
      <!ATTLIST sample dmax CDATA "" >

This meant that dmax is always going to be present, with a default value of "". Hence the method selectParameterFromNode in XMLConfigurationService:

            Node node = ganglia.getAttributes().getNamedItem(attributeName);
            if ( node != null ) {
                String value = node.getNodeValue();
                if ( value != null )
                    ret = value ;
            }

would return "", as node is never null for dmax, since a default value was given in the XML doctype.

2 ways to fix this:

  1. remove that attribute from sample
  2. give it a default string of "0", because that's what the code does anyway

Referencing the initialdelay attribute in etc/jmxetric.xml, it seems that 2. is a better way:

   <!ELEMENT sample (mbean)*>
      <!ATTLIST sample delay CDATA #REQUIRED>
      <!ATTLIST sample initialdelay CDATA "0">
      <!ATTLIST sample dmax CDATA "" >

and note that dmax has an empty default string here as well.

@dpocock which way would be suitable?

@dpocock
Copy link
Member

dpocock commented May 18, 2014

I would suggest two things:

  • fix the default in the sample, change it to "0"
  • some people may have already copied that sample and may not notice the fix. Therefore, I think that in the code it should check if sampleDMax.equals("") and if so replace it with 0

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

No branches or pull requests

2 participants