1
1
/*
2
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates and others.
2
+ * Copyright (c) 2012, 2025 Oracle and/or its affiliates and others.
3
3
* All rights reserved.
4
4
*
5
5
* This program and the accompanying materials are made available under the
14
14
*
15
15
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
16
*/
17
-
18
17
package jakarta .el ;
19
18
20
19
import static java .lang .reflect .Modifier .isAbstract ;
@@ -47,7 +46,7 @@ public class ImportHandler {
47
46
/**
48
47
* Import a static field or method.
49
48
*
50
- * @param name The static member name, including the full class name, to be imported
49
+ * @param name The static member name, including the full class name (in canonical form) , to be imported
51
50
* @throws ELException if the name does not include a ".".
52
51
*/
53
52
public void importStatic (String name ) throws ELException {
@@ -65,7 +64,7 @@ public void importStatic(String name) throws ELException {
65
64
/**
66
65
* Import a class.
67
66
*
68
- * @param name The full class name of the class to be imported
67
+ * @param name The full class name (in canonical form) of the class to be imported
69
68
* @throws ELException if the name does not include a ".".
70
69
*/
71
70
public void importClass (String name ) throws ELException {
@@ -144,6 +143,25 @@ private Class<?> resolveClassFor(String className) {
144
143
if (c != null ) {
145
144
checkModifiers (c .getModifiers ());
146
145
classMap .put (className , c );
146
+ return c ;
147
+ }
148
+
149
+ // Might be an inner class
150
+ StringBuilder sb = new StringBuilder (className );
151
+ int replacementPosition = sb .lastIndexOf ("." );
152
+ while (replacementPosition > -1 ) {
153
+ sb .setCharAt (replacementPosition , '$' );
154
+ c = getClassFor (sb .toString ());
155
+ if (c != null ) {
156
+ checkModifiers (c .getModifiers ());
157
+ classMap .put (sb .toString (), c );
158
+ break ;
159
+ }
160
+ replacementPosition = sb .lastIndexOf ("." , replacementPosition );
161
+ }
162
+
163
+ if (c == null ) {
164
+ notAClass .add (className );
147
165
}
148
166
149
167
return c ;
@@ -155,11 +173,11 @@ private Class<?> getClassFor(String className) {
155
173
return Class .forName (className , false , Thread .currentThread ().getContextClassLoader ());
156
174
// Some operating systems have case-insensitive path names. An example is Windows if className is
157
175
// attempting to be resolved from a wildcard import a java.lang.NoClassDefFoundError may be thrown as
158
- // the expected case for the type likely doesn't match. See
159
- // https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8024775 and
176
+ // the expected case for the type likely doesn't match. See
177
+ // https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8024775 and
160
178
// https://bugs.openjdk.java.net/browse/JDK-8133522.
161
179
} catch (ClassNotFoundException | NoClassDefFoundError ex ) {
162
- notAClass . add ( className );
180
+ // Ignore
163
181
}
164
182
}
165
183
0 commit comments