Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@OrderBy causes java.lang.ClassCastException: antlr.CommonToken cannot be cast to antlr.Token [duplicate]

I'm trying to use the @OrderBy annotation on a Spring MVC project that run on a JBoss EAP 6.1+ server.

I have 2 projects: the first one is named model-gen-wifipnsd and it contains only the model classes that are used by the second project (named WIFIPNSD) that represent the web application.

1) So for the model-gen-wifipnsd I have this pom.xml file:

<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>model-gen-wifipnsd</groupId>
  <artifactId>model-gen-wifipnsd</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>

    <dependencies>      
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>       
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.11.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.8.2.RELEASE</version>
        </dependency>   
    </dependencies>
</project>

2) And this is the *pom.xml** file related to the WIFIPNSD web application project:

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>it.mycompany</groupId>
    <artifactId>projectName</artifactId>
    <name>GestioneUtenzeCloud</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.7</java-version>
        <org.springframework-version>4.1.7.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
        <spring-security.version>4.0.2.RELEASE</spring-security.version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                 </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>   

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>

        <!-- add -->
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>velocity-tools</groupId>
            <artifactId>velocity-tools</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring-security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
            <version>${spring-security.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring-security.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${spring-security.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring-tx</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.ldap</groupId>
            <artifactId>spring-ldap-core</artifactId>
            <version>2.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>4.1.7.RELEASE</version>
        </dependency>
        <!-- <dependency>
          <groupId>org.springframework.data</groupId>
          <artifactId>spring-data-commons</artifactId>
          <version>1.8.2.RELEASE</version>
        </dependency>-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.1.7.RELEASE</version>
        </dependency>
        <dependency>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.1-api</artifactId>
                <version>1.0.0.Final</version>
            </dependency>       
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>4.3.11.Final</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-jpa</artifactId>
                <version>1.8.2.RELEASE</version>
            </dependency>   
        <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>4.1.7.RELEASE</version>
    </dependency>
        <dependency>
            <groupId>model-gen-wifipnsd</groupId>
            <artifactId>model-gen-wifipnsd</artifactId>
            <version>1.0</version>          
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.1.7.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator</artifactId>
            <version>0.1</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>2.0.3</version> 
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.0.0</version>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

Ok, into a model class (inside model-gen-wifipnsd project) I have mapped this field:

@OneToMany(fetch=FetchType.EAGER)
@OrderBy("flgTipPrg")
@JoinColumns({
    @JoinColumn(name="COD_MEC_ATT", referencedColumnName="COD_SCU_UT"),
    @JoinColumn(name="DAT_ANN_SCO_ATT", referencedColumnName="DAT_ANN_SCO_RIL")
    })
private List<Twp1007Progetto> twp1007Progettos;

As you can see I have putted the @OrderBy("flgTipPrg") to order the list according to this field defined into the Twp1007Progetto model class:

@Column(name="FLG_TIP_PRG")
private String flgTipPrg;

The problem is that using this @OrderBy("flgTipPrg") I obtain this exception:

10:26:17,279 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.serverManagement.controller.management.http: org.jboss.msc.service.StartException in service jboss.serverManagement.controller.management.http: Address already in use: bind localhost/127.0.0.1:9990
    at org.jboss.as.server.mgmt.HttpManagementService.start(HttpManagementService.java:224) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]
Caused by: java.net.BindException: Address already in use: bind
    at sun.nio.ch.Net.bind0(Native Method) [rt.jar:1.8.0_25]
    at sun.nio.ch.Net.bind(Net.java:436) [rt.jar:1.8.0_25]
    at sun.nio.ch.Net.bind(Net.java:428) [rt.jar:1.8.0_25]
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214) [rt.jar:1.8.0_25]
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) [rt.jar:1.8.0_25]
    at org.jboss.sun.net.httpserver.ServerImpl.<init>(ServerImpl.java:144)
    at org.jboss.sun.net.httpserver.HttpServerImpl.<init>(HttpServerImpl.java:54)
    at org.jboss.sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:38)
    at org.jboss.com.sun.net.httpserver.HttpServer.create(HttpServer.java:147)
    at org.jboss.as.domain.http.server.ManagementHttpServer.create(ManagementHttpServer.java:162)
    at org.jboss.as.server.mgmt.HttpManagementService.start(HttpManagementService.java:190) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    ... 5 more

10:26:17,344 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
10:26:18,479 ERROR [org.jboss.remoting.remote.connection] (Remoting "andreanobili:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: Connessione interrotta dal software del computer host
10:26:18,488 ERROR [org.jboss.remoting.remote.connection] (Remoting "andreanobili:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: Connessione interrotta dal software del computer host
10:26:19,092 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015960: Class Path entry activation.jar in /C:/Program Files (x86)/EAP-6.2.0/jboss-eap-6.2/standalone/deployments/WIFIPNSD.war/WEB-INF/lib/mail-1.4.jar  does not point to a valid jar for a Class-Path reference.
10:26:19,274 INFO  [org.jboss.as.jpa] (MSC service thread 1-7) JBAS011401: Read persistence.xml for wifipnsdPU
10:26:19,723 WARN  [org.jboss.as.ee] (MSC service thread 1-1) JBAS011006: Not installing optional component org.springframework.http.server.ServletServerHttpAsyncRequestControl due to an exception (enable DEBUG log level to see the cause)
10:26:19,723 WARN  [org.jboss.as.ee] (MSC service thread 1-1) JBAS011006: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to an exception (enable DEBUG log level to see the cause)
10:26:19,818 WARN  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016012: Deployment deployment "WIFIPNSD.war" contains CDI annotations but beans.xml was not found.
10:26:19,862 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 48) JBAS011402: Starting Persistence Unit Service 'WIFIPNSD.war#wifipnsdPU'
10:26:19,999 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 48) HCANN000001: Hibernate Commons Annotations {4.0.1.Final-redhat-2}
10:26:20,013 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 48) HHH000412: Hibernate Core {4.2.7.SP1-redhat-3}
10:26:20,015 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 48) HHH000206: hibernate.properties not found
10:26:20,019 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 48) HHH000021: Bytecode provider name : javassist
10:26:20,037 INFO  [org.hibernate.ejb.Ejb3Configuration] (ServerService Thread Pool -- 48) HHH000204: Processing PersistenceUnitInfo [
    name: wifipnsdPU
    ...]
10:26:20,230 WARN  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (ServerService Thread Pool -- 48) HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
10:26:20,253 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 48) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
10:26:20,260 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (ServerService Thread Pool -- 48) HHH000422: Disabling contextual LOB creation as connection was null
10:26:20,505 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (ServerService Thread Pool -- 48) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
10:26:20,510 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 48) HHH000397: Using ASTQueryTranslatorFactory
10:26:20,552 INFO  [org.hibernate.validator.internal.util.Version] (ServerService Thread Pool -- 48) HV000001: Hibernate Validator 4.3.1.Final-redhat-1
10:26:21,387 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 48) MSC000001: Failed to start service jboss.persistenceunit."WIFIPNSD.war#wifipnsdPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."WIFIPNSD.war#wifipnsdPU": javax.persistence.PersistenceException: [PersistenceUnit: wifipnsdPU] Unable to build EntityManagerFactory
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:103) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final-redhat-1.jar:2.1.1.Final-redhat-1]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: wifipnsdPU] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:200) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$600(PersistenceUnitServiceImpl.java:57) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:99) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    ... 4 more
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.collection.OneToManyPersister
    at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:253)
    at org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:201)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:415)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1794)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
    ... 9 more
Caused by: org.hibernate.HibernateException: Unable to parse order-by fragment
    at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator.translate(OrderByFragmentTranslator.java:69)
    at org.hibernate.sql.Template.translateOrderBy(Template.java:721)
    at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:561)
    at org.hibernate.persister.collection.OneToManyPersister.<init>(OneToManyPersister.java:88)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.8.0_25]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [rt.jar:1.8.0_25]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.8.0_25]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408) [rt.jar:1.8.0_25]
    at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:231)
    ... 14 more
Caused by: java.lang.ClassCastException: antlr.CommonToken cannot be cast to antlr.Token
    at antlr.CharScanner.makeToken(CharScanner.java:173)
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByLexer.mIDENT(GeneratedOrderByLexer.java:239)
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByLexer.nextToken(GeneratedOrderByLexer.java:139)
    at antlr.TokenBuffer.fill(TokenBuffer.java:69)
    at antlr.TokenBuffer.LA(TokenBuffer.java:80)
    at antlr.LLkParser.LA(LLkParser.java:52)
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.expression(GeneratedOrderByFragmentParser.java:565)
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.sortKey(GeneratedOrderByFragmentParser.java:346)
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.sortSpecification(GeneratedOrderByFragmentParser.java:241)
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.orderByFragment(GeneratedOrderByFragmentParser.java:190)
    at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator.translate(OrderByFragmentTranslator.java:63)
    ... 22 more

10:26:21,847 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 26) JBAS018559: Deployed "WIFIPNSD.war" (runtime-name : "WIFIPNSD.war")
10:26:21,850 INFO  [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.persistenceunit."WIFIPNSD.war#wifipnsdPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."WIFIPNSD.war#wifipnsdPU": javax.persistence.PersistenceException: [PersistenceUnit: wifipnsdPU] Unable to build EntityManagerFactory
      service jboss.serverManagement.controller.management.http: org.jboss.msc.service.StartException in service jboss.serverManagement.controller.management.http: Address already in use: bind localhost/127.0.0.1:9990

If I remove the @OrderBy("flgTipPrg") annotation I have no exception and the application correctly start (but the list is not ordered).

How can I fix this issue? From what I have understand reading online this issue could depend by the fact that that I can have 2 versions of antlr dependency in my project but I am absolutly not sure about this and I don't know how to solve it.

like image 863
AndreaNobili Avatar asked Aug 28 '15 08:08

AndreaNobili


3 Answers

I am not sure if this is similar to your case but I had similar problem while using WebLogic with it's feature called deployment plan. Solution can be found in Utils.class inside of antlr itself. They use method getContextClassLoader: enter image description here

Fortunately there is a switch in this class which let us to disable it: enter image description here

You have to add to JAVA_OPTS of application server: -DANTLR_USE_DIRECT_CLASS_LOADING=true And problem should be gone.

like image 187
FilMiOs Avatar answered Oct 29 '22 21:10

FilMiOs


There are a lot of question regarding this issue (e.g. this one) and the error, as you supposed, seems caused by an automatically inserted dependency, antlr.

Try to exclude the dependency as suggested in the question above, so in your pom add:

<dependency>
   ...

   <exclusions>
      <exclusion>
         <groupId>antlr</groupId>
         <artifactId>antlr</artifactId>
      </exclusion>
   </exclusions>
</dependency>
like image 6
Alepac Avatar answered Oct 29 '22 22:10

Alepac


The fix is using system property as @FilMiOs said (I would have comment on his reply if had enough points).

Anyway, the root cause is thread classloader and normal classloader are pointing to different locations. As explained here: Difference between thread's context class loader and normal classloader

It happens to me in a tomcat instance where multiple applications share a common thread pool. The thread classloader is whichever app started the thread. But when the thread reused by another application, the thread classloader stay the same. Hence the difference.

To confirm, set a break point and watch the following two results, see if they are the same.

Thread.currentThread().getContextClassLoader()

this.getClass().getClassLoader()
like image 2
M.Liang Avatar answered Oct 29 '22 22:10

M.Liang