You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Lauri Keel (Jira)" <ji...@apache.org> on 2020/02/22 15:51:00 UTC

[jira] [Comment Edited] (FREEMARKER-133) BeansWrapper IllegalAccessException when class defining accessed method is package-private, but subclass is public

    [ https://issues.apache.org/jira/browse/FREEMARKER-133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17042611#comment-17042611 ] 

Lauri Keel edited comment on FREEMARKER-133 at 2/22/20 3:50 PM:
----------------------------------------------------------------

The accessible methods list contains two get methods:
 # public java.util.List com.google.common.collect.ArrayListMultimap.get(java.lang.Object)
 # public java.util.Collection com.google.common.collect.AbstractListMultimap.get(java.lang.Object)

Strange that AbstractListMultimap.get returns a Collection – it has returned a List since the very beginning.

Introspector.getBeanInfo() seems to be returning methods for interfaces (where possible?) – in one case it selects Multimap.get (returns Collection) and in another one ListMultimap.get (returns List).

Locally my beanInfo.methods contains {{java.beans.MethodDescriptor[name=get; method=public abstract java.util.Collection com.google.common.collect.Multimap.get(java.lang.Object)]}}

Then getMatchingAccessibleMethod selects a suitable method according to the return type:
 # for Multimap.get it will be AbstractListMultimap.get (returns Collection)
 # for ListMultimap.get it will be ArrayListMultimap.get (returns List)

Even if the accessible methods list didn't contain the package-private class method it still wouldn't work, because the return types won't match.


was (Author: siilike9):
The accessible methods list contains two get methods:
 # public java.util.List com.google.common.collect.ArrayListMultimap.get(java.lang.Object)
 # public java.util.Collection com.google.common.collect.AbstractListMultimap.get(java.lang.Object)

Strange that AbstractListMultimap.get returns a Collection – it has returned a List since the very beginning.

Introspector.getBeanInfo() seems to be returning methods for interfaces (where possible?) – in one case it selects Multimap.get (returns Collection) and in another one ListMultimap.get (returns List).

Locally my beanInfo.methods contains {{java.beans.MethodDescriptor[name=get; method=public abstract java.util.Collection com.google.common.collect.Multimap.get(java.lang.Object)]}}

Then getMatchingAccessibleMethod selects a suitable method according to the return type:
 # for Multimap.get it will be AbstractListMultimap.get (returns Collection)
 # for ListMultimap.get it will be ArrayListMultimap.get (returns List)

Even if the accessible methods list didn't contain the package-private method it still wouldn't work, because the return types won't match.

> BeansWrapper IllegalAccessException when class defining accessed method is package-private, but subclass is public
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: FREEMARKER-133
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-133
>             Project: Apache Freemarker
>          Issue Type: Bug
>            Reporter: Lauri Keel
>            Priority: Major
>
> Consider the following code:
> {code:java}
> <#list orders.get(type) as order></#list>{code}
> where orders is com.google.common.collect.ArrayListMultimap. An IllegalAccessException is thrown, because com.google.common.collect.AbstractListMultimap where the get method is defined is package-private.
> {code:java}
> ----
> FTL stack trace ("~" means nesting-related):
>         - Failed at: #list orders.get(type) as order  [in template "admin-orders.ftl" at line 4, column 9]
> ----
>         at freemarker.ext.beans._MethodUtil.newInvocationTemplateModelException(_MethodUtil.java:289)
>         at freemarker.ext.beans._MethodUtil.newInvocationTemplateModelException(_MethodUtil.java:252)
>         at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:77)
>         at freemarker.core.MethodCall._eval(MethodCall.java:65)
>         at freemarker.core.Expression.eval(Expression.java:83)
>         at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:98)
>         at freemarker.core.IteratorBlock.accept(IteratorBlock.java:93)
>         at freemarker.core.Environment.visit(Environment.java:366)
>         at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:291)
>         at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271)
>         at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:242)
>         at freemarker.core.Environment.visitIteratorBlock(Environment.java:642)
>         at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:107)
>         at freemarker.core.IteratorBlock.accept(IteratorBlock.java:93)
>         at freemarker.core.Environment.visit(Environment.java:330)
>         at freemarker.core.Environment.visit(Environment.java:336)
>         at freemarker.core.Environment.process(Environment.java:309)
>         at freemarker.template.Template.process(Template.java:384)
>         at puu.page.PageHandler.getRendered(PageHandler.java:550)
>         ... 36 common frames omitted
> Caused by: java.lang.IllegalAccessException: class freemarker.ext.beans.BeansWrapper cannot access a member of class com.google.common.collect.AbstractListMultimap with modifiers "public volatile"
>         at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
>         at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
>         at java.base/java.lang.reflect.Method.invoke(Method.java:558)
>         at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1505)
>         at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:72)
>         ... 52 common frames omitted
> {code}
> Tested in 2.3.29, 2.3.28, 2.3.23. Strangely it occasionally randomly does work.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)