Skip to content

Commit

Permalink
Fix #239 - Ensure static imports in JSP are visible to EL on that page
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Feb 1, 2023
1 parent 5bf8b94 commit 65c102f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions api/src/main/java/jakarta/servlet/jsp/el/ImportELResolver.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
* Copyright (c) 2023 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,6 +18,7 @@
import jakarta.el.ELContext;
import jakarta.el.ELClass;
import jakarta.el.ELResolver;
import jakarta.el.ImportHandler;
import jakarta.el.ELException;

/**
Expand Down Expand Up @@ -55,16 +56,31 @@ public Object getValue(ELContext context, Object base, Object property) {
throw new NullPointerException();
}

// check to see if the property is an imported class
if (base == null && property instanceof String && context.getImportHandler() != null) {
ImportHandler importHandler = context.getImportHandler();
if (base == null && property instanceof String && importHandler != null) {
String attribute = (String) property;
Object value = null;
Class<?> c = context.getImportHandler().resolveClass(attribute);
// Check to see if the property is an imported class
Class<?> c = importHandler.resolveClass(attribute);
if (c != null) {
value = new ELClass(c);
// A possible optimization is to set the ELClass
// instance in an attribute map.
}
// Check to see if the property is an imported static field
if (value == null) {
c = importHandler.resolveStatic(attribute);
if (c != null) {
try {
value = c.getField(attribute).get(null);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException |
SecurityException e) {
// Most (all?) of these should have been
// prevented by the checks when the import
// was defined.
}
}
}
if (value != null) {
context.setPropertyResolved(true);
}
Expand Down

0 comments on commit 65c102f

Please sign in to comment.