Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-5729

NoSuchFieldError when @Reference referenceInterface type different than field type

    XMLWordPrintableJSON

    Details

      Description

      NoSuchFieldError is thrown when injecting dependencies for a component Foo that has a field bar of type T1 with @Reference(referenceInterface = T2.class) and T2 implements T1.
      This error is caused by the bind/unbind methods generated by maven-scr-plugin which have bytecode generated for get/set field bar operations with field descriptor of type T2 instead of T1.

      Bytecode:

      protected void bindBar(T2);
          Code:
             0: aload_0
             1: aload_1
             2: putfield      #95                 // Field bar:LT2;
             5: return
      
        protected void unbindBar(T2);
          Code:
             0: aload_0
             1: getfield      #95                 // Field bar:LT2;
             4: aload_1
             5: if_acmpne     13
             8: aload_0
             9: aconst_null
            10: putfield      #95                 // Field bar:LT2;
      

      StackTrace:

      The bindBar method has thrown an exception (java.lang.NoSuchFieldError: bar)
      java.lang.NoSuchFieldError: bar
      	at Foo.bindBar(Foo.java)
      	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.apache.felix.scr.impl.inject.BaseMethod.invokeMethod(BaseMethod.java:224)
      	at org.apache.felix.scr.impl.inject.BaseMethod.access$500(BaseMethod.java:39)
      	at org.apache.felix.scr.impl.inject.BaseMethod$Resolved.invoke(BaseMethod.java:617)
      	at org.apache.felix.scr.impl.inject.BaseMethod.invoke(BaseMethod.java:501)
      	at org.apache.felix.scr.impl.inject.BindMethod.invoke(BindMethod.java:655)
      	at org.apache.felix.scr.impl.manager.DependencyManager.doInvokeBindMethod(DependencyManager.java:1722)
      	at org.apache.felix.scr.impl.manager.DependencyManager.open(DependencyManager.java:1556)
      	at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:261)
      	at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:109)
      	at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:906)
      	at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:879)
      	at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:823)
      

        Attachments

          Activity

            People

            • Assignee:
              cziegeler Carsten Ziegeler
              Reporter:
              ioancris Ioan-Cristian Linte
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: