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

Hotswap Agent / Wildfly / Weld: Exception when reloading: BeanManagerImpl.contexts not accessible #161

Closed
geert3 opened this Issue Dec 25, 2016 · 10 comments

Comments

Projects
None yet
2 participants
@geert3

geert3 commented Dec 25, 2016

I'm using WildFly 10, and have properly configured Hotswap Agent 1.0 as far as I can see. It's starting up nicely with the message:

HOTSWAP AGENT: 20:01:19.893 INFO (org.hotswap.agent.HotswapAgent) - Loading Hotswap agent {1.0} - unlimited runtime class redefinition.
HOTSWAP AGENT: 20:01:21.096 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: [Hotswapper, WatchResources, AnonymousClassPatch, ClassInitPlugin, Hibernate, Hibernate3JPA, Hibernate3, Spring, Jersey1, Jersey2, Jetty, Tomcat, ZK, Logback, Log4j2, MyFaces, Mojarra, Seam, ELResolver, WildFlyELResolver, OsgiEquinox, Proxy, WebObjects, Weld, JBossModules, ResteasyRegistry, Deltaspike, JavaBeans]
20:01:22,363 INFO  [org.jboss.modules] (main) JBoss Modules version 1.5.1.Final

However every time I modify a class (mostly @injected Vaadin UI classes), I get the following WARNING in the console log. Modified classes are not reloaded.

19:56:07,946 INFO  [stdout] (Thread-281) HOTSWAP AGENT: 19:56:07.946 WARNING (org.hotswap.agent.plugin.weld.command.BeanDeploymentArchiveAgent) - BeanManagerImpl.contexts not accessible
19:56:07,947 INFO  [stdout] (Thread-281) java.lang.NoSuchFieldException: contexts
19:56:07,948 INFO  [stdout] (Thread-281)    at java.lang.Class.getField(Class.java:1703)
19:56:07,948 INFO  [stdout] (Thread-281)    at org.hotswap.agent.plugin.weld.command.BeanDeploymentArchiveAgent.getContexts(BeanDeploymentArchiveAgent.java:269)
19:56:07,948 INFO  [stdout] (Thread-281)    at org.hotswap.agent.plugin.weld.command.BeanDeploymentArchiveAgent.reloadManagedBeanInContexts(BeanDeploymentArchiveAgent.java:318)
19:56:07,948 INFO  [stdout] (Thread-281)    at org.hotswap.agent.plugin.weld.command.BeanDeploymentArchiveAgent.reloadManagedBean(BeanDeploymentArchiveAgent.java:297)
19:56:07,948 INFO  [stdout] (Thread-281)    at org.hotswap.agent.plugin.weld.command.BeanDeploymentArchiveAgent.reloadBean(BeanDeploymentArchiveAgent.java:231)
19:56:07,948 INFO  [stdout] (Thread-281)    at org.hotswap.agent.plugin.weld.command.BeanDeploymentArchiveAgent.refreshBeanClass(BeanDeploymentArchiveAgent.java:192)
19:56:07,948 INFO  [stdout] (Thread-281)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
19:56:07,949 INFO  [stdout] (Thread-281)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
19:56:07,949 INFO  [stdout] (Thread-281)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
19:56:07,949 INFO  [stdout] (Thread-281)    at java.lang.reflect.Method.invoke(Method.java:497)
19:56:07,949 INFO  [stdout] (Thread-281)    at org.hotswap.agent.plugin.weld.command.BeanClassRefreshCommand.executeCommand(BeanClassRefreshCommand.java:93)
19:56:07,949 INFO  [stdout] (Thread-281)    at org.hotswap.agent.command.impl.CommandExecutor.run(CommandExecutor.java:25)
19:56:07,950 INFO  [stdout] (Thread-281) 
19:56:08,030 INFO  [stdout] (Thread-282) HOTSWAP AGENT: 19:56:08.030 INFO (org.hotswap.agent.plugin.wildfly.el.PurgeWildFlyBeanELResolverCacheCommand) - Cleaning  BeanPropertiesCache lgc.mysynap.ui.components.SourcePopup ModuleClassLoader for Module "deployment.mysynap-0.1.war:main" from Service Module Loader.
@skybber

This comment has been minimized.

Contributor

skybber commented Dec 25, 2016

Strange.., field contexts is in BeanManagerImpl since weld 2.0 at least. What version of weld/java do you use ?

@geert3

This comment has been minimized.

geert3 commented Dec 26, 2016

This is using Wildfly 10 provided version of Weld. Below are all weld-related jars in the distribution.

./org/jboss/as/jsf-injection/main/weld-core-jsf-2.3.2.Final.jar
./org/jboss/as/weld/main/wildfly-weld-10.0.0.Final.jar
./org/jboss/weld/api/main/weld-api-2.3.Final.jar
./org/jboss/weld/core/main/weld-core-impl-2.3.2.Final.jar
./org/jboss/weld/probe/main/weld-probe-core-2.3.2.Final.jar
./org/jboss/weld/spi/main/weld-spi-2.3.Final.jar

Hope this helps
best
g

@geert3

This comment has been minimized.

geert3 commented Dec 26, 2016

Funnily enough there is indeed a contexts field. But the lookup is using Class.getField which is supposed to only return public fields. Shouldn't it be using Class.getDeclaredField instead? From the getField JavaDoc:

Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object. The name parameter is a String specifying the simple name of the desired field.

See attached screenshot with stack trace and BeanManagerImpl fields.

stack

@skybber skybber closed this in 8b2359a Dec 26, 2016

@skybber

This comment has been minimized.

Contributor

skybber commented Dec 26, 2016

Yes, that is the problem, thanks. I've commit fix using HA way how to setup accessibility flag.

@geert3

This comment has been minimized.

geert3 commented Dec 26, 2016

Seems some tests fail now?

Tests run: 8, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 7.716 sec <<< FAILURE! - in org.hotswap.agent.plugin.weld.WeldPluginTest
newBeanClassIsManagedBeanReRunTestOnlyAfterMvnClean(org.hotswap.agent.plugin.weld.WeldPluginTest)  Time elapsed: 0.127 sec  <<< ERROR!
java.lang.RuntimeException: org.hotswap.agent.javassist.CannotCompileException:
by java.lang.LinkageError: loader (instance of  sun/misc/Launcher$AppClassLoader): attempted  duplicate class definition for name: "NewClass"
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.hotswap.agent.javassist.ClassPool.toClass2(ClassPool.java:1082)
        at org.hotswap.agent.javassist.ClassPool.toClass(ClassPool.java:1067)
        at org.hotswap.agent.javassist.ClassPool.toClass(ClassPool.java:1019)
        at org.hotswap.agent.javassist.ClassPool.toClass(ClassPool.java:978)
        at org.hotswap.agent.javassist.CtClass.toClass(CtClass.java:1224)
        at org.hotswap.agent.plugin.hotswapper.HotSwapper.newClass(HotSwapper.java:51)
        at org.hotswap.agent.plugin.weld.WeldPluginTest.newBeanClassIsManagedBeanReRunTestOnlyAfterMvnClean(WeldPluginTest.java:184)

hotswapPrototypeTestNotFailWhenHoldingInstanceBecauseSingletonInjectionPointWasReinitialize(org.hotswap.agent.plugin.weld.WeldPluginTest)  Time elapsed: 0.638 sec  <<< ERROR!
java.lang.NullPointerException: null
        at org.hotswap.agent.plugin.weld.testBeans.HelloServiceImpl.hello(HelloServiceImpl.java:16)
        at org.hotswap.agent.plugin.weld.testBeans.DependentHello.hello(DependentHello.java:15)
        at org.hotswap.agent.plugin.weld.WeldPluginTest.hotswapPrototypeTestNotFailWhenHoldingInstanceBecauseSingletonInjectionPointWasReinitialize(WeldPluginTest.java:173)

Weld SE container STATIC_INSTANCE shut down by shutdown hook

Results :

Tests in error:
  WeldPluginTest.newBeanClassIsManagedBeanReRunTestOnlyAfterMvnClean:184 » Runtime
  WeldPluginTest.hotswapPrototypeTestNotFailWhenHoldingInstanceBecauseSingletonInjectionPointWasReinitialize:173 » NullPointer

Tests run: 8, Failures: 0, Errors: 2, Skipped: 0

@geert3

This comment has been minimized.

geert3 commented Dec 26, 2016

Also, possibly another instance of getField() that requires similar modification:

9:19:40,202 INFO  [stdout] (Thread-288) HOTSWAP AGENT: 19:19:40.149 WARNING (org.hotswap.agent.plugin.weld.beans.ContextualReloadHelper) - Context org.jboss.weld.context.unbound.DependentContextImpl@23a5be48 is not patched. Can not add Managed Bean [class lgc.mysynap.ui.components.ProgramDetails] with qualifiers [@Any @Default] to reload set
19:19:40,203 INFO  [stdout] (Thread-288) java.lang.NoSuchFieldException: _toReload
19:19:40,203 INFO  [stdout] (Thread-288) 	at java.lang.Class.getField(Class.java:1703)
19:19:40,203 INFO  [stdout] (Thread-288) 	at org.hotswap.agent.plugin.weld.beans.ContextualReloadHelper.addToReloadSet(ContextualReloadHelper.java:52)
19:19:40,203 INFO  [stdout] (Thread-288) 	at org.hotswap.agent.plugin.weld.command.BeanDeploymentArchiveAgent.reloadManagedBeanInContexts(BeanDeploymentArchiveAgent.java:322)
19:19:40,203 INFO  [stdout] (Thread-288) 	at org.hotswap.agent.plugin.weld.command.BeanDeploymentArchiveAgent.reloadManagedBean(BeanDeploymentArchiveAgent.java:293)
19:19:40,203 INFO  [stdout] (Thread-288) 	at org.hotswap.agent.plugin.weld.command.BeanDeploymentArchiveAgent.reloadBean(BeanDeploymentArchiveAgent.java:231)
19:19:40,204 INFO  [stdout] (Thread-288) 	at org.hotswap.agent.plugin.weld.command.BeanDeploymentArchiveAgent.refreshBeanClass(BeanDeploymentArchiveAgent.java:192)
19:19:40,204 INFO  [stdout] (Thread-288) 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
19:19:40,204 INFO  [stdout] (Thread-288) 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
19:19:40,204 INFO  [stdout] (Thread-288) 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
19:19:40,204 INFO  [stdout] (Thread-288) 	at java.lang.reflect.Method.invoke(Method.java:497)
19:19:40,204 INFO  [stdout] (Thread-288) 	at org.hotswap.agent.plugin.weld.command.BeanClassRefreshCommand.executeCommand(BeanClassRefreshCommand.java:93)
19:19:40,204 INFO  [stdout] (Thread-288) 	at org.hotswap.agent.command.impl.CommandExecutor.run(CommandExecutor.java:25)
19:19:40,204 INFO  [stdout] (Thread-288) 

@skybber

This comment has been minimized.

Contributor

skybber commented Dec 26, 2016

As far as unit test fail - try to do mvn clean before build. I've just tested it and it seems ok.

@skybber

This comment has been minimized.

Contributor

skybber commented Dec 26, 2016

_toReload is defined as plublic, therefore it should work... I will fix it too...

@skybber skybber reopened this Dec 26, 2016

@skybber skybber closed this Dec 26, 2016

@skybber skybber reopened this Dec 26, 2016

@geert3

This comment has been minimized.

geert3 commented Dec 26, 2016

working fine now! thanks

@skybber

This comment has been minimized.

Contributor

skybber commented Dec 27, 2016

Thanks too.

@skybber skybber closed this Dec 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment