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

            Hide
            resplin Richard Esplin added a comment -

            The [~platformdeliveryteam] will research what is involved with addressing this issue.

            Show
            resplin Richard Esplin added a comment - The [~platformdeliveryteam] will research what is involved with addressing this issue.
            Hide
            resplin Richard Esplin added a comment -

            Thank you Axel for pointing out this problem. We discussed this with the responsible engineering architect, and it is helpful now that we are aware of it.

            Our team is currently focused on building out a more complete set of REST APIs so that integrations can move out-of-process. Because there is a clear workaround for this issue (don't use lambdas), we won't be fixing it in the near future. But we will pay attention to how we can use the new features in Java 8 in the future.

            Show
            resplin Richard Esplin added a comment - Thank you Axel for pointing out this problem. We discussed this with the responsible engineering architect, and it is helpful now that we are aware of it. Our team is currently focused on building out a more complete set of REST APIs so that integrations can move out-of-process. Because there is a clear workaround for this issue (don't use lambdas), we won't be fixing it in the near future. But we will pay attention to how we can use the new features in Java 8 in the future.

              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: