0 Replies Latest reply on Nov 2, 2003 7:57 AM by max goff

    NullPointerException in DistributedPOJOState.fieldRead()

    max goff Newbie

      Brief: NullPointerException in org.jboss.aop.versioned.DistributedPOJOState.fieldRead()

      I am trying to work with the Transactional Cache example present at http://www.jboss.org/index.html?module=html&op=userdisplay&id=developers/projects/jboss/aop#cache on jboss-4.0.0DR2.

      I have two classes 'Person' and 'Address', as in the example, defined in package 'usm'. I have defined Person and Address to be advisable as:



      The code that I am running looks like this:
      final long lockTimeoutInMillis = 1000;
      final int cacheSize = 100;
      Address address = new Address("55 street road", "Boston", "MA");
      Person person = new Person("Bill", 32, address);
      TxCache cache = new TxCache(cacheSize, lockTimeoutInMillis);
      try {
      javax.transaction.TransactionManager tm = some code that gets reference of Transaction Manager;
      cache.create();
      cache.start();
      System.out.println("cache.start() called");
      cache.insert("Bill", person);
      System.out.println("Person inserted in cache");
      tm.begin();
      System.out.println("tm.begin() called");
      person.address.city = "Bedford";
      System.out.println("Bedford set");
      person.age = 42;
      System.out.println("Age set");
      System.out.println("person = " + person);
      System.out.println("Before rolling back tx : " + person.address.city);
      tm.rollback();
      person = (Person) cache.get("Bill");
      System.out.println("After rollback : " + person.address.city);
      } catch (Exception ex) {
      System.out.println("***************************************************");
      System.out.println(ex.getMessage());
      ex.printStackTrace();
      System.out.println("***************************************************");
      System.out.println("***************************************************");
      }


      With this code, I am getting a NullPointerException as seen from this stack trace:
      19:42:27,406 INFO [STDOUT] cache.start() called
      19:42:27,421 INFO [STDOUT] VersionManager: 3j001-xvt1ww-dmj61atj-1-dmj61g9a-3
      19:42:27,484 INFO [STDOUT] VersionManager: 3j001-xvt1ww-dmj61atj-1-dmj61gbg-4
      19:42:27,500 INFO [STDOUT] VERSION REFERENCE CREATION: 3j001-xvt1ww-dmj61atj-1-dmj61gbg-4
      19:42:27,875 INFO [STDOUT] VERSION REFERENCE CREATION: 3j001-xvt1ww-dmj61atj-1-dmj61gkk-5
      19:42:27,875 INFO [STDOUT] Person inserted in cache
      19:42:28,078 INFO [STDOUT] tm.begin() called
      19:42:28,078 INFO [STDOUT] **** fieldRead:: fieldInvocation.field = public usm.Address usm.Person.address
      19:42:28,125 INFO [STDOUT] **** fieldRead:: index = 0
      19:42:28,125 INFO [STDOUT] **** fieldRead:: map set inside if()
      19:42:28,125 INFO [STDOUT] **** fieldRead:: map = {3=org.jboss.aop.versioned.DistributedFieldUpdate@3, 2=org.jboss.aop.versioned.DistributedFieldUpdate@2, 1=org.jboss.aop.versioned.DistributedFieldUpdate@1, 0=org.jboss.aop.versioned.DistributedFieldUpdate@0}
      19:42:28,171 INFO [STDOUT] **** fieldRead:: map.size = 4
      19:42:28,171 INFO [STDOUT] **** fieldRead:: ref = org.jboss.aop.versioned.DistributedFieldUpdate@0
      19:42:28,171 INFO [STDOUT] **** fieldRead:: update = org.jboss.aop.versioned.DistributedFieldUpdate@0
      19:42:28,171 INFO [STDOUT] **** fieldRead:: val = usm.Address@56b93a
      19:42:28,187 INFO [STDOUT] Bedford set
      19:42:28,187 INFO [STDOUT] Age set
      19:42:28,234 INFO [STDOUT] **** fieldRead:: fieldInvocation.field = public java.lang.String usm.Person.name
      19:42:28,234 INFO [STDOUT] **** fieldRead:: index = 3
      19:42:28,234 INFO [STDOUT] **** fieldRead:: map = {1=org.jboss.aop.versioned.DistributedFieldUpdate@1}
      19:42:28,250 INFO [STDOUT] **** fieldRead:: map.size = 1
      19:42:28,250 INFO [STDOUT] **** fieldRead:: ref = null
      19:42:28,250 INFO [STDOUT] **** fieldRead:: update = null
      19:42:28,296 INFO [STDOUT] ***************************************************
      19:42:28,296 INFO [STDOUT] null
      19:42:28,296 ERROR [STDERR] java.lang.NullPointerException
      19:42:28,296 ERROR [STDERR] at org.jboss.aop.versioned.DistributedPOJOState.fieldRead(DistributedPOJOState.java:136)
      19:42:28,312 ERROR [STDERR] at org.jboss.aop.versioned.StateChangeInterceptor.invoke(StateChangeInterceptor.java:48)
      19:42:28,312 ERROR [STDERR] at org.jboss.aop.Invocation.invokeNext(Invocation.java:61)
      19:42:28,343 ERROR [STDERR] at org.jboss.aop.ClassAdvisor.invokeRead(ClassAdvisor.java:820)
      19:42:28,343 ERROR [STDERR] at org.jboss.aop.ClassAdvisor.trapRead(ClassAdvisor.java:996)
      19:42:28,343 ERROR [STDERR] at usm.Person._added_m$1(Person.java)
      19:42:28,343 ERROR [STDERR] at usm.Person.name_r_$WithoutAdvisement(Person.java)
      19:42:28,359 ERROR [STDERR] at usm.Person.usm$Person$toString$WithoutAdvisement(Person.java:21)
      19:42:28,359 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      19:42:28,390 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      19:42:28,390 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      19:42:28,390 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
      19:42:28,390 ERROR [STDERR] at org.jboss.aop.ClassAdvisor$MethodTailInterceptor.invoke(ClassAdvisor.java:865)
      19:42:28,406 ERROR [STDERR] at org.jboss.aop.Invocation.invokeNext(Invocation.java:61)
      19:42:28,406 ERROR [STDERR] at org.jboss.aop.versioned.StateChangeInterceptor.invoke(StateChangeInterceptor.java:42)
      19:42:28,453 ERROR [STDERR] at org.jboss.aop.Invocation.invokeNext(Invocation.java:61)
      19:42:28,453 ERROR [STDERR] at org.jboss.aop.ClassAdvisor.invokeMethod(ClassAdvisor.java:729)
      19:42:28,453 ERROR [STDERR] at org.jboss.aop.ClassAdvisor.invokeMethod(ClassAdvisor.java:705)
      19:42:28,453 ERROR [STDERR] at usm.Person._added_m$0(Person.java)
      19:42:28,468 ERROR [STDERR] at usm.Person.toString(Person.java)
      19:42:28,468 ERROR [STDERR] at java.lang.String.valueOf(String.java:2173)
      19:42:28,500 ERROR [STDERR] at java.lang.StringBuffer.append(StringBuffer.java:369)
      19:42:28,500 ERROR [STDERR] at usm.JBossAopDemo.(JBossAopDemo.java:35)
      19:42:28,500 ERROR [STDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      19:42:28,500 ERROR [STDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      19:42:28,515 ERROR [STDERR] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      19:42:28,515 ERROR [STDERR] at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
      19:42:28,546 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.instantiate(MBeanServerImpl.java:909)
      19:42:28,546 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.instantiate(MBeanServerImpl.java:297)
      19:42:28,546 ERROR [STDERR] at org.jboss.system.ServiceCreator.install(ServiceCreator.java:122)
      19:42:28,546 ERROR [STDERR] at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigurator.java:159)
      19:42:28,593 ERROR [STDERR] at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:116)
      19:42:28,593 ERROR [STDERR] at org.jboss.system.ServiceController.install(ServiceController.java:229)
      19:42:28,593 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      19:42:28,609 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      19:42:28,609 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      19:42:28,640 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
      19:42:28,640 ERROR [STDERR] at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:72)
      19:42:28,640 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:45)
      19:42:28,656 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:70)
      19:42:28,656 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:155)
      19:42:28,687 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:544)
      19:42:28,687 ERROR [STDERR] at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:172)
      19:42:28,687 ERROR [STDERR] at $Proxy6.install(Unknown Source)
      19:42:28,687 ERROR [STDERR] at org.jboss.deployment.SARDeployer.create(SARDeployer.java:185)
      19:42:28,703 ERROR [STDERR] at org.jboss.deployment.DeploymentInfo.create(DeploymentInfo.java:243)
      19:42:28,703 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      19:42:28,734 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      19:42:28,734 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      19:42:28,734 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
      19:42:28,734 ERROR [STDERR] at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:72)
      19:42:28,750 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:45)
      19:42:28,750 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:70)
      19:42:28,781 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:155)
      19:42:28,781 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:544)
      19:42:28,781 ERROR [STDERR] at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:1036)
      19:42:28,781 ERROR [STDERR] at $Proxy9.create(Unknown Source)
      19:42:28,796 ERROR [STDERR] at org.jboss.system.ServiceController.create(ServiceController.java:307)
      19:42:28,796 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      19:42:28,828 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      19:42:28,828 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      19:42:28,828 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
      19:42:28,890 ERROR [STDERR] at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:72)
      19:42:28,890 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:45)
      19:42:28,890 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:70)
      19:42:28,890 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:155)
      19:42:28,906 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:544)
      19:42:28,906 ERROR [STDERR] at org.jboss.deployment.MainDeployer.create(MainDeployer.java:748)
      19:42:28,937 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:593)
      19:42:28,937 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:558)
      19:42:28,937 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      19:42:28,984 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      19:42:28,984 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      19:42:28,984 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
      19:42:28,984 ERROR [STDERR] at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:72)
      19:42:29,031 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:45)
      19:42:29,031 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:70)
      19:42:29,031 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:155)
      19:42:29,046 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:544)
      19:42:29,046 ERROR [STDERR] at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:172)
      19:42:29,078 ERROR [STDERR] at $Proxy8.deploy(Unknown Source)
      19:42:29,078 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:405)
      19:42:29,078 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:529)
      19:42:29,078 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:200)
      19:42:29,093 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:211)
      19:42:29,093 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:190)
      19:42:29,140 INFO [STDOUT] ***************************************************
      19:42:29,140 INFO [STDOUT] ***************************************************



      Here, the code on line 136 of DistributedPOJOState.java (I have only added some println() statements to this method for debugging) points to "Object val = update.getValue();" present in the code given below:
      public InvocationResponse fieldRead(Invocation invocation) throws Throwable {
      acquireReadLock();
      InvocationResponse invocationresponse;
      try {
      FieldReadInvocation fieldInvocation = (FieldReadInvocation)invocation;
      System.out.println("**** fieldRead:: fieldInvocation.field = " + fieldInvocation.field);
      Integer index = new Integer(fieldInvocation.index);
      System.out.println("**** fieldRead:: index = " + index);
      HashMap map = getTxState();

      if(map == null) {
      map = fieldMap;
      System.out.println("**** fieldRead:: map set inside if()");
      }
      System.out.println("**** fieldRead:: map = " + map);
      System.out.println("**** fieldRead:: map.size = " + map.size());
      Object ref = map.get(index);
      System.out.println("**** fieldRead:: ref = " + ref);
      DistributedFieldUpdate update = (DistributedFieldUpdate) ref;
      System.out.println("**** fieldRead:: update = " + update);
      Object val = update.getValue();
      System.out.println("**** fieldRead:: val = " + val);
      invocationresponse = new InvocationResponse(val);
      } finally {
      releaseReadLock();
      }
      return invocationresponse;
      }

      What am I missing here? Is there a problem with the code or with the AOP settings I have made to make Person and Address ?
      Anyways does this help: The stack trace includes the line "19:42:28,234 INFO [STDOUT] **** fieldRead:: map = {1=org.jboss.aop.versioned.DistributedFieldUpdate@1}".
      The map here contains an element whose index is '1'. Should it be '0'?