My approach was that from the perspective of a dynamic language, the
array type is accessible even if the element type is not exposed. That
is, FreeMarker can get its elements, and length. If then later it
tries to access members of an element, that's a separate matter, and
it might succeed, because even though the declared class is not
exposed, some types it implements or extends might be.

(It's true that the comment should mention primitives though.)

On Thu, Mar 28, 2024 at 3:29 AM Simon Hartley
<scrhart...@yahoo.co.uk.invalid> wrote:
>
> Hey Daniel.
>
> The fix you've done doesn't seem to take into account that some arrays should 
> be inaccessible.
> I assume that's the case and that the following test should be added:
>
> assertFalse(_JavaVersions.JAVA_9.isAccessibleAccordingToModuleExports(getSomeInternalClass().arrayType()));
>
>
> Here's one idea for a fix:
>
> Package accessedPackage = accessedClass.getPackage(); // null for arrays and 
> primitives!
> if (accessedPackage == null) {
>         Class<?> componentClass = accessedClass.getComponentType(); // null 
> for non-arrays!
>         if (componentClass != null) {
>                 accessedPackage = componentClass.getPackage();
>         }
> }
> if (accessedPackage == null) {
>         return true;
> }
>
>
> P.S.
> That Class.arrayType() method was added in Java12, but if that's a problem 
> then it's implementation is a one liner anyway:
>
> public Class<?> arrayType() {
>     return Array.newInstance(this, 0).getClass();
> }
>
> P.P.S
> Class has a componentType() method that was added in 12,
> but there already existed getComponentType() which is identical.
>
>
> Cheers,
> Simon
>
>
>
>
>
> On Thursday, 28 March 2024 at 00:40:46 GMT, Daniel Dekany 
> <daniel.dek...@gmail.com> wrote:
>
>
> Yes, thanks for running into that! That was a bug with new code that
> checks if we have access to a class according to Java 9+ modules. It
> was because I didn't realize that for the class of an array,
> Class.getPackage() returns null. The fixed version was pushed to the
> Maven snapshot repo already.



-- 
Best regards,
Daniel Dekany

Reply via email to