HotswapProjects / HotswapAgent

Java unlimited redefinition of classes at runtime.
GNU General Public License v2.0
2.32k stars 491 forks source link

Hotswapping agent possibly breaks other libraries #120

Open TheEpTic opened 8 years ago

TheEpTic commented 8 years ago

So I finally managed to get HotswapAgent working and as I do, it breaks my Twitter library:

x@beast:~/bot$ java -Xmx8g -XXaltjvm=dcevm -javaagent:hotswap/hotswap-agent.jar -Xbootclasspath/a:hotswap/hotswap-agent.jar -jar bot.jar 
HOTSWAP AGENT: 15:47:37.018 INFO (org.hotswap.agent.HotswapAgent) - Loading Hotswap agent {0.3.0-SNAPSHOT} - unlimited runtime class redefinition.
HOTSWAP AGENT: 15:47:37.884 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: [Hotswapper, AnonymousClassPatch, WatchResources, Hibernate, Spring, Jersey2, Jetty, Tomcat, ZK, Logback, JSF, Seam, ELResolver, OsgiEquinox, Proxy, WebObjects, Weld, JBossModules, Resteasy, Gae]
[bot] Config loaded successfully
Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.bot.Start.main(Start.java:84)
Caused by: java.lang.NullPointerException
        at com.twitter.hbc.ClientBuilder.loadVersion(ClientBuilder.java:63)
        at com.twitter.hbc.ClientBuilder.<clinit>(ClientBuilder.java:79)
        ... 1 more
x@beast:~/bot$ 

Bare in mind, this runs fine if I don't include the agent or the alt vm.

The library effected: https://github.com/twitter/hbc

I don't know if this is my error or what, but a second opinion would be great! Thanks

skybber commented 8 years ago

It looks that ClientBuilder is loaded by boot class loader. What it will do if you remove -Xbootclasspath/a:hotswap/hotswap-agent.jar ?

TheEpTic commented 8 years ago
x@beast:~/bot$ java -Xmx8g -XXaltjvm=dcevm -javaagent:hotswap/hotswap-agent.jar -jar bot.jar 
HOTSWAP AGENT: 20:1:19.319 INFO (org.hotswap.agent.HotswapAgent) - Loading Hotswap agent {0.3.0-SNAPSHOT} - unlimited runtime class redefinition.
HOTSWAP AGENT: 20:1:19.757 ERROR (org.hotswap.agent.config.PluginRegistry) - Error in plugin initial processing for plugin package 'org.hotswap.agent.plugin'
java.lang.ClassNotFoundException: org/hotswap/agent/plugin/hotswapper/HotswapperPlugin
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:278)
        at org.hotswap.agent.config.PluginRegistry.scanPlugins(PluginRegistry.java:89)
        at org.hotswap.agent.config.PluginManager.init(PluginManager.java:123)
        at org.hotswap.agent.HotswapAgent.premain(HotswapAgent.java:47)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:382)
        at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:397)

[bot] Config loaded successfully
Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.perry.Start.main(Start.java:87)
Caused by: java.lang.NullPointerException
        at com.twitter.hbc.ClientBuilder.loadVersion(ClientBuilder.java:63)
        at com.twitter.hbc.ClientBuilder.<clinit>(ClientBuilder.java:79)
        ... 1 more

Is what I would get otherwise. I don't get why at all.

x@beast:~/bot$ java -version
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-1~deb8u1)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
x@beast:~/bot$ 
skybber commented 8 years ago

The problem is in following:

ClientBuilder.class.getClassLoader().getResourceAsStream(..)

If the ClientBuilder is loaded by boot class loader then ClientBuilder.class.getClassLoader() is null. Null value for boot class loader was introduced in JVM 1.7.0.u80. But I don't know why the ClientBuilder is loaded by boot class loader. I would expect that it is loaded by system class loader.

TheEpTic commented 8 years ago

Huh, so weird. I'm guessing there's no real fix to it. I guess I'm back to square one with my problem being that the hotswap jar doesn't work without sending the boot class loader

On 31 Mar 2016, at 08:02, skybber notifications@github.com wrote:

The problem is in following:

ClientBuilder.class.getClassLoader().getResourceAsStream(..) If the ClientBuilder is loaded by boot class loader then ClientBuilder.class.getClassLoader() is null. Null value for boot class loader was introduced in JVM 1.7.0.u80. But I don't know why the ClientBuilder is loaded by boot class loader. I would expect that it is loaded by system class loader.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub