NoSuchMethodError: org.objectweb.asm.tree.ClassNode.<init>(I)V while using Parboiled

1.8k Views Asked by At

I have the following program, which executes a parser. This is developed in grappa (a fork of parboiled)

package com.test;

import org.parboiled.Parboiled;
import org.parboiled.parserunners.BasicParseRunner;
import org.parboiled.parserunners.ParseRunner;
import org.parboiled.support.ParsingResult;

public final class SampleRun
{
        public static void main(final String... args)
        {
        // 1. create a parser

        final TestGrammar parser = Parboiled.createParser(TestGrammar.class);
        // 2. create a runner
        final ParseRunner<String> runner
        = new BasicParseRunner<String>(parser.oneLine());
        // 3. collect the result

        @SuppressWarnings("deprecation")
        final ParsingResult<String> result
        = runner.run("sno101 snamegowtham");

        // 4. success or not?
        System.out.println(result.isSuccess());
        }
} 

TestGrammar

package com.test;

import com.github.parboiled1.grappa.parsers.EventBusParser;
import org.parboiled.Rule;
import org.parboiled.support.Var;

import java.util.HashMap;
import java.util.Map;

public class TestGrammar
    extends EventBusParser<String>
{
    protected final Map<String, String> collectedValues
        = new HashMap<String, String>();
    protected final Var<String> var = new Var<String>();

    Rule key()
    {
        return sequence(
            firstOf(ignoreCase("sno"), ignoreCase("sname")),
            var.set(match().toLowerCase()),
            !collectedValues.containsKey(var.get())
        );
    }

    Rule separator()
    {
        return optional(anyOf(":-*_ "));
    }

    Rule value()
    {
        return sequence(
            oneOrMore(testNot(wsp()), ANY),
            collectedValues.put(var.get(), match()) == null
        );
    }

    Rule oneLine()
    {
        return join(sequence(key(), separator(), value()))
            .using(oneOrMore(wsp()))
            .min(2);
    }
}

But, I am getting the following error when I try to execute the above program.

Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.tree.ClassNode.<init>(I)V
    at org.parboiled.transform.ParserClassNode.<init>(ParserClassNode.java:50)
    at org.parboiled.transform.ParserTransformer.extendParserClass(ParserTransformer.java:93)
    at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:63)
    at org.parboiled.Parboiled.createParser(Parboiled.java:64)
    at com.test.SampleRun.main(SampleRun.java:15)

I have the following maven dependencies

  1. grappa-1.0.4.jar
  2. asm-debug-all-5.0.3.jar
  3. guava-18.0.jar
  4. jitescript-0.4.0.jar

Here is my pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>parboiledprogram</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
      <dependency>
        <groupId>com.github.parboiled1</groupId>
        <artifactId>grappa</artifactId>
        <version>1.0.4</version>
      </dependency>
  </dependencies>
</project>

Note: I am using Eclipse Juno Service Release 2


Some attempts that didn't work


I have noticed the following icon for asm-debug-all-5.0.3.jar, I am not sure what this icon means in eclipse juno.

enter image description here

  1. Also, in the pom.xml of the dependency jitesscript-0.4.0.jar I have noticed relocation of the org.objectweb.asm package. However, the classes in that too contain the ClassNode(int) jitescript was updated is on 16-Apr-2014 whereas asm-debug-all-5.0.3 was on 24-May-2014

  2. I have tried to remove jitescript.jar and updated the maven project and also cleaned and build it but still no use.

  3. I have also tested this in KEPLER without using maven by manually including all the dependencies that are listed above. But still, I am getting the same error. This means that the problem was not with Maven but something else.

1

There are 1 best solutions below

0
On BEST ANSWER

The error is due to the presence of dcevm.jar present in my jre\lib\ext folder. The jdk which I have used for the project contains the dcevm.jar file and that this jar contains the package org.objectweb.asm.tree which containsClassNodewith no constructor like ClassNode(int).

The jvm is using this jar instead of the jar file in the maven dependencies i.e. if there are classes that are present in any of the jar files in the JRE system library used by the project, they override the classes present in the maven jars.

Therefore, I have deleted the dcevm.jar from the jre\lib\ext and then in my eclipse preferences, I have changed the execution environment to a new one (to my jdk path, jdk1.7.0_13) and used at is default.

Summary

Such errors occur clearly because of different versions of jar files containing the class. To identify them:

  1. First, search for the class (ex. ClassNode) in the eclipse Open Type (Ctrl+Shift+T) and you'll find different files with same classname and package too. You can also see where they are located.
  2. Open each one and check in which the method is not found. Eliminate it.

Note: If the class is present in JRE system library, then this is likely to override the one in the maven dependency.