1

I have a third-party library (tibco smartsockets in java) that works in a java console app but when calling the same code inside a Spring Boot Controller or a Bean, it would throw a

java.lang.IllegalAccessError: tried to access field com.smartsockets.TipcMsgImpl.j from class com.smartsockets.TipcConnClientImpl.

Decompiling TipcMsgImpl class and look at field j, it's declared as private. My guess is that TipcConnClientImpl uses reflection to set the j field and this was allowed but when running inside a Spring Boot application, this isn't allowed. Note that calling System.getSecurityManager() returns null so there isn't any security manager being used here.

alepuzio
  • 1,382
  • 2
  • 28
  • 38
  • This may be caused by having the two classes in different classloaders; see [this answer](https://stackoverflow.com/a/3387520/1907186). – Lucas Ross Jun 14 '18 at 21:27
  • I thought about that but this is why I think it isn't that: 1. Field j isn't declared "boolean j" (package scope), it was declared as "private boolean j". 2. Running w/ argument -verbose:class shows that TipcMsgImpl and TipcConnClientImpl were loaded exactly once each and from the same jar file. – Rydan Gardener Jun 14 '18 at 21:34
  • Looks like at run time you are referring to different version of class than expected. This field `TipcMsgImpl.j` is not supposed to be private in the expected class, but it is at runtime, and thus you got IllegalAccessError. You have to lookup the dependency tree when building your package. (like mvn build it is `mvn dependency:tree -Dverbose`). Most of the time the same qualified class can get into the deployment package through different jars (called [Jar Hell](https://dzone.com/articles/what-is-jar-hell)) or same jar but different versions through transitive depedency. – Amith Kumar Jun 14 '18 at 22:04
  • How would I resolve the Jar Hell issue then? It sounded like the version of the jar/class is not being used, only the fully qualified name is being used so collision can happen. – Rydan Gardener Jun 20 '18 at 14:09

0 Answers0