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

NPE when root node name in testng.xml is invalid #809

Closed
juherr opened this issue Sep 21, 2015 · 14 comments
Closed

NPE when root node name in testng.xml is invalid #809

juherr opened this issue Sep 21, 2015 · 14 comments

Comments

@juherr
Copy link
Member

juherr commented Sep 21, 2015

From @gitpavi

[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project ShowTime: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: There was an error in the forked process
[ERROR] org.testng.TestNGException: java.lang.NullPointerException
[ERROR] at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:322)
[ERROR] at org.testng.TestNG.run(TestNG.java:991)
[ERROR] at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:295)
[ERROR] at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:84)
[ERROR] at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:90)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
[ERROR] Caused by: java.lang.NullPointerException
[ERROR] at org.testng.xml.XmlTest.init(XmlTest.java:77)
[ERROR] at org.testng.xml.XmlTest.<init>(XmlTest.java:68)
[ERROR] at org.testng.xml.TestNGContentHandler.xmlTest(TestNGContentHandler.java:265)
[ERROR] at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:517)
[ERROR] at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
[ERROR] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1363)
[ERROR] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786)
[ERROR] at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
[ERROR] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
[ERROR] at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
[ERROR] at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
[ERROR] at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
[ERROR] at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
[ERROR] at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
[ERROR] at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
[ERROR] at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
[ERROR] at org.testng.xml.XMLParser.parse(XMLParser.java:38)
[ERROR] at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:16)
[ERROR] at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:9)
[ERROR] at org.testng.xml.Parser.parse(Parser.java:172)
[ERROR] at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:302)
[ERROR] ... 7 more
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
<Suite name="ShowTime" verbose="3" parallel="none">
    <test name=" Demo 1" preserve-order="true" >
            <classes> 
             <class name="com.zoho.showTime.testCases.AudienceValidation" />
             <class name="com.zoho.showTime.testCases.SetAudienceKeyValidation" />           
             <class name="com.zoho.showTime.testCases.PresentationSlideShowValidation" />
        </classes>
    </test>
</Suite>
@juherr
Copy link
Member Author

juherr commented Sep 21, 2015

@gitpavi Could you share testng.xml and some classes to reproduce the NPE?

@gitpavi
Copy link

gitpavi commented Sep 22, 2015

@juherr
The below mentioned class was missing in the testng.xml which actually caused the above mentioned issue.

@juherr
Copy link
Member Author

juherr commented Sep 22, 2015

Strange, I succeed to run tests without the TestBase declaration.

How do you run it? With eclipse? Command line? Which version of eclipse, maven, java?

@gitpavi
Copy link

gitpavi commented Sep 22, 2015

I was got the error while running it on my eclipse and command line as well

@gitpavi
Copy link

gitpavi commented Sep 22, 2015

Below is the content of my Testng.xml which caused this exception

<test name=" Demo 1" preserve-order="true" >
        <classes> 
         <class name="com.zoho.showTime.testCases.AudienceValidation" />
         <class name="com.zoho.showTime.testCases.SetAudienceKeyValidation" />           
         <class name="com.zoho.showTime.testCases.PresentationSlideShowValidation" />
    </classes>
</test>

I got this error while running it on eclipse as well as command prompt. Latest version of java and maven but not sure of eclipse cause i dont have my system with me right now.

@juherr
Copy link
Member Author

juherr commented Sep 22, 2015

Do you mean without <suite> node? It can explain the NPE, but not how it is possible you succeed to run it.

@gitpavi
Copy link

gitpavi commented Sep 22, 2015

The suite details are not getting displayed in this text field so i have removed the tags now. What exactly caused this NPE @juherr ?

<Suite name="ShowTime" verbose="3" parallel="none">
    <test name=" Demo 1" preserve-order="true" >
            <classes> 
             <class name="com.zoho.showTime.testCases.AudienceValidation" />
             <class name="com.zoho.showTime.testCases.SetAudienceKeyValidation" />           
             <class name="com.zoho.showTime.testCases.PresentationSlideShowValidation" />
        </classes>
    </test>
</Suite>

@juherr
Copy link
Member Author

juherr commented Sep 22, 2015

I suppose NPE is from this line m_suite.getTests().add(this);
But m_suite and m_suite.getTests() are not supposed to be null... never.

As I can't reproduce, it is difficult to be sure.

@gitpavi
Copy link

gitpavi commented Sep 22, 2015

Oh okay. Thanks for that info.

@juherr
Copy link
Member Author

juherr commented Sep 22, 2015

I got it! <suite> is working when <Suite> will make the NPE!

@gitpavi
Copy link

gitpavi commented Sep 22, 2015

@juherr 👍

@juherr juherr changed the title NPE in XmlTest.init NPE when root node name in testng.xml is invalid Sep 22, 2015
@juherr
Copy link
Member Author

juherr commented Sep 22, 2015

I won't fix it (which doesn't mean it shouldn't) because it is not as easy as expected and I think the xml parer should be reworked.
A good practice is to valid xml with the DTD too.

@gitpavi
Copy link

gitpavi commented Sep 23, 2015

@juherr Sure Thank you for the support 👍

@juherr
Copy link
Member Author

juherr commented Nov 25, 2015

I close the issue: #898 won't fix it but should avoid bad formated file.

@juherr juherr closed this as completed Nov 25, 2015
cbeust added a commit that referenced this issue Nov 26, 2015
Activate XML valiation that should avoid issues like #809
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