[
https://issues.apache.org/struts/browse/TILES-286?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44470#action_44470
]
Dmitry commented on TILES-286:
------------------------------
Unfortunately I'm not able to upgrade Jetty on that particular server for which
I'm developing an application. It's already running a number of critical
applications and upgrading Jetty there means testing them all over again. My
current task is to put a new application there so that it would work. Not using
Tiles is probably the simplest way in my case.
However when I found the bug I thought that an old Jetty might not be the only
web server in which Tiles do not work. In any web server that implements
ServletContext in the way Jetty 5 does (not public inner class) this bug will
appear. The bug is connected to quite low-level things: java language access
control and reflection.
I wonder why reflection is used in TilesAccess? Isn't it enough to cast the
context variable to javax.servlet.ServletContext? I see the only reason to use
reflection there: to implement "duck typing", i.e., accept contexts other than
subclasses of javax.servlet.ServletContext. This is (probably) good but it
doesn't work in all cases. The current implementation can be improved to
support those weird cases as well.
> TilesAccess won't set context attributes in Jetty 5.1.10
> --------------------------------------------------------
>
> Key: TILES-286
> URL: https://issues.apache.org/struts/browse/TILES-286
> Project: Tiles
> Issue Type: Bug
> Components: tiles-api
> Affects Versions: 2.0.6
> Environment: Java(TM) 2 Runtime Environment, Standard Edition (build
> 1.5.0_12-b04), Jetty 5.1.11, SUSE Linux Enterprise 10, 64 bit
> Reporter: Dmitry
>
> The code for setting a context attribute in the TilesAccess class is as
> follows:
> private static void setAttribute(Object context, String name, Object
> value)
> throws TilesException {
> try {
> Class<?> contextClass = context.getClass();
> Method attrMethod = contextClass.getMethod("setAttribute",
> String.class, Object.class);
> attrMethod.invoke(context, name, value);
> } catch (Exception e) {
> throw new TilesException("Unable to set attribute for specified
> context: '" + context + "'");
> }
> }
> The line
> attrMethod.invoke(context, name, value);
> throws an IllegalAccessException if Tiles are used inside a Jetty 5.1.11.
> This happens because Jetty's implementation of the
> javax.servlet.ServletContext interface is an inner class without the public
> modifier.
> I.e., Jetty's org.mortbay.jetty.servlet.ServletHandler$Context is not public
> although it's setAttribute() is.
> The same applies to getAttribute() and removeAttribute() methods.
> One of the possible solutions is to reflect the method not only from the
> class itself, but from all its superclasses and interfaces as well.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.