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

Using the unexpected method, due to dependency conflicts on antlr:antlr #8

Open
HelloCoCooo opened this issue Oct 4, 2020 · 1 comment

Comments

@HelloCoCooo
Copy link

Hi, in halo-dal, there are mulptiple versions of library antlr:antlr. However, according to Maven's dependency management strategy: "first declaration wins", only antlr:antlr:2.7.6 can be loaded, and antlr:antlr:2.7.7 will be shadowed.

Your project expects to reference the method <antlr.TokenStreamRewriteEngine$RewriteOperation: toString()Ljava/lang/String;> via org.antlr:antlr-runtime:jar:3.1.3, which is included in the shaded version antlr:antlr:2.7.7 (original dependency path). However, this method is missing in the actual loaded versionantlr:antlr:2.7.6. Surprisingly, it will not cause NoSuchMethodError at rumtime.
By further analyzing, I found that the caller(org.antlr:antlr-runtime:jar:3.1.3) would invoke the method java.lang.Object.toString() defined in antlr.TokenStreamRewriteEngine$RewriteOperation's superclass , due to dynamic binding mechanism (actual dependency path).

However, methods java.lang.Object.toString() and <antlr.TokenStreamRewriteEngine$RewriteOperation: toString()Ljava/lang/String;> have different implementations, which will lead to buggy behaviors-----

Code snippet of <antlr.TokenStreamRewriteEngine$RewriteOperation: toString()Ljava/lang/String;> in antlr:antlr:2.7.7 (shadowed but expected to invoke):

public String toString() {
            String var1 = this.getClass().getName();
            int var2 = var1.indexOf(36);
            var1 = var1.substring(var2 + 1, var1.length());
            return var1 + "@" + this.index + '"' + this.text + '"';
        }

Code snippet of <toString()Ljava/lang/String;> in antlr:antlr:2.7.6 (loaded version):

public String toString() {
        return getClass().getName() + "@" + Integer.toHexString(hashCode());
    }

halo-dal

Actual dependency path:

<halo.dal.analysis.antlr.v3.AntlrV3SQLParser: kv()V> /home/wwww/wangSensor/unzip/halo-dal-master/target/classes
<org.antlr.runtime.CommonTokenStream: toString(Lorg/antlr/runtime/Token;Lorg/antlr/runtime/Token;)Ljava/lang/String;> /home/wwww/.m2/repository/org/antlr/antlr-runtime/3.1.3/antlr-runtime-3.1.3.jar
<org.antlr.runtime.TokenRewriteStream: toString(II)Ljava/lang/String;> /home/wwww/.m2/repository/org/antlr/antlr-runtime/3.1.3/antlr-runtime-3.1.3.jar
<org.antlr.runtime.TokenRewriteStream: toString(Ljava/lang/String;II)Ljava/lang/String;> /home/wwww/.m2/repository/org/antlr/antlr-runtime/3.1.3/antlr-runtime-3.1.3.jar
<org.antlr.runtime.TokenRewriteStream: reduceToSingleOperationPerIndex(Ljava/util/List;)Ljava/util/Map;> /home/wwww/.m2/repository/org/antlr/antlr-runtime/3.1.3/antlr-runtime-3.1.3.jar
<org.antlr.runtime.TokenRewriteStream: catOpText(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/String;> /home/wwww/.m2/repository/org/antlr/antlr-runtime/3.1.3/antlr-runtime-3.1.3.jar
<antlr.TokenStreamRewriteEngine$RewriteOperation: toString()Ljava/lang/String;>

Dependency tree--

[INFO] halo.dal:halodal:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:4.8.2:test
[INFO] +- org.mybatis:mybatis:jar:3.0.5:test
[INFO] +- org.mybatis:mybatis-spring:jar:1.0.1:test
[INFO] | +- (org.mybatis:mybatis:jar:3.0.5:test - omitted for duplicate)
[INFO] | +- (org.springframework:spring-core:jar:3.0.5.RELEASE:test - omitted for duplicate)
[INFO] | +- (org.springframework:spring-tx:jar:3.0.5.RELEASE:test - omitted for duplicate)
[INFO] | +- (org.springframework:spring-jdbc:jar:3.0.5.RELEASE:test - omitted for duplicate)
[INFO] | - (org.springframework:spring-context:jar:3.0.5.RELEASE:compile - scope updated from test; omitted for duplicate)
[INFO] +- org.springframework:spring-core:jar:3.0.5.RELEASE:compile
[INFO] | - commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-tx:jar:3.0.5.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:3.0.5.RELEASE:compile
[INFO] | | - (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] | +- (org.springframework:spring-context:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] | - (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-jdbc:jar:3.0.5.RELEASE:compile
[INFO] | +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] | +- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] | - (org.springframework:spring-tx:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-test:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:3.0.5.RELEASE:test
[INFO] | +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:test - omitted for duplicate)
[INFO] | +- (org.springframework:spring-core:jar:3.0.5.RELEASE:test - omitted for duplicate)
[INFO] | +- (org.springframework:spring-jdbc:jar:3.0.5.RELEASE:test - omitted for duplicate)
[INFO] | - (org.springframework:spring-tx:jar:3.0.5.RELEASE:test - omitted for duplicate)
[INFO] +- org.springframework:spring-context:jar:3.0.5.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:3.0.5.RELEASE:compile
[INFO] | | +- aopalliance:aopalliance:jar:1.0:compile
[INFO] | | +- (org.springframework:spring-asm:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] | | +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] | | - (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] | +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] | +- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] | +- org.springframework:spring-expression:jar:3.0.5.RELEASE:compile
[INFO] | | - (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] | - org.springframework:spring-asm:jar:3.0.5.RELEASE:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.5.10:compile
[INFO] +- org.slf4j:slf4j-jcl:jar:1.5.10:compile
[INFO] | +- (org.slf4j:slf4j-api:jar:1.5.10:compile - omitted for duplicate)
[INFO] | - (commons-logging:commons-logging:jar:1.1.1:compile - omitted for duplicate)
[INFO] +- commons-lang:commons-lang:jar:2.4:compile
[INFO] +- c3p0:c3p0:jar:0.9.1.2:test
[INFO] +- log4j:log4j:jar:1.2.16:compile
[INFO] +- cglib:cglib:jar:2.2:compile
[INFO] | - asm:asm:jar:3.1:compile
[INFO] +- javassist:javassist:jar:3.11.0.GA:compile
[INFO] +- org.antlr:antlr-runtime:jar:3.1.3:compile
[INFO] | - org.antlr:stringtemplate:jar:3.2:compile
[INFO] | - (antlr:antlr:jar:2.7.7:compile - omitted for conflict with 2.7.6)
[INFO] +- org.hibernate:hibernate-core:jar:3.6.8.Final:compile
[INFO] | +- antlr:antlr:jar:2.7.6:compile
[INFO] | +- (commons-collections:commons-collections:jar:3.1:compile - omitted for duplicate)
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
[INFO] | | - (org.slf4j:slf4j-api:jar:1.5.8:compile - omitted for conflict with 1.5.10)
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] | +- javax.transaction:jta:jar:1.1:compile
[INFO] | - (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for conflict with 1.5.10)
[INFO] +- commons-io:commons-io:jar:1.4:test
[INFO] +- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] +- commons-collections:commons-collections:jar:3.1:compile
[INFO] - mysql:mysql-connector-java:jar:5.1.12:test

Suggested solutions:

Solution1: Exclude the dependency antlr:antlr:2.7.6.

Solution2: Declare version antlr:antlr:2.7.7 as a direct dependency.

Thanks.
Best regards,
Coco

@HelloCoCooo
Copy link
Author

@akwei Could please help me check this issue?
May I pull a request to fix it?
Thanks again.

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

1 participant