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/06/13 14:21:00 UTC
[jira] [Comment Edited] (FREEMARKER-145) Can't access nio
Path.getParent() in templates
[ https://issues.apache.org/jira/browse/FREEMARKER-145?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17134814#comment-17134814 ]
Dániel Dékány edited comment on FREEMARKER-145 at 6/13/20, 2:20 PM:
--------------------------------------------------------------------
OK, I see what they did. {{java.bean.Introspector}} was always kind of broken, as in a situation like this, prior to Java 9 (so probably for 20+ years), it gave back both variation of the property read method (of {{getParent()}} here). That was, I believe, just a Java bug, because actually you can't directly call the overloaded method from a non-public class (causes {{java.lang.IllegalAccessException}}). Hence the accessible method filtering you see in FreeMarker; it filters out the method variation that you can't call, replacing it with the one that you can. Now, with Java 9 they managed to make {{java.bean.Inrospector}} even more broken, because now it only gives back a single method out of the two... But not the right one, but the one that you can't call. So, yeah, has to code in even more {{java.bean.Inrospector}} bug workarounds.
was (Author: ddekany):
OK, I see what they did. {{java.bean.Introspector}} was always kind of broken, as in a situation like this, prior to Java 9 (so probably for 20+ years), it gave back both variation of the property read method (of {{getPath()}} here). That was, I believe, just a Java bug, because actually you can't directly call the overloaded method from a non-public class (causes {{java.lang.IllegalAccessException}}). Hence the accessible method filtering you see in FreeMarker; it filters out the method variation that you can't call, replacing it with the one that you can. Now, with Java 9 they managed to make {{java.bean.Inrospector}} even more broken, because now it only gives back a single method out of the two... But not the right one, but the one that you can't call. So, yeah, has to code in even more {{java.bean.Inrospector}} bug workarounds.
> Can't access nio Path.getParent() in templates
> ----------------------------------------------
>
> Key: FREEMARKER-145
> URL: https://issues.apache.org/jira/browse/FREEMARKER-145
> Project: Apache Freemarker
> Issue Type: Bug
> Components: engine
> Affects Versions: 2.3.30
> Reporter: Alfio Gloria
> Priority: Major
> Attachments: freemarkertest.zip
>
>
> When using something like ${data.path.parent} freemarker throws an exception "The following has evaluated to null or missing" (obviously on a path that has non null parent).
> After some investigation i figured out that freemarker does not recognize getParent() as a valid bean method.
> This seems due to a condition in ClassIntrospector, line 827:
> if (am.getReturnType() == m.getReturnType())
> where
> am.getReturnType() -> java.nio.file.Path
> m.getReturnType() -> sun.nio.fs.UnixPath
> I don't know the rationale of the aforementioned condition but it seems weird to me that I can reference a Path object with ${data.path} but not with ${data.path.parent} since they are both sun.nio.fs.UnixPath objects
--
This message was sent by Atlassian Jira
(v8.3.4#803005)