Uploaded image for project: 'Alfresco'
  1. Alfresco
  2. ALF-21843

IllegalAccessException when using Java 8 lambda as policy implementation

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: Community Edition 201612 GA
    • Fix Version/s: None
    • Component/s: Repository
    • Security Level: external (External user)
    • Labels:
      None
    • Environment:
      Windows 10, Oracle JDK 1.8.0_112 64-bit

      Description

      Since all policy interfaces (e.g. OnUpdatePropertiesPolicy) only define a single method to be implemented, it is possible to use Java 8 lambda expressions when binding custom policies. There is no error on startup and registration - the bound policy passes all checks. But when it is actually being invoked there will be an IllegalAccessException.

      Exception message:
      Caused by: java.lang.IllegalAccessException: Class org.alfresco.repo.policy.JavaBehaviour$JavaMethodInvocationHandler can not access a member of class com.acme.training22.service.BusinessDocumentServiceImpl$$Lambda$11/798822706 with modifiers "public"
      at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
      at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
      at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
      at java.lang.reflect.Method.invoke(Method.java:491)
      at org.alfresco.repo.policy.JavaBehaviour$JavaMethodInvocationHandler.invoke(JavaBehaviour.java:181)

      Example code:

      public void bindBehaviour()
      {
          OnUpdatePropertiesPolicy policy = (nodeRef, before, after) -> {
              if (StoreRef.STORE_REF_WORKSPACE_SPACESTORE.equals(nodeRef.getStoreRef())
              {
                  // TODO actual implementation
              }
          };
          this.policyComponent.bindClassBehaviour(OnUpdatePropertiesPolicy.QNAME, ContentModel.TYPE_CONTENT, new JavaBehaviour(policy, "onUpdateProperties", NotificationFrequency.EVERY_EVENT));
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                closedissues Closed Issues
                Reporter:
                afaust Axel Faust
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Date of First Response: