Author: markt
Date: Thu Jan 22 13:56:05 2015
New Revision: 1653858
URL: http://svn.apache.org/r1653858
Log:
Fix error when defining functions using lambda expressions in JSPs.
Added:
tomcat/tc8.0.x/trunk/test/webapp/bug5nnnn/bug57441.jsp
- copied unchanged from r1653857,
tomcat/trunk/test/webapp/bug5nnnn/bug57441.jsp
Modified:
tomcat/tc8.0.x/trunk/ (props changed)
tomcat/tc8.0.x/trunk/java/org/apache/jasper/compiler/ELFunctionMapper.java
tomcat/tc8.0.x/trunk/java/org/apache/jasper/compiler/Validator.java
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings_es.properties
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings_ja.properties
tomcat/tc8.0.x/trunk/java/org/apache/jasper/runtime/ProtectedFunctionMapper.java
tomcat/tc8.0.x/trunk/test/org/apache/el/TestELInJsp.java
tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc8.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 22 13:56:05 2015
@@ -1 +1 @@
-/tomcat/trunk:1636524,1637156,1637176,1637188,1637331,1637684,1637695,1638720-1638725,1639653,1640010,1640083-1640084,1640088,1640275,1640322,1640347,1640361,1640365,1640403,1640410,1640652,1640655-1640658,1640688,1640700-1640883,1640903,1640976,1640978,1641000,1641026,1641038-1641039,1641051-1641052,1641058,1641064,1641300,1641369,1641374,1641380,1641486,1641634,1641656-1641692,1641704,1641707-1641718,1641720-1641722,1641735,1641981,1642233,1642280,1642554,1642564,1642595,1642606,1642668,1642679,1642697,1642699,1642766,1643002,1643045,1643054-1643055,1643066,1643121,1643128,1643206,1643209-1643210,1643216,1643249,1643270,1643283,1643309-1643310,1643323,1643365-1643366,1643370-1643371,1643465,1643474,1643536,1643570,1643634,1643649,1643651,1643654,1643675,1643731,1643733-1643734,1643761,1643766,1643814,1643937,1643963,1644017,1644169,1644201-1644203,1644321,1644323,1644516,1644523,1644529,1644535,1644730,1644768,1644784-1644785,1644790,1644793,1644815,1644884,1644886,1644890,1644892
,1644910,1644924,1644929-1644930,1644935,1644989,1645011,1645247,1645355,1645357-1645358,1645455,1645465,1645469,1645471,1645473,1645475,1645486-1645488,1645626,1645641,1645685,1645743,1645763,1645951-1645953,1645955,1645993,1646098-1646106,1646178,1646220,1646302,1646304,1646420,1646470-1646471,1646476,1646559,1646717-1646723,1646773,1647026,1647042,1647530,1647655,1648304,1648815,1648907,1650081,1650365,1651116,1651120,1651280,1651470,1652938,1652970,1653041,1653471,1653550,1653574,1653797,1653815-1653816,1653819,1653840
+/tomcat/trunk:1636524,1637156,1637176,1637188,1637331,1637684,1637695,1638720-1638725,1639653,1640010,1640083-1640084,1640088,1640275,1640322,1640347,1640361,1640365,1640403,1640410,1640652,1640655-1640658,1640688,1640700-1640883,1640903,1640976,1640978,1641000,1641026,1641038-1641039,1641051-1641052,1641058,1641064,1641300,1641369,1641374,1641380,1641486,1641634,1641656-1641692,1641704,1641707-1641718,1641720-1641722,1641735,1641981,1642233,1642280,1642554,1642564,1642595,1642606,1642668,1642679,1642697,1642699,1642766,1643002,1643045,1643054-1643055,1643066,1643121,1643128,1643206,1643209-1643210,1643216,1643249,1643270,1643283,1643309-1643310,1643323,1643365-1643366,1643370-1643371,1643465,1643474,1643536,1643570,1643634,1643649,1643651,1643654,1643675,1643731,1643733-1643734,1643761,1643766,1643814,1643937,1643963,1644017,1644169,1644201-1644203,1644321,1644323,1644516,1644523,1644529,1644535,1644730,1644768,1644784-1644785,1644790,1644793,1644815,1644884,1644886,1644890,1644892
,1644910,1644924,1644929-1644930,1644935,1644989,1645011,1645247,1645355,1645357-1645358,1645455,1645465,1645469,1645471,1645473,1645475,1645486-1645488,1645626,1645641,1645685,1645743,1645763,1645951-1645953,1645955,1645993,1646098-1646106,1646178,1646220,1646302,1646304,1646420,1646470-1646471,1646476,1646559,1646717-1646723,1646773,1647026,1647042,1647530,1647655,1648304,1648815,1648907,1650081,1650365,1651116,1651120,1651280,1651470,1652938,1652970,1653041,1653471,1653550,1653574,1653797,1653815-1653816,1653819,1653840,1653857
Modified:
tomcat/tc8.0.x/trunk/java/org/apache/jasper/compiler/ELFunctionMapper.java
URL:
http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/jasper/compiler/ELFunctionMapper.java?rev=1653858&r1=1653857&r2=1653858&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/jasper/compiler/ELFunctionMapper.java
(original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/jasper/compiler/ELFunctionMapper.java
Thu Jan 22 13:56:05 2015
@@ -220,40 +220,46 @@ public class ELFunctionMapper {
ELNode.Function f = functions.get(i);
FunctionInfo funcInfo = f.getFunctionInfo();
String key = f.getPrefix()+ ":" + f.getName();
- ds.append(funcMethod + "(\"" + key + "\", " +
- getCanonicalName(funcInfo.getFunctionClass()) +
- ".class, " + '\"' + f.getMethodName() + "\", " +
- "new Class[] {");
- String params[] = f.getParameters();
- for (int k = 0; k < params.length; k++) {
- if (k != 0) {
- ds.append(", ");
- }
- int iArray = params[k].indexOf('[');
- if (iArray < 0) {
- ds.append(params[k] + ".class");
- }
- else {
- String baseType = params[k].substring(0, iArray);
- ds.append("java.lang.reflect.Array.newInstance(");
- ds.append(baseType);
- ds.append(".class,");
+ if (funcInfo == null) {
+ // Added via Lambda or ImportHandler. EL will expect a
+ // function mapper even if one isn't used so just pass null
+ ds.append(funcMethod + "(null, null, null, null);\n");
+ } else {
+ ds.append(funcMethod + "(\"" + key + "\", " +
+ getCanonicalName(funcInfo.getFunctionClass()) +
+ ".class, " + '\"' + f.getMethodName() + "\", " +
+ "new Class[] {");
+ String params[] = f.getParameters();
+ for (int k = 0; k < params.length; k++) {
+ if (k != 0) {
+ ds.append(", ");
+ }
+ int iArray = params[k].indexOf('[');
+ if (iArray < 0) {
+ ds.append(params[k] + ".class");
+ }
+ else {
+ String baseType = params[k].substring(0, iArray);
+ ds.append("java.lang.reflect.Array.newInstance(");
+ ds.append(baseType);
+ ds.append(".class,");
- // Count the number of array dimension
- int aCount = 0;
- for (int jj = iArray; jj < params[k].length(); jj++ ) {
- if (params[k].charAt(jj) == '[') {
- aCount++;
+ // Count the number of array dimension
+ int aCount = 0;
+ for (int jj = iArray; jj < params[k].length();
jj++ ) {
+ if (params[k].charAt(jj) == '[') {
+ aCount++;
+ }
+ }
+ if (aCount == 1) {
+ ds.append("0).getClass()");
+ } else {
+ ds.append("new int[" + aCount +
"]).getClass()");
}
- }
- if (aCount == 1) {
- ds.append("0).getClass()");
- } else {
- ds.append("new int[" + aCount + "]).getClass()");
}
}
+ ds.append("});\n");
}
- ds.append("});\n");
// Put the current name in the global function map
gMap.put(f.getPrefix() + ':' + f.getName() + ':' + f.getUri(),
decName);
Modified: tomcat/tc8.0.x/trunk/java/org/apache/jasper/compiler/Validator.java
URL:
http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/jasper/compiler/Validator.java?rev=1653858&r1=1653857&r2=1653858&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/jasper/compiler/Validator.java
(original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/jasper/compiler/Validator.java Thu Jan
22 13:56:05 2015
@@ -1582,8 +1582,10 @@ class Validator {
if (uri == null) {
if (prefix == null) {
- err.jspError(n, "jsp.error.noFunctionPrefix",
- function);
+ // This can occur when lambda expressions define
+ // functions and when functions are imported. No
+ // longer able to be sure this is an error.
+ return;
} else {
err.jspError(n,
"jsp.error.attribute.invalidPrefix",
prefix);
@@ -1716,6 +1718,11 @@ class Validator {
@Override
public void visit(ELNode.Function n) throws JasperException {
+ // Lambda / ImportHandler defined fucntion
+ if (n.getFunctionInfo() == null) {
+ return;
+ }
+
Class<?> c = null;
Method method = null;
try {
Modified:
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties?rev=1653858&r1=1653857&r2=1653858&view=diff
==============================================================================
---
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties
(original)
+++
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties
Thu Jan 22 13:56:05 2015
@@ -338,7 +338,6 @@ jsp.error.variable.alias=Both or none of
jsp.error.attribute.null_name=Null attribute name
jsp.error.jsptext.badcontent=\'<\', when appears in the body of
<jsp:text>, must be encapsulated within a CDATA
jsp.error.jsproot.version.invalid=Invalid version number: \"{0}\", must be
\"1.2\", \"2.0\", \"2.1\", \"2.2\" or \"2.3\"
-jsp.error.noFunctionPrefix=The function {0} must be used with a prefix when a
default namespace is not specified
jsp.error.noFunction=The function {0} cannot be located with the specified
prefix
jsp.error.noFunctionMethod=Method \"{0}\" for function \"{1}\" not found in
class \"{2}\"
jsp.error.function.classnotfound=The class {0} specified in TLD for the
function {1} cannot be found: {2}
Modified:
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings_es.properties
URL:
http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings_es.properties?rev=1653858&r1=1653857&r2=1653858&view=diff
==============================================================================
---
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings_es.properties
(original)
+++
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings_es.properties
Thu Jan 22 13:56:05 2015
@@ -332,7 +332,6 @@ jsp.error.variable.alias = Ambos atribut
jsp.error.attribute.null_name = Nombre de atributo nulo
jsp.error.jsptext.badcontent = '<', cuando aparece en el cuerpo de
<jsp\:text>, debe de estar encapsulado dentro de un CDATA
jsp.error.jsproot.version.invalid = N\u00FAmero incorrecto de versi\u00F3n\:
"{0}", debe de ser "1.2" o "2.0" o "2.1" o "2.2" o "2.3"
-jsp.error.noFunctionPrefix = La funci\u00F3n {0} debe de usarse con un prefijo
cuando no se especifica un espacio de nombres por defecto
jsp.error.noFunction = La funci\u00F3n {0} no puede ser localizada mediante el
prefijo especificado
jsp.error.noFunctionMethod = El m\u00E9todo "{0}" para la funci\u00F3n "{1}"
no se pudo hallar en la clase "{2}"
jsp.error.function.classnotfound = La clase {0} especificada en el TLD para la
funci\u00F3n {1} no se puede hallar\: {2}
Modified:
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings_ja.properties
URL:
http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings_ja.properties?rev=1653858&r1=1653857&r2=1653858&view=diff
==============================================================================
---
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings_ja.properties
(original)
+++
tomcat/tc8.0.x/trunk/java/org/apache/jasper/resources/LocalStrings_ja.properties
Thu Jan 22 13:56:05 2015
@@ -297,7 +297,6 @@ jsp.error.variable.alias=name-from-attri
jsp.error.attribute.null_name=\u7a7a\u306e\u5c5e\u6027\u540d\u3067\u3059
jsp.error.jsptext.badcontent=\'<\'\u304c<jsp:text>\u306e\u30dc\u30c7\u30a3\u306e\u4e2d\u306b\u73fe\u308c\u308b\u6642\u306f\u3001CDATA\u306e\u4e2d\u306b\u96a0\u853d\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093
jsp.error.jsproot.version.invalid=\u7121\u52b9\u306a\u30d0\u30fc\u30b8\u30e7\u30f3\u756a\u53f7\u3067\u3059:
\"{0}\"\u3001\"1.2\"\u3000\"2.0\"\u3000\"2.1\"\u3000\"2.2\" \u53c8\u306f
\"2.3\"\u3000\u3067\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093
-jsp.error.noFunctionPrefix=\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u540d\u524d\u7a7a\u9593\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u6642\u306b\u306f\u3001\u95a2\u6570
{0}
\u306f\u30d7\u30ea\u30d5\u30a3\u30af\u30b9\u4ed8\u304d\u3067\u4f7f\u7528\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093
jsp.error.noFunction=\u95a2\u6570 {0}
\u3092\u6307\u5b9a\u3055\u308c\u305f\u30d7\u30ea\u30d5\u30a3\u30af\u30b9\u3067\u914d\u7f6e\u3067\u304d\u307e\u305b\u3093
jsp.error.noFunctionMethod=\u95a2\u6570 \"{1}\" \u306e\u30e1\u30bd\u30c3\u30c9
\"{0}\" \u304c \"{2}\" \u4e2d\u3067\u898b\u3064\u304b\u308a\u307e\u305b\u3093
jsp.error.function.classnotfound=TLD\u306e\u4e2d\u3067\u95a2\u6570 {1}
\u306b\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b\u30af\u30e9\u30b9 {0}
\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093: {2}
Modified:
tomcat/tc8.0.x/trunk/java/org/apache/jasper/runtime/ProtectedFunctionMapper.java
URL:
http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/jasper/runtime/ProtectedFunctionMapper.java?rev=1653858&r1=1653857&r2=1653858&view=diff
==============================================================================
---
tomcat/tc8.0.x/trunk/java/org/apache/jasper/runtime/ProtectedFunctionMapper.java
(original)
+++
tomcat/tc8.0.x/trunk/java/org/apache/jasper/runtime/ProtectedFunctionMapper.java
Thu Jan 22 13:56:05 2015
@@ -97,6 +97,12 @@ public final class ProtectedFunctionMapp
*/
public void mapFunction(String fnQName, final Class<?> c,
final String methodName, final Class<?>[] args) {
+ // Skip if null values were passed in. They indicate a function
+ // added via a lambda or ImportHandler; nether of which need to be
+ // placed in the Map.
+ if (fnQName == null) {
+ return;
+ }
java.lang.reflect.Method method;
if (SecurityUtil.isPackageProtectionEnabled()) {
try {
@@ -143,7 +149,7 @@ public final class ProtectedFunctionMapp
*/
public static ProtectedFunctionMapper getMapForFunction(String fnQName,
final Class<?> c, final String methodName, final Class<?>[] args) {
- java.lang.reflect.Method method;
+ java.lang.reflect.Method method = null;
ProtectedFunctionMapper funcMapper;
if (SecurityUtil.isPackageProtectionEnabled()) {
funcMapper = AccessController.doPrivileged(
@@ -153,28 +159,37 @@ public final class ProtectedFunctionMapp
return new ProtectedFunctionMapper();
}
});
-
- try {
- method = AccessController.doPrivileged(
- new PrivilegedExceptionAction<Method>() {
- @Override
- public Method run() throws Exception {
- return c.getDeclaredMethod(methodName, args);
- }
- });
- } catch (PrivilegedActionException ex) {
- throw new RuntimeException(
- "Invalid function mapping - no such method: "
- + ex.getException().getMessage());
+ // Skip if null values were passed in. They indicate a function
+ // added via a lambda or ImportHandler; nether of which need to be
+ // placed in the Map.
+ if (fnQName != null) {
+ try {
+ method = AccessController.doPrivileged(
+ new PrivilegedExceptionAction<Method>() {
+ @Override
+ public Method run() throws Exception {
+ return c.getDeclaredMethod(methodName,
args);
+ }
+ });
+ } catch (PrivilegedActionException ex) {
+ throw new RuntimeException(
+ "Invalid function mapping - no such method: "
+ + ex.getException().getMessage());
+ }
}
} else {
funcMapper = new ProtectedFunctionMapper();
- try {
- method = c.getDeclaredMethod(methodName, args);
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(
- "Invalid function mapping - no such method: "
- + e.getMessage());
+ // Skip if null values were passed in. They indicate a function
+ // added via a lambda or ImportHandler; nether of which need to be
+ // placed in the Map.
+ if (fnQName != null) {
+ try {
+ method = c.getDeclaredMethod(methodName, args);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(
+ "Invalid function mapping - no such method: "
+ + e.getMessage());
+ }
}
}
funcMapper.theMethod = method;
Modified: tomcat/tc8.0.x/trunk/test/org/apache/el/TestELInJsp.java
URL:
http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/test/org/apache/el/TestELInJsp.java?rev=1653858&r1=1653857&r2=1653858&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/test/org/apache/el/TestELInJsp.java (original)
+++ tomcat/tc8.0.x/trunk/test/org/apache/el/TestELInJsp.java Thu Jan 22
13:56:05 2015
@@ -430,6 +430,22 @@ public class TestELInJsp extends TomcatB
}
+ /*
+ * BZ https://issues.apache.org/bugzilla/show_bug.cgi?id=57441
+ * Can't validate function names defined in lambdas (or via imports)
+ */
+ @Test
+ public void testBug57441() throws Exception {
+ getTomcatInstanceTestWebapp(false, true);
+
+ ByteChunk res = getUrl("http://localhost:" + getPort() +
+ "/test/bug5nnnn/bug57441.jsp");
+
+ String result = res.toString();
+ assertEcho(result, "00-11");
+ }
+
+
// Assertion for text contained with <p></p>, e.g. printed by tags:echo
private static void assertEcho(String result, String expected) {
Assert.assertTrue(result, result.indexOf("<p>" + expected + "</p>") >
0);
Modified: tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml?rev=1653858&r1=1653857&r2=1653858&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml Thu Jan 22 13:56:05 2015
@@ -98,6 +98,11 @@
to the EL environment via the ImportHandler. Issue is reported by
Coverity Scan. (violetagg)
</fix>
+ <fix>
+ <bug>57441</bug>: Do not trigger an error when using functions defined
+ by lambdas or imported via an ImportHandler in an EL expression in a
+ JSP. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Cluster">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]