-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarification required for declaration of scripting variables for actions #42
Comments
@glassfishrobot Commented |
@glassfishrobot Commented |
|
I have been spending some time looking at this issue. The existing specification and Javadoc appear, to me at least, to make conflicting statements relating to exactly where scripting variables defined by tags should be declared. JSP.9.4.4 defines transformations that include when scripting variables should be declared but JSP.9.1.3 states that the transformations do not have to be performed literally. An additional factor is that previous attempts to make changes in this area has triggered regressions and I'd like to avoid that when resolving this issue, particularly since there is relatively little time available between now and the planned completion date for JSP 3.1 for implementations to make changes, test and provide feedback. My own testing suggests that moving scripting variable definition to the declarations section will address this issue in most cases but that there are scenarios where such a change will break an existing page. Given:
rather than introduce a change, or even a configuration option, my current intention is to:
Unless there are objections, I hope to have a PR along the above lines ready for review towards the end of this week. |
There are some grey areas in the JSP specification regarding when and how scripting variables associated with actions are declared that need to be clarified.
Consider the following from JSP.9.4.4
Equivalent Text:
If <x:tag> declares an AT_BEGIN scripting variable myVar of type String then the equivalent text becomes (ignoring the required variable synchronization to make the example clearer)
If our original code is extended to:
then the equivalent text becomes
Clearly this is problematic since it is illegal to declare the same variable multiple times in the same scope.
There are a couple of ways to handle this. The first is to insert an outer code block around the code for each tag. However, that makes little sense since it makes the declaration of AT_END variables pointless as the following example shows. There is no point declaring the AT_END variables in this case since they instantly go out of scope.
Another alternative is to pre-process the tags and to ensure that duplicate scripting variables are not defined. The equivalent text for multiple tag instances then becomes:
The pre-processing approach works in most cases but it can break if scriptlets are present. Consider the following original text:
With pre-processing this becomes:
which will break if the transformation of foo refers to myVar (which it almost certainly will) because myVar is now out of scope for the second instance of the tag.
I do not believe it is reasonable or practical for JSP containers to parse scriplets surrounding actions to determine the scope of any declared scripting variables and then adjust the declaration of those scripting variables accordingly.
One potential solution is to move the declaration of all scripting variables for actions (AT_BEGIN, NESTED and AT_END) to immediately after the declaration of the implicit scripting variables so the scripting variables for actions are always declared once only and are always in scope during the execution of the page.
It is necessary for the JSP specification to clarify how scripting variables declared by actions should be handled. It should be noted that there are variations on this problem such as when tags are nested.
For background on the Tomcat bug report that prompted this issue see:
https://issues.apache.org/bugzilla/show_bug.cgi?id=56516
Also see:
https://issues.apache.org/bugzilla/show_bug.cgi?id=42390
https://issues.apache.org/bugzilla/show_bug.cgi?id=48616
The text was updated successfully, but these errors were encountered: