Uploaded image for project: 'Aries'
  1. Aries
  2. ARIES-1724

Proxy generates calls to static methods in <clinit> which can fail on Java 9

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • None
    • Proxy
    • None
    • Java 9

    Description

      The issue is that the JVMS was changed in Java 9 to disallow "final" fields from being modified outside of the <clinit> method. Even other methods called by <clinit>.
      "if the field is final the instruction must occur in the < clinit > method of the current class. Otherwise, an IllegalAccessError is thrown."

      The issue here is that aires generates method proxies that stores references to the generated methods in 'private static final' fields, which it then assigns in woven static init weaving code by calling another generated static method.

      It seems that we can trivially fix this by removing the 'final' modifier of the generated method field.

      Here is what the current generated code would looking as a java class:

      Foo.java
      public class Foo {
        static final boolean bar;
        static {
          setBar(); // blows up with IAE as of class version >= 53
        }
        static void setBar() {
          bar = true;
        }
      }
      

      Where the bar field is a field declared by the proxy code and set by another static method which is called by the <clinit> block. A proper fix would be to change the generated code to do something more like this:

      Foo.java
      public class Foo {
          static final boolean bar;
          static {
              bar = getBar();
          }
          static boolean getBar() {
              return true;
          }
      }
      

      But as of now I am not sure how complicated of a change that would be to the proxy code. The simple fix is to not generate these static private fields as final.

      Attachments

        Activity

          People

            tjwatson Tom Watson
            tjwatson Tom Watson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: