Skip to content
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

jakarta.el.ELException: The class [...] must be public, in an exported package, non-abstract and not an interface #25135

Closed
volosied opened this issue Apr 27, 2023 · 2 comments · Fixed by #27073
Labels
in:Web Components release bug This bug is present in a released version of Open Liberty release:24001 team:Sirius

Comments

@volosied
Copy link
Member

volosied commented Apr 27, 2023

Describe the bug
An ELException occurs when a JSP imports static field from an interface.


jakarta.el.ELException: The class [io.openliberty.pages31.fat.misc.other.SomeInterface] must be public, in an exported package, non-abstract and not an interface
at jakarta.el.ImportHandler.findClass(ImportHandler.java:463)
at jakarta.el.ImportHandler.importStatic(ImportHandler.java:297)
at org.apache.jasper.runtime.PageContextImpl.addImportsToELContext(PageContextImpl.java:856)
at [internal classes]
at com.ibm._jsp._staticImportInterface._jspService(_staticImportInterface.java:125)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:102)
at [internal classes]`

Steps to Reproduce
A JSP using the pages 3.1 feature imports a static field via an interface.
For example:
<%@ page import = "static io.openliberty.pages31.fat.misc.other.SomeInterface.DEFAULT" %>

Expected behavior
No errors should occur.

Diagnostic information:

  • OpenLiberty Version: Since 23.0.0.3
  • Affected feature(s) pages-3.1
  • Java Version: N/A
  • server.xml configuration - N/A

Additional context
Also reported in Tomcat: https://bz.apache.org/bugzilla/show_bug.cgi?id=66582

@volosied volosied added the release bug This bug is present in a released version of Open Liberty label Apr 27, 2023
@pnicolucci pnicolucci added this to General Issues in Web Tier Team via automation Apr 27, 2023
@pnicolucci pnicolucci moved this from General Issues to Current Priority in Web Tier Team Apr 27, 2023
@volosied
Copy link
Member Author

volosied commented Sep 26, 2023

I'm not too sure about this one and the the specification could be more explicit about interfaces ( mostly because docs just says "static field". The closest text I found is the restrictions section: a class has to be explicitly imported before its static fields or methods can be referenced..

Looking over https://jakarta.ee/specifications/platform/10/apidocs/jakarta/el/package-summary (specifically the ImportHandler - Handles imports of class names and package names.)

importStatic​:

Import a static field or method.

Parameters:
    name - The static member name, including the full class name, to be imported

https://jakarta.ee/specifications/expression-language/5.0/jakarta-expression-language-spec-5.0#imports-of-packages-classes-and-static-fields

Package description mentions concrete classes specially:
Importing a package imports all the public, concrete classes in the package.

Access restrictions:



For security, the following restrictions are enforced.

    Only the public static fields and methods can be referenced.

    Static fields cannot be modified.

    Except for classes with java.lang.* package names, a class has to be explicitly imported before its static fields or methods can be referenced.

There's also the StaticFieldELResolver, but I think the class has to be imported first to be found.

I don't think the EL is meant to handle this situation where a static field from an interface is imported. This also applies to abstract classes (as the error indicates) I think this also explains why the en masse import also fails: #24182

It seems like it could handle this situation though, but it would need to be fixed via the API. It is possible to the field: for example:

                          public interface Test {
	                          public static String DOG = "bark";
                          }

			ClassLoader cl = Thread.currentThread().getContextClassLoader();

			System.out.println(cl.loadClass("Test").getField("DOG").get(null));		

However, I don't see much use for this scenario. If no one has asked for this then it's probably not worth pursuing.

@volosied
Copy link
Member Author

volosied commented Nov 15, 2023

Assigning to @chungngoops

Edit: Name doesn't show up here?

chungngoops added a commit to chungngoops/open-liberty that referenced this issue Nov 29, 2023
chungngoops added a commit to chungngoops/open-liberty that referenced this issue Nov 30, 2023
chungngoops added a commit to chungngoops/open-liberty that referenced this issue Nov 30, 2023
Web Tier Team automation moved this from Current Priority to Completed Tasks Dec 1, 2023
volosied added a commit that referenced this issue Dec 1, 2023
…d-test

#25135 fix static imports from interfaces in JSPs via EL
mrsaldana pushed a commit to mrsaldana/open-liberty that referenced this issue Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:Web Components release bug This bug is present in a released version of Open Liberty release:24001 team:Sirius
Projects
Archived in project
Web Tier Team
  
Completed Tasks
3 participants