You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide APIs for construction with potentially inaccessible constructors #6
Pull request #4 raises a need to make some constructors (e.g. default constructor in the specific pull request case) useable when constructing objects using IntrinsicObjectModel. Similar needs exist in StructuredArray, and in some case they are supported by making the constructor accessible via reflection.
I am trying to avoid making constructors accessible this way for both default or non-default constructors, and will probably look to avoid doing the same in some of the StructuredArray cases that currently do (taking away the current accessible-forcing behavior). Making e.g. private or protected constructors accessible can lead to surprising and potentially insecure construction behavior.
Obviously, we have a problem here, in that a class that has access to a certain constructor that is not accessible from IntrinsicObjectModel or IntrinsicStraturedArray may want to declare intrinsic fields, structured arrays or inner classes with such fields or arrays using that accessible-only-to-it constructor. This will not be possible with the current API.
My hope is to address such situations in Java 7 and beyond with method handles. Unlike reflective calls to constructors, which have their accessibility checked at invocation time based on the calling class, Method handle based calls to constructors have the accessibility checked at lookup time. A class with access to a certain constructor can therefore provide a method handle to that constructor in a way that can be executed by IntrinsicObjectModel or IntrinsicStraturedArray.
Will update this issue when we make more progress.
@simonis commented on the subject in #4 , adding a suggested implementation that does not use method handles, but instead verifies that the caller (obtained via sun.reflect.Reflection.getCallerClass()) has access to the constructor before overriding it's accessibility. The change requires that the ObjectLayout library reside on the bootclasspath.
We can describe the concern we have with accessibility changes as "security", because most of the problems I'd expect would come from malicious code. They would instead come from breaking encapsulation visibility rules that help good code avoid bugs.
While the change proposed (so far) does achieve the needed restrictions, the bootclasspath requirement is a a problem. It will certainly work for intrinsified org.ObjectLayout implementations, and for anyone that can control the bootclasspath, but our requirement for the vanilla Java code versions is (currently) that it will work on regular JDKs without any changes to the JDK or special privileges. So I'm still looking for ideas on how to do this reliably with reflection without requiring bootclasspath access.
I believe that supporting method handles as an alternate constructor specification form for CtorAndArgs could provide an acceptable solution, but haven't coded that yet, so haven't found the problems with it yet either. The main drawback of doing that is that sacrificing Java SE 6 as a supported platform, which I would like to avoid. But between requiring bootclasspath and requiring Java SE 7 or later, I'd probably choose Java 7 right now.
Remi Forax has just posted his varhandle2 implementation on GitHub where he is using MethodHandles to check access rights to fields. I think that's a way how we could do the required accessibility checks as well, although Remi is apparently using MethodHandles.reflectAs() which was only introduced in Java 8 :(
Activity
giltene commentedon Dec 11, 2014
@simonis commented on the subject in #4 , adding a suggested implementation that does not use method handles, but instead verifies that the caller (obtained via sun.reflect.Reflection.getCallerClass()) has access to the constructor before overriding it's accessibility. The change requires that the ObjectLayout library reside on the bootclasspath.
We can describe the concern we have with accessibility changes as "security", because most of the problems I'd expect would come from malicious code. They would instead come from breaking encapsulation visibility rules that help good code avoid bugs.
While the change proposed (so far) does achieve the needed restrictions, the bootclasspath requirement is a a problem. It will certainly work for intrinsified org.ObjectLayout implementations, and for anyone that can control the bootclasspath, but our requirement for the vanilla Java code versions is (currently) that it will work on regular JDKs without any changes to the JDK or special privileges. So I'm still looking for ideas on how to do this reliably with reflection without requiring bootclasspath access.
I believe that supporting method handles as an alternate constructor specification form for CtorAndArgs could provide an acceptable solution, but haven't coded that yet, so haven't found the problems with it yet either. The main drawback of doing that is that sacrificing Java SE 6 as a supported platform, which I would like to avoid. But between requiring bootclasspath and requiring Java SE 7 or later, I'd probably choose Java 7 right now.
simonis commentedon Apr 13, 2015
Remi Forax has just posted his varhandle2 implementation on GitHub where he is using MethodHandles to check access rights to fields. I think that's a way how we could do the required accessibility checks as well, although Remi is apparently using MethodHandles.reflectAs() which was only introduced in Java 8 :(