Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2104

Regression - after upgrade of ECJ version Jastow is unable to compile JSPs with local classes

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Done
    • None
    • Jastow 2.2.2.Final
    • None
    • None

    Description

      After upgrade of ECJ version Jastow is unable to properly compile some JSPs with local classes (i.e. nested classes defined in scriplet) - ECJ now issues additional call 'isPackage' for such classes and existing implementation in JDTCompiler class doesn't work with nested classes.

      Here is an example of simple JSP, which fails compilation:

      <%@ page import="java.util.*"%><%
      class InnerClass {
      }
      List<InnerClass> list = new ArrayList<>();
      for(InnerClass elements : list) {
      }
      %>

      Attempt to compile this JSP causes following error:

      org.apache.jasper.JasperException: org.apache.jasper.JasperException: JBWEB004001: 
      Unable to compile class for JSP
              at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549) [jastow-2.0.10.Final.jar:2.0.10.Final]
              at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:379) [jastow-2.0.10.Final.jar:2.0.10.Final]
              at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403) [jastow-2.0.10.Final.jar:2.0.10.Final]
              at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347) [jastow-2.0.10.Final.jar:2.0.10.Final]
      <...>
      Caused by: org.apache.jasper.JasperException: JBWEB004001: Unable to compile class for JSP
              at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:667) [jastow-2.0.10.Final.jar:2.0.10.Final]
              at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358) [jastow-2.0.10.Final.jar:2.0.10.Final]
              ... 47 more
      Caused by: java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.lookup.PlainPackageBinding cannot be cast to org.eclipse.jdt.internal.compiler.lookup.TypeBinding
              at org.eclipse.jdt.internal.compiler.ClassFile.getTypeBinding(ClassFile.java:6328)
              at org.eclipse.jdt.internal.compiler.ClassFile.traverse(ClassFile.java:7402)
              at org.eclipse.jdt.internal.compiler.ClassFile.generateStackMapTableAttribute(ClassFile.java:5199)
              at org.eclipse.jdt.internal.compiler.ClassFile.completeCodeAttribute(ClassFile.java:1688)
              at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:368)
              at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:291)
              at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:761)
              at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:831)
              at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:412)
              at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:913)
              at org.eclipse.jdt.internal.compiler.Compiler.processCompiledUnits(Compiler.java:575)
              at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:475)
              at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)
              at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:445) [jastow-2.0.10.Final.jar:2.0.10.Final]
              at org.apache.jasper.compiler.Compiler.compile(Compiler.java:359) [jastow-2.0.10.Final.jar:2.0.10.Final]
              at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334) [jastow-2.0.10.Final.jar:2.0.10.Final]
              at org.apache.jasper.compiler.Compiler.compile(Compiler.java:321) [jastow-2.0.10.Final.jar:2.0.10.Final]
              at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:652) [jastow-2.0.10.Final.jar:2.0.10.Final]
              ... 48 more

      This fix seems to be simple – JDTCompiler.isPackage method need to be updated to handle nested classes name, i.e. instead of:

      private boolean isPackage(String result) {
          if (result.equals(targetClassName)) {
              return false;
          }
      ...

      it should be following:

      {code:java}private boolean isPackage(String result) {
          if (result.equals(targetClassName) || result.startsWith(targetClassName + '$')) {
              return false;
          }
      ...

      This issue was already observed in original Jasper project:

      And similar issue was also fixes in OpenLiberty project:

      This issue in Undertow / Jastow code causes regression in WildFly 25+ – the same JSP page was compiling without problem in WF 24, but fails in later version.

      Attachments

        Issue Links

          Activity

            People

              ropalka Richard Opalka
              alexeymakhmutov Alexey Makhmutov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: