4 Replies Latest reply on Oct 8, 2015 7:00 PM by Radek Koubský

    AFTER WRITE - NullPointerException

    Radek Koubský Newbie

      Hello,

      I reported one issue (the first one in Unexpected behavior in TRY-CATCH-FINALLY) with AFTER WRITE location specifier which throws NullPointerException after compilation.

      I have same problem, but I am not sure if this is the same situation because there is no try-catch-finally around the definition of local variable interceptorBindings, which is used for AFTER WRITE.

      Env:

      Byteman 3.0.1

      wildfly-8.2.0.Final - wildfly/Jsr299BindingsInterceptor.java at 8.x · wildfly/wildfly · GitHub

       

      Source code:

      @Override
          public Object processInvocation(final InterceptorContext context) throws Exception {
              final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
              final WeldInterceptorInstances interceptorInstances = (WeldInterceptorInstances) componentInstance.getInstanceData(SerializedCdiInterceptorsKey.class);
              final InterceptorBindings interceptorBindings = this.interceptorBindings.getValue();
              switch (interceptionType) {
                  case AROUND_INVOKE:
                      return doMethodInterception(context.getInvocationContext(), InterceptionType.AROUND_INVOKE, interceptorInstances, interceptorBindings);
                  case AROUND_TIMEOUT:
                      return doMethodInterception(context.getInvocationContext(), InterceptionType.AROUND_TIMEOUT, interceptorInstances, interceptorBindings);
                  case PRE_DESTROY:
                      try {
                          return doLifecycleInterception(context, interceptorInstances, interceptorBindings);
                      } finally {
                          interceptorInstances.getCreationalContext().release();
                      }
                  case POST_CONSTRUCT:
                      return doLifecycleInterception(context, interceptorInstances, interceptorBindings);
                  case AROUND_CONSTRUCT:
                      return doLifecycleInterception(context, interceptorInstances, interceptorBindings);
                  default:
                      //should never happen
                      return context.proceed();
              }
      
      
      
      

       

      and my rule:

      #Log process invocation
      RULE logJsr299BindingsInterceptor.processInvocation
      CLASS org.jboss.as.weld.ejb.Jsr299BindingsInterceptor
      METHOD processInvocation(InterceptorContext)
      AFTER WRITE $interceptorBindings
      IF true
      DO log($CLASS, "DEBUG", "(Method processInvocation) Processing invocation, getting interceptor instances and bindings:\n" +
        "InterceptorContext: " + $context + "\ninterceptionType: " + $0.interceptionType +
        "\ninterceptorInstances: " + ($interceptorInstances == null ? "null" : $interceptorInstances.interceptorInstances) +
        "\n" + "interceptorBindings - all interceptors: " + ($interceptorBindings == null ? "null" : $interceptorBindings.getAllInterceptors()))
      
      
      
      

       

      this throws NullPointerException when rule is being compiled:

      RULE logJsr299BindingsInterceptor.processInvocation

      CLASS org.jboss.as.weld.ejb.Jsr299BindingsInterceptor

      METHOD processInvocation(InterceptorContext)

      HELPER org.jboss.byteman.koubsky.LogHelper

      AFTER WRITE $interceptorBindings

      IF true

      DO log($CLASS, "DEBUG", "(Method processInvocation) Processing invocation, getting interceptor instances and bindings:\n" +

      "InterceptorContext: " + $context + "\ninterceptionType: " + $0.interceptionType +

      "\ninterceptorInstances: " + ($interceptorInstances == null ? "null" : $interceptorInstances.interceptorInstances) +

      "\n" + "interceptorBindings - all interceptors: " + ($interceptorBindings == null ? "null" : $interceptorBindings.getAllInterceptors()))

      ENDRULE

      Transformed in:

      loader: ModuleClassLoader for Module "org.jboss.as.weld:main" from local module loader @6fb525d8 (finder: local module finder @5dc7c133 (roots: /home/koubsky/Wildfly8/wildfly-8.2.0.Final/modules,/home/koubsky/Wildfly8/wildfly-8.2.0.Final/modules/system/layers/base))

      trigger class: org.jboss.as.weld.ejb.Jsr299BindingsInterceptor

      threw java.lang.NullPointerException

      java.lang.NullPointerException

      at org.jboss.byteman.agent.adapter.cfg.CFG.inBytemanTrigger(CFG.java:1704)

      at org.jboss.byteman.agent.adapter.RuleTriggerMethodAdapter.inBytemanTrigger(RuleTriggerMethodAdapter.java:588)

      at org.jboss.byteman.agent.adapter.VariableAccessTriggerAdapter$VariableAccessTriggerMethodAdapter.visitVarInsn(VariableAccessTriggerAdapter.java:136)

      at org.jboss.byteman.objectweb.asm.tree.VarInsnNode.accept(Unknown Source)

      at org.jboss.byteman.agent.adapter.BMInsnList.accept(BMInsnList.java:81)

      at org.jboss.byteman.objectweb.asm.tree.MethodNode.accept(Unknown Source)

      at org.jboss.byteman.objectweb.asm.commons.JSRInlinerAdapter.visitEnd(Unknown Source)

      at org.jboss.byteman.objectweb.asm.ClassReader.b(Unknown Source)

      at org.jboss.byteman.objectweb.asm.ClassReader.accept(Unknown Source)

      at org.jboss.byteman.objectweb.asm.ClassReader.accept(Unknown Source)

      at org.jboss.byteman.agent.TransformContext.transform(TransformContext.java:150)

      at org.jboss.byteman.agent.Transformer.transform(Transformer.java:746)

      at org.jboss.byteman.agent.Transformer.tryTransform(Transformer.java:814)

      at org.jboss.byteman.agent.Transformer.tryTransform(Transformer.java:785)

      at org.jboss.byteman.agent.Transformer.transform(Transformer.java:257)

      at sun.instrument.TransformerManager.transform(TransformerManager.java:188)

      at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:424)

      at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)

      at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)

      at org.jboss.byteman.agent.Retransformer.installScript(Retransformer.java:144)

      at org.jboss.byteman.agent.TransformListener.handleScripts(TransformListener.java:349)

      at org.jboss.byteman.agent.TransformListener.loadScripts(TransformListener.java:272)

      at org.jboss.byteman.agent.TransformListener.handleConnection(TransformListener.java:225)

      at org.jboss.byteman.agent.TransformListener.run(TransformListener.java:158)

       

      Thanks for your comments.

        • 1. Re: AFTER WRITE - NullPointerException
          Andrew Dinn Master

          Hi Radek,

           

          I have uploaded a SNAPSHOT jar to the Sonatype snapshot repo containing a patch for this very same bug as reported by Marco Rietveld. I am still waiting to see if this fixes his problem. Could you try making your project depend on this jar and then check whether it fixes the bugs you are seeing. You will need to change your byteman dependency to use version 3.0.2-SNAPSHOT and add the Sonatype snapshot repo in the list of repositories configured in your pom

           

          <repositories>
              <repository>
                  <id>ow2</id>
                  <name>ow2 release repository</name>
                  <url>://oss.sonatype.org/content/repositories/snapshots</url>
              </repository>
              . . .
          </repositories>
          

           

          Let me know if ti fixes wither or both of your problems.

          • 2. Re: AFTER WRITE - NullPointerException
            Radek Koubský Newbie

            Thanks for uploading the jar. Unfortunately, I am not able to download byteman dependency, build fails with following exception:

             

            [ERROR] Failed to execute goal on project byteman-wildfly-log: Could not resolve dependencies for project org.jboss.byteman:byteman-wildfly-log:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at org.jboss.byteman:byteman:jar:3.0.2-SNAPSHOT: Failed to read artifact descriptor for org.jboss.byteman:byteman:jar:3.0.2-SNAPSHOT: Could not transfer artifact org.jboss.byteman:byteman:pom:3.0.2-SNAPSHOT from/to ow2 (://oss.sonatype.org/content/repositories/snapshots): No connector available to access repository ow2 (://oss.sonatype.org/content/repositories/snapshots) of type default using the available factories AetherRepositoryConnectorFactory, WagonRepositoryConnectorFactory -> [Help 1]
            org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project byteman-wildfly-log: Could not resolve dependencies for project org.jboss.byteman:byteman-wildfly-log:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at org.jboss.byteman:byteman:jar:3.0.2-SNAPSHOT
              at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:220)
              at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies(LifecycleDependencyResolver.java:127)
              at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved(MojoExecutor.java:257)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:200)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
              at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
              at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
              at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
              at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
              at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
              at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
              at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
              at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
              at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
              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 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
              at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
              at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
              at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
            Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project org.jboss.byteman:byteman-wildfly-log:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at org.jboss.byteman:byteman:jar:3.0.2-SNAPSHOT
              at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:167)
              at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:195)
              ... 22 more
            Caused by: org.eclipse.aether.collection.DependencyCollectionException: Failed to collect dependencies at org.jboss.byteman:byteman:jar:3.0.2-SNAPSHOT
              at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:292)
              at org.eclipse.aether.internal.impl.DefaultRepositorySystem.collectDependencies(DefaultRepositorySystem.java:317)
              at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:159)
              ... 23 more
            Caused by: org.eclipse.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for org.jboss.byteman:byteman:jar:3.0.2-SNAPSHOT
              at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:335)
              at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:217)
              at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:461)
              at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:261)
              ... 25 more
            Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact org.jboss.byteman:byteman:pom:3.0.2-SNAPSHOT from/to ow2 (://oss.sonatype.org/content/repositories/snapshots): No connector available to access repository ow2 (://oss.sonatype.org/content/repositories/snapshots) of type default using the available factories AetherRepositoryConnectorFactory, WagonRepositoryConnectorFactory
              at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:459)
              at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:262)
              at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:239)
              at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:320)
              ... 28 more
            Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact org.jboss.byteman:byteman:pom:3.0.2-SNAPSHOT from/to ow2 (://oss.sonatype.org/content/repositories/snapshots): No connector available to access repository ow2 (://oss.sonatype.org/content/repositories/snapshots) of type default using the available factories AetherRepositoryConnectorFactory, WagonRepositoryConnectorFactory
              at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:546)
              at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:436)
              ... 31 more
            Caused by: org.eclipse.aether.transfer.NoRepositoryConnectorException: No connector available to access repository ow2 (://oss.sonatype.org/content/repositories/snapshots) of type default using the available factories AetherRepositoryConnectorFactory, WagonRepositoryConnectorFactory
              at org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider.newRepositoryConnector(DefaultRepositoryConnectorProvider.java:193)
              at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:531)
              ... 32 more
            [ERROR] 
            [ERROR] 
            [ERROR] For more information about the errors and possible solutions, please read the following articles:
            [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
            

             

            I have one question about BYTEMAN_HOME? Shouldn't I put the new jar to my BYTEMAN_HOME directory where Wildfly looks for its javaagent?

            This is taken from my standalone.conf:

            JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.byteman.transform.all -javaagent:${BYTEMAN_HOME}/lib/byteman.jar=script:${HOME}/byteman-wildfly-log/rules/ejb.btm,sys:${HOME}/byteman-wildfly-log/target/byteman-wildfly-log-0.0.1-SNAPSHOT.jar,listener:true"
            
            • 3. Re: AFTER WRITE - NullPointerException
              Andrew Dinn Master

              Oops! Two problems caused by me :-]

               

              Problem 1:

               

              Firstly, the download error is because I mistyped the snapshot repo URL (it needs an http prefix). The repositories config should say

               

               

              <repositories>
                <repository>
                  <id>ow2</id>
                  <name>ow2 release repository</name>
                  <url>http://oss.sonatype.org/content/repositories/snapshots</url>
                  </repository>
              </repositories>
              

               

              Problem 2:

               

              Secondly, I did not realise that you were using BYTEMAN from the Java command line (I assumed you were running a unit test from maven). So, setting a maven dependency is not going to be any help at all. For command line use the byteman jar is picked up from the directory you specify as part of the javaagent command i.e. ${BYTEMAN_HOME}/lib/byteman.jar. So, you are right that you need to download the SNAPSHOT jar to your local disk, unzip it and then point BYTEMAN_HOME at the resulting directory.

               

              You can download the snapshot release as a zip file using Sonatype's Nexus manager. Point your browser at

               

                http://oss.sonatype.org/

               

              Click on 'Repositories' on the left hand side menu. Scroll down in the list of repositories that appears top centre in the Repositories tab until you reach an entry labelled 'Snapshots'. Click on that entry and you will see a tab open up below labelled 'Browse Storage'. Open up the tree by clicking on successive tabs

               

                org

                  jboss

                    byteman

                      byteman-downbload

                        3.0.2-SNAPSHOT

               

              Now click on file byteman-download-3.0.2-20151001.094023-2-full.zip and download it to your local machine. It should create a directrory called byteman-download-3.0.2-20151001.094023-2-full. Unzip the file and set BYTEMAN_HOME to point to this (n.b. you set BYTEMAN_HOME to the top level dir so you can use ti to locate other things like the byteman bin scripts -- byteman.jar is actually in subdirectory lib which is why you add  -javaagent:${BYTEMAN_HOME}/lib/byteman.jar to the java command line).

              • 4. Re: AFTER WRITE - NullPointerException
                Radek Koubský Newbie

                ad1)

                I added the http prefix, now eclipse shows red line "Missing artifact org.jboss.byteman:byteman:jar:3.0.2-SNAPSHOT" in my pom. However, when I run maven, it downloads artifact properly. I use the maven source for debugging, so it helps me as well.

                 

                ad2)

                I tried to run both of them and it works properly. I use AFTER WRITE in similar cases and every one works as well. So it seems that it fixes the problem. I think this is not the end with try - catch - finally,  I have another problem which I post in a new topic.

                Thank you again for the bug fix, it really helps me because I use AFTER WRITE often.