You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Dániel Dékány (Jira)" <ji...@apache.org> on 2020/02/21 22:41:00 UTC

[jira] [Commented] (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=17042215#comment-17042215 ] 

Dániel Dékány commented on FREEMARKER-133:
------------------------------------------

Strange. The visibility of the concrete classes involved shouldn't mater, because {{get(key)}} was declared in the public {{Multimap}} interface. Also, {{BeansWrapper}} has already decided that it's OK to call that method, as the stack trace shows, and then the reflection API decides that it's not allowed. But the method is shown to be "public". So, I don't get it. Can you navigate into reflection API code visible in the stack trace, on the exact Java version where it fails, to see why it decides as it does?

> 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)