0

I'm trying to use webdrive in a Netbeans platform project, but i keep getting the following error:

java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "com.gargoylesoftware.htmlunit.html.DomNode.getAttributes()Lorg/w3c/dom/NamedNodeMap;" the class loader (instance of org/netbeans/StandardModule$OneModuleClassLoader) of the current class, com/gargoylesoftware/htmlunit/html/DomNode, and the class loader (instance of <bootloader>) for interface org/w3c/dom/Node have different Class objects for the type 3c/dom/NamedNodeMap; used in the signature
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:187)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:437)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:311)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:376)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:476)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:454)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:180)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:190)
at geo.parser.GeocacheParser.getNextPage(GeocacheParser.java:102)
at geo.DetailsTopComponent.btnLoadPlus20ActionPerformed(DetailsTopComponent.java:250)
at geo.DetailsTopComponent.access$200(DetailsTopComponent.java:61)
at geo.DetailsTopComponent$3.actionPerformed(DetailsTopComponent.java:125)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)

[catch]

    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
WARNING [org.netbeans.TopSecurityManager]: use of system property netbeans.home has been obsoleted in favor of InstalledFileLocator/Places at org.netbeans.Clusters.relativeDirsWithHome(Clusters.java:137)

Can anyone help?

Krease
  • 15,805
  • 8
  • 54
  • 86

2 Answers2

0

You have different versions of org/w3c/dom/NamedNodeMap in your classpath.

You should check your project build preferences because you may have the same xml-apis-X.YZ.jar twice (with different version) for one project. (But I checked my project dependencies.... selenium-server-standalone-2.41.0.jar contains this class too.)

The solution is to eliminate the wrong version of this class file from the classpath. One work around is to manually delete the unused jar file. (or set the jars scope to provided)

UPDATE:

Display project classpath with this method:

void displayClassPath() {  

    ClassLoader classloader = Thread.currentThread().getContextClassLoader();  

    do {  
        URL[] urls = ((URLClassLoader)classloader).getURLs();  

        for(URL url: urls){  
            System.out.println(url.getFile());  
        }  
        classloader = (URLClassLoader)classloader.getParent();  

    } while(classloader != null);  
}  

You can find all instances of NamedNodeMap class file in your file system (inside the listed jar files). Try to exclude the invalid/deprecated/old version.

...or... another way is to use the JVM option -verbose. It displays all loaded JAR files and classes (and interfaces).

[Loaded org.openqa.selenium.io.FileHandler$NoFilter from file:/C:/Program%20Files/Java/jre7/lib/ext/selenium-java-2.41.0.jar]
[Loaded java.nio.channels.ReadableByteChannel from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.nio.channels.ByteChannel from C:\Program Files\Java\jre7\lib\rt.jar]

For example: I have a Selenium project in Eclipse and I used the displayClassPath() method. Three instances of NamedNodeMap were founded in the classpath with the same signature in these jar files:

  • selenium-server-standalone-2.41.0.jar
  • xml-apis-1.4.01.jar
  • jre7\lib\rt.jar

(To check the signature you can decompile the .class file : http://jd.benow.ca/)

Some links about it:

Community
  • 1
  • 1
Gyorgy.Hegedus
  • 361
  • 1
  • 3
0

For other people who get this error since I don't believe it was sufficiently explained so far:

As mentioned earlier rt.jar contains this class it is Java runtime itself. Therefore, if you have xml-apis jar as a dependency or any other dependencies have it as dependency you will get that error.

The fix for Gradle (but can be easily interpolated onto any other java build tool), htmlunit is used as an example but it can be any other dependency:

compile('net.sourceforge.htmlunit:htmlunit:2.27' ){
    exclude group: 'xml-apis', module: 'xml-apis'
}

To find dependencies run

gradle dependencies

The problem is since gradle does cannot compare xml-apis with rt.jar it won't do version check, normally how you can see here:

   \--- xerces:xercesImpl:2.9.1 -> 2.11.0

The -> says xerces was replaced with a more recent version to avoid conflicts since another dependency was already using more recent version.

wholenewstrain
  • 199
  • 1
  • 8