Is it possible to disable static field and method reference support for JSP 2.3 in Tomcat 8

Is it possible to disable support for references to static fields and methods in Tomcat 8, which was added as part of Unified Expression Language 3.0.

We have ~ 4K JSP in our application with many expressions ${undefined}(without scope), switching to Tomcat 8 leads to a significant decrease in performance, since evaluating these expressions is the legal value of "null". We no longer use JSP technology for new pages, but outdated ones will not disappear soon.

The problematic code is in the javax.servlet.el.ScopedAttributeELResolver class , which is trying to resolve the expression from ImportHandler, which makes a lot of Class.forName lookup requests, which is largely due to a ClassNotFoundException.

@Override
public Object getValue(ELContext context, Object base, Object property) {
    if (context == null) {
        throw new NullPointerException();
    }

    Object result = null;

    if (base == null) {
        context.setPropertyResolved(base, property);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            result = page.findAttribute(key);

            if (result == null) {
                // This might be the name of an imported class
                ImportHandler importHandler = context.getImportHandler();
                if (importHandler != null) {
                    Class<?> clazz = importHandler.resolveClass(key);
                    if (clazz != null) {
                        result = new ELClass(clazz);
                    }
                    if (result == null) {
                        // This might be the name of an imported static field
                        clazz = importHandler.resolveStatic(key);
                        if (clazz != null) {
                            try {
                                result = clazz.getField(key).get(null);
                            } catch (IllegalArgumentException | IllegalAccessException |
                                    NoSuchFieldException | SecurityException e) {
                                // Most (all?) of these should have been
                                // prevented by the checks when the import
                                // was defined.
                            }
                        }
                    }
                }
            }
        }
    }

    return result;
}

Update

For problems with Tomcat 8 - errors were detected when using unlimited optional attributes , which is closed since it will not be fixed. I thought they could add some property to disable code that requires high performance, but so far they won't be, due to:

  • This will be specific to Tomcat.
  • This must be a system property, as it is a specification class.
  • It cannot be applied for each application - this will affect all applications running in this instance.

Advise thanks

+4
3

Tomcat. , Tomcat, -. , , common.loader $CATALINA_BASE/conf/catalina.properties. , :

  • $CATALINA_BASE/lib
  • JAR $CATALINA_BASE/lib
  • $CATALINA_HOME/lib
  • JAR $CATALINA_HOME/lib

: javax.servlet.jsp.el.ScopedAttributeELResolver, ( jsp-api.jar), getValue, ( tomcat Apache 2, ). $CATALINA_BASE/lib.

:

    @Override
    public Object getValue(ELContext context, Object base, Object property) {
        if (context == null) {
            throw new NullPointerException();
        }

        Object result = null;

        if (base == null) {
            context.setPropertyResolved(base, property);
            if (property != null) {
                String key = property.toString();
                PageContext page = (PageContext) context
                        .getContext(JspContext.class);
                result = page.findAttribute(key);

//                if (result == null) {
//                    // This might be the name of an imported class
//                    ImportHandler importHandler = context.getImportHandler();
//                    if (importHandler != null) {
//                        Class<?> clazz = importHandler.resolveClass(key);
//                        if (clazz != null) {
//                            result = new ELClass(clazz);
//                        }
//                        if (result == null) {
//                            // This might be the name of an imported static field
//                            clazz = importHandler.resolveStatic(key);
//                            if (clazz != null) {
//                                try {
//                                    result = clazz.getField(key).get(null);
//                                } catch (IllegalArgumentException | IllegalAccessException |
//                                        NoSuchFieldException | SecurityException e) {
//                                    // Most (all?) of these should have been
//                                    // prevented by the checks when the import
//                                    // was defined.
//                                }
//                            }
//                        }
//                    }
//                }
            }
        }

        return result;
    }

.

:

:

  • Tomcat.
+4

, - , Tomcat 8.5, , (fooobar.com/questions/1629324/...), , , ( ) .

, , , , Tomcat...

0

Source: https://habr.com/ru/post/1629324/


All Articles