struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jasper Rosenberg (JIRA)" <>
Subject [jira] [Created] (WW-4485) New cacheKey is too expensive to create
Date Mon, 06 Apr 2015 21:34:12 GMT
Jasper Rosenberg created WW-4485:

             Summary: New cacheKey is too expensive to create
                 Key: WW-4485
             Project: Struts 2
          Issue Type: Bug
          Components: Core Actions, Expression Language
    Affects Versions: 2.5
            Reporter: Jasper Rosenberg
            Priority: Blocker

So we pushed ognl 3.0.10 to production this afternoon, and promptly had to rollback because
load on the servers went through the roof.  Looking at the stack traces, the issue was tons
of threads doing this:

      at java.lang.Class.getEnclosingMethod0(Native Method)
      at java.lang.Class.getEnclosingMethodInfo(
      at java.lang.Class.isLocalOrAnonymousClass(
      at java.lang.Class.getCanonicalName(
      at ognl.OgnlRuntime.buildCacheKey(
      at ognl.OgnlRuntime.getGetMethod(
      at ognl.OgnlRuntime.hasGetMethod(
      at ognl.OgnlRuntime.hasGetProperty(
      at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.getProperty(

The problem is that the change to buildCacheKey() for
is way to expensive considering how often it is called.

I'd like to suggest replacing the current buildCacheKey() implementation with this:

    private static Object buildCacheKey(Class targetClass, String propertyName) {
        return new CacheKey(targetClass, propertyName);
    private static final class CacheKey {
        private final Class clazz;
        private final String propertyName;

        public CacheKey(Class clazz, String propertyName) {
            this.clazz = clazz;
            this.propertyName = propertyName;
        public boolean equals(Object obj) {
            CacheKey cacheKey = (CacheKey) obj;
            return clazz.equals(cacheKey.clazz)
                && propertyName.equals(cacheKey.propertyName);
        public int hashCode() {
            return clazz.hashCode() * 31 + propertyName.hashCode();

This message was sent by Atlassian JIRA

View raw message