commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1187867 - in /commons/proper/ognl/trunk/src: changes/ main/java/org/apache/commons/ognl/ main/java/org/apache/commons/ognl/enhance/ test/java/org/apache/commons/ognl/ test/java/org/apache/commons/ognl/test/ test/java/org/apache/commons/ogn...
Date Sun, 23 Oct 2011 11:35:11 GMT
Author: simonetripodi
Date: Sun Oct 23 11:35:10 2011
New Revision: 1187867

URL: http://svn.apache.org/viewvc?rev=1187867&view=rev
Log:
[OGNL-23] Class.forName() usage is malicious inside OSGi (contributed by Adrian Cumiskey)

Modified:
    commons/proper/ognl/trunk/src/changes/changes.xml
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTAnd.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTAssign.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTChain.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTList.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMap.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMethod.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTOr.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTProperty.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTStaticMethod.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTTest.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTVarRef.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ClassResolver.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/DefaultClassResolver.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ObjectPropertyAccessor.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlRuntime.java
    commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java
    commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/TestOgnlRuntime.java
    commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ASTMethodTest.java
    commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/test/objects/BeanProviderAccessor.java

Modified: commons/proper/ognl/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/changes/changes.xml?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/changes/changes.xml (original)
+++ commons/proper/ognl/trunk/src/changes/changes.xml Sun Oct 23 11:35:10 2011
@@ -26,6 +26,7 @@
       <action issue="OGNL-28" type="update" dev="mcucchiara">Visitor pattern needs
way to propagate exceptions (contributed by Daniel Pitts).</action>
       <action issue="OGNL-27" type="update" dev="simonetripodi">Move "toString" implementations
into visitor pattern (contributed by Daniel Pitts).</action>
       <action issue="OGNL-26" type="update" dev="grobmeier">JUnit Tests produce confusing
output.</action>
+      <action issue="OGNL-23" type="fix" dev="simonetripodi">Class.forName() usage
is malicious inside OSGi (contributed by Adrian Cumiskey)</action>
       <action issue="OGNL-21" type="update" dev="grobmeier">Remove dead and broken
code from OgnlRuntime/SimpleNode (with contributions by Daniel Pitts)</action>
       <action issue="OGNL-24" type="update" dev="grobmeier">Support visitor pattern
on AST (contributed by Daniel Pitts)</action>
       <action issue="OGNL-15" type="update" dev="simonetripodi">OGNL needs a new Logo</action>

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTAnd.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTAnd.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTAnd.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTAnd.java Sun Oct 23
11:35:10 2011
@@ -143,13 +143,13 @@ public class ASTAnd
 
             if ( !OgnlRuntime.isBoolean( first ) && !context.getCurrentType().isPrimitive()
) 
             {
-                first = OgnlRuntime.getCompiler().createLocalReference( context, first, context.getCurrentType()
);
+                first = OgnlRuntime.getCompiler( context ).createLocalReference( context,
first, context.getCurrentType() );
             }
             
             String second = OgnlRuntime.getChildSource( context, target, _children[1] );
             if ( !OgnlRuntime.isBoolean( second ) && !context.getCurrentType().isPrimitive()
) 
             {
-                second = OgnlRuntime.getCompiler().createLocalReference( context, second,
context.getCurrentType() );
+                second = OgnlRuntime.getCompiler( context ).createLocalReference( context,
second, context.getCurrentType() );
             }
             
             result += "(org.apache.commons.ognl.OgnlOps.booleanValue(" + first + ")";

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTAssign.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTAssign.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTAssign.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTAssign.java Sun Oct
23 11:35:10 2011
@@ -57,7 +57,7 @@ class ASTAssign
 
         if ( ASTProperty.class.isInstance( _children[1] ) )
         {
-            second += "((" + OgnlRuntime.getCompiler().getClassName( target.getClass() )
+ ")$2).";
+            second += "((" + OgnlRuntime.getCompiler( context ).getClassName( target.getClass()
) + ")$2).";
         }
 
         second += _children[1].toGetSourceString( context, target );
@@ -75,7 +75,7 @@ class ASTAssign
             }
             
             second =
-                OgnlRuntime.getCompiler().createLocalReference( context,
+                OgnlRuntime.getCompiler( context ).createLocalReference( context,
                                                                 "org.apache.commons.ognl.OgnlOps.returnValue(($w)"
                                                                     + core + ", ($w) " +
seq.getLastExpression() + ")",
                                                                 Object.class );
@@ -99,7 +99,7 @@ class ASTAssign
 
             result =
                 OgnlRuntime
-                    .getCompiler()
+                    .getCompiler( context )
                     .createLocalReference( context,
                                            "org.apache.commons.ognl.OgnlOps.returnValue(($w)"
+ result + ", ($w)"
                                                + ( (OrderedReturn) _children[0] ).getLastExpression()
+ ")",
@@ -117,7 +117,7 @@ class ASTAssign
 
         if ( ASTProperty.class.isInstance( _children[1] ) )
         {
-            result += "((" + OgnlRuntime.getCompiler().getClassName( target.getClass() )
+ ")$2).";
+            result += "((" + OgnlRuntime.getCompiler( context ).getClassName( target.getClass()
) + ")$2).";
         }
 
         String value = _children[1].toSetSourceString( context, target );

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTChain.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTChain.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTChain.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTChain.java Sun Oct
23 11:35:10 2011
@@ -326,7 +326,7 @@ public class ASTChain
                         && ( (OrderedReturn) _children[i] ).getLastExpression() !=
null )
                         && ( _parent == null || !ASTSequence.class.isInstance( _parent
) ) )
                     {
-                        value = OgnlRuntime.getCompiler().castExpression( context, _children[i],
value );
+                        value = OgnlRuntime.getCompiler( context ).castExpression( context,
_children[i], value );
                     }
 
                     /*
@@ -454,7 +454,7 @@ public class ASTChain
                         && ( (OrderedReturn) _children[i] ).getLastExpression() !=
null )
                         && ( _parent == null || !ASTSequence.class.isInstance( _parent
) ) )
                     {
-                        value = OgnlRuntime.getCompiler().castExpression( context, _children[i],
value );
+                        value = OgnlRuntime.getCompiler( context ).castExpression( context,
_children[i], value );
                     }
 
                     // System.out.println("astchain setter after cast value is: " + value);

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java Sun Oct 23
11:35:10 2011
@@ -320,7 +320,7 @@ public class ASTCtor
                             {
 
                                 value =
-                                    "(" + OgnlRuntime.getCompiler().getInterfaceClass( values[i].getClass()
).getName()
+                                    "(" + OgnlRuntime.getCompiler( context ).getInterfaceClass(
values[i].getClass() ).getName()
                                         + ")" + value;
                             }
                             else if ( !ASTConst.class.isInstance( _children[i] )

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTList.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTList.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTList.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTList.java Sun Oct 23
11:35:10 2011
@@ -143,7 +143,7 @@ public class ASTList
 
                         value =
                             OgnlRuntime
-                                .getCompiler()
+                                .getCompiler( context )
                                 .createLocalReference( context, "(" + ExpressionCompiler.getCastString(
ctorClass )
                                     + ")org.apache.commons.ognl.OgnlOps.toArray(" + value
+ ", "
                                     + ctorClass.getComponentType().getName() + ".class, true)",
ctorClass );
@@ -156,7 +156,7 @@ public class ASTList
 
                         value =
                             OgnlRuntime
-                                .getCompiler()
+                                .getCompiler( context )
                                 .createLocalReference( context, "((" + wrapClass.getName()
                                     + ")org.apache.commons.ognl.OgnlOps.convertValue(" +
value + ","
                                     + wrapClass.getName() + ".class, true))." + OgnlRuntime.getNumericValueGetter(
@@ -167,7 +167,7 @@ public class ASTList
 
                         value =
                             OgnlRuntime
-                                .getCompiler()
+                                .getCompiler( context )
                                 .createLocalReference( context, "(" + ctorClass.getName()
                                     + ")org.apache.commons.ognl.OgnlOps.convertValue(" +
value + ","
                                     + ctorClass.getName() + ".class)", ctorClass );

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMap.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMap.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMap.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMap.java Sun Oct 23
11:35:10 2011
@@ -32,23 +32,9 @@ import java.util.Map;
 class ASTMap
     extends SimpleNode
 {
-
-    private static Class defaultMapClass;
-
     private String className;
 
-    static
-    {
-        /* Try to get LinkedHashMap; if older JDK than 1.4 use HashMap */
-        try
-        {
-            defaultMapClass = Class.forName( "java.util.LinkedHashMap" );
-        }
-        catch ( ClassNotFoundException ex )
-        {
-            defaultMapClass = HashMap.class;
-        }
-    }
+    private Map<OgnlContext, Class> defaultMapClassMap = new HashMap<OgnlContext,
Class>();
 
     public ASTMap( int id )
     {
@@ -83,6 +69,7 @@ class ASTMap
 
         if ( className == null )
         {
+            Class defaultMapClass = getDefaultMapClass( context );
             try
             {
                 answer = (Map) defaultMapClass.newInstance();
@@ -132,4 +119,23 @@ class ASTMap
     {
         return visitor.visit( this, data );
     }
+
+    private Class getDefaultMapClass( OgnlContext context ) {
+        Class defaultMapClass = defaultMapClassMap.get( context );
+        if (defaultMapClass != null) {
+            return defaultMapClass;
+        }
+
+        /* Try to get LinkedHashMap; if older JDK than 1.4 use HashMap */
+        try
+        {
+            defaultMapClass = OgnlRuntime.classForName( context, "java.util.LinkedHashMap"
);
+        }
+        catch ( ClassNotFoundException ex )
+        {
+            defaultMapClass = HashMap.class;
+        }
+        defaultMapClassMap.put( context, defaultMapClass );
+        return defaultMapClass;
+    }
 }

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMethod.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMethod.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMethod.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMethod.java Sun Oct
23 11:35:10 2011
@@ -191,7 +191,7 @@ public class ASTMethod
 
                     context.setCurrentType( m.getReturnType() );
                     context.setCurrentAccessor( 
-                                OgnlRuntime.getCompiler().getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
+                                OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass(
m, m.getDeclaringClass() ) );
 
                     coreExpression = toSetSourceString( context, target );
                     if ( coreExpression == null || coreExpression.length() < 1 )
@@ -293,7 +293,7 @@ public class ASTMethod
 
                             parmString =
                                 OgnlRuntime
-                                    .getCompiler()
+                                    .getCompiler( context )
                                     .createLocalReference( context, "(" + ExpressionCompiler.getCastString(
parms[i] )
                                         + ")org.apache.commons.ognl.OgnlOps#toArray(" + parmString
+ ", "
                                         + parms[i].getComponentType().getName() + ".class,
true)", parms[i] );
@@ -306,7 +306,7 @@ public class ASTMethod
 
                             parmString =
                                 OgnlRuntime
-                                    .getCompiler()
+                                    .getCompiler( context )
                                     .createLocalReference( context, "((" + wrapClass.getName()
                                         + ")org.apache.commons.ognl.OgnlOps#convertValue("
+ parmString + ","
                                         + wrapClass.getName() + ".class, true))." + OgnlRuntime.getNumericValueGetter(
@@ -317,7 +317,7 @@ public class ASTMethod
                         {
                             parmString =
                                 OgnlRuntime
-                                    .getCompiler()
+                                    .getCompiler( context )
                                     .createLocalReference( context, "(" + parms[i].getName()
                                         + ")org.apache.commons.ognl.OgnlOps#convertValue("
+ parmString + ","
                                         + parms[i].getName() + ".class)", parms[i] );
@@ -369,7 +369,7 @@ public class ASTMethod
         }
 
         context.setCurrentType( m.getReturnType() );
-        context.setCurrentAccessor( OgnlRuntime.getCompiler().getSuperOrInterfaceClass( m,
m.getDeclaringClass() ) );
+        context.setCurrentAccessor( OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass(
m, m.getDeclaringClass() ) );
 
         return result;
     }
@@ -489,7 +489,7 @@ public class ASTMethod
                         {
                             parmString =
                                 OgnlRuntime
-                                    .getCompiler()
+                                    .getCompiler( context )
                                     .createLocalReference( context, "(" + ExpressionCompiler.getCastString(
parms[i] )
                                         + ")org.apache.commons.ognl.OgnlOps#toArray(" + parmString
+ ", "
                                         + parms[i].getComponentType().getName() + ".class)",
parms[i] );
@@ -501,7 +501,7 @@ public class ASTMethod
 
                             parmString =
                                 OgnlRuntime
-                                    .getCompiler()
+                                    .getCompiler( context )
                                     .createLocalReference( context, "((" + wrapClass.getName()
                                         + ")org.apache.commons.ognl.OgnlOps#convertValue("
+ parmString + ","
                                         + wrapClass.getName() + ".class, true))." + OgnlRuntime.getNumericValueGetter(
@@ -512,7 +512,7 @@ public class ASTMethod
                         {
                             parmString =
                                 OgnlRuntime
-                                    .getCompiler()
+                                    .getCompiler( context )
                                     .createLocalReference( context, "(" + parms[i].getName()
                                         + ")org.apache.commons.ognl.OgnlOps#convertValue("
+ parmString + ","
                                         + parms[i].getName() + ".class)", parms[i] );
@@ -557,7 +557,7 @@ public class ASTMethod
         }
 
         context.setCurrentType( m.getReturnType() );
-        context.setCurrentAccessor( OgnlRuntime.getCompiler().getSuperOrInterfaceClass( m,
m.getDeclaringClass() ) );
+        context.setCurrentAccessor( OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass(
m, m.getDeclaringClass() ) );
 
         return result + ")" + post;
     }

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTOr.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTOr.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTOr.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTOr.java Sun Oct 23
11:35:10 2011
@@ -101,7 +101,7 @@ public class ASTOr
             String first = OgnlRuntime.getChildSource( context, target, _children[0] );
             if ( !OgnlRuntime.isBoolean( first ) )
             {
-                first = OgnlRuntime.getCompiler().createLocalReference( context, first, context.getCurrentType()
);
+                first = OgnlRuntime.getCompiler( context ).createLocalReference( context,
first, context.getCurrentType() );
             }
             
             Class firstType = context.getCurrentType();
@@ -109,7 +109,7 @@ public class ASTOr
             String second = OgnlRuntime.getChildSource( context, target, _children[1] );
             if ( !OgnlRuntime.isBoolean( second ) )
             {
-                second = OgnlRuntime.getCompiler().createLocalReference( context, second,
context.getCurrentType() );
+                second = OgnlRuntime.getCompiler( context ).createLocalReference( context,
second, context.getCurrentType() );
             }
             
             Class secondType = context.getCurrentType();
@@ -167,7 +167,7 @@ public class ASTOr
                     + _children[0].toGetSourceString( context, target );
             if ( !OgnlRuntime.isBoolean( first ) )
             {
-                first = OgnlRuntime.getCompiler().createLocalReference( context, first, Object.class
);
+                first = OgnlRuntime.getCompiler( context ).createLocalReference( context,
first, Object.class );
             }
             _children[1].getValue( context, target );
 
@@ -176,7 +176,7 @@ public class ASTOr
                     + _children[1].toSetSourceString( context, target );
             if ( !OgnlRuntime.isBoolean( second ) )
             {
-                second = OgnlRuntime.getCompiler().createLocalReference( context, second,
context.getCurrentType() );
+                second = OgnlRuntime.getCompiler( context ).createLocalReference( context,
second, context.getCurrentType() );
             }
             result += "org.apache.commons.ognl.OgnlOps.booleanValue(" + first + ")";
 

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTProperty.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTProperty.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTProperty.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTProperty.java Sun Oct
23 11:35:10 2011
@@ -85,7 +85,7 @@ public class ASTProperty
                 {
                     return OgnlRuntime.getIndexedPropertyType( 
                           context,
-                          ( source == null ) ? null : OgnlRuntime.getCompiler().getInterfaceClass(
source.getClass() ),
+                          ( source == null ) ? null : OgnlRuntime.getCompiler( context ).getInterfaceClass(
source.getClass() ),
                           (String) property );
                 }
             }
@@ -206,7 +206,7 @@ public class ASTProperty
                     context.setCurrentType( getterClass );
                     context.setCurrentObject( indexedValue );
                     context.setCurrentAccessor( 
-                        OgnlRuntime.getCompiler().getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
+                        OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
 
                     return "." + m.getName() + "(" + srcString + ")";
                 }
@@ -403,7 +403,7 @@ public class ASTProperty
 
             context.setCurrentType( m.getReturnType() );
             context.setCurrentAccessor( 
-                OgnlRuntime.getCompiler().getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
+                OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
         }
 
         context.setCurrentObject( target );
@@ -501,7 +501,7 @@ public class ASTProperty
                     }
                     context.setCurrentType( setterClass );
                     context.setCurrentAccessor( 
-                        OgnlRuntime.getCompiler().getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
+                        OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
 
                     if ( !lastChild )
                     {
@@ -598,7 +598,7 @@ public class ASTProperty
 
             PropertyDescriptor pd =
                 OgnlRuntime.getPropertyDescriptor( 
-                    OgnlRuntime.getCompiler().getInterfaceClass( 
+                    OgnlRuntime.getCompiler( context ).getInterfaceClass(
                         context.getCurrentObject().getClass() ), name );
 
             if ( pd != null )
@@ -723,7 +723,7 @@ public class ASTProperty
         {
             context.setCurrentType( m.getReturnType() );
             context.setCurrentAccessor( 
-                OgnlRuntime.getCompiler().getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
+                OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
         }
 
         return result;

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTStaticMethod.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTStaticMethod.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTStaticMethod.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTStaticMethod.java Sun
Oct 23 11:35:10 2011
@@ -167,7 +167,7 @@ public class ASTStaticMethod
                         if ( parms[i].isArray() )
                         {
                             parmString =
-                                OgnlRuntime.getCompiler().createLocalReference( context,
+                                OgnlRuntime.getCompiler( context ).createLocalReference(
context,
                                                                 "("
                                                                     + ExpressionCompiler.getCastString(
parms[i] )
                                                                     + ")org.apache.commons.ognl.OgnlOps.toArray("
@@ -182,7 +182,7 @@ public class ASTStaticMethod
                             Class wrapClass = OgnlRuntime.getPrimitiveWrapperClass( parms[i]
);
 
                             parmString =
-                                OgnlRuntime.getCompiler().createLocalReference( context,
+                                OgnlRuntime.getCompiler( context ).createLocalReference(
context,
                                                             "(("
                                                                 + wrapClass.getName()
                                                                 + ")org.apache.commons.ognl.OgnlOps.convertValue("
@@ -197,7 +197,7 @@ public class ASTStaticMethod
                         else if ( parms[i] != Object.class )
                         {
                             parmString =
-                                OgnlRuntime.getCompiler().createLocalReference( context,
+                                OgnlRuntime.getCompiler( context ).createLocalReference(
context,
                                                             "("
                                                                 + parms[i].getName()
                                                                 + ")org.apache.commons.ognl.OgnlOps.convertValue("
@@ -240,7 +240,7 @@ public class ASTStaticMethod
 
                 context.setCurrentType( m.getReturnType() );
                 context.setCurrentAccessor( 
-                    OgnlRuntime.getCompiler().getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
+                    OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass( m, m.getDeclaringClass()
) );
             }
 
         }

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTTest.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTTest.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTTest.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTTest.java Sun Oct 23
11:35:10 2011
@@ -81,7 +81,7 @@ class ASTTest
             String first = OgnlRuntime.getChildSource( context, target, _children[0] );
             if ( !OgnlRuntime.isBoolean( first ) && !context.getCurrentType().isPrimitive()
)
             {
-                first = OgnlRuntime.getCompiler().createLocalReference( context, first, context.getCurrentType()
);
+                first = OgnlRuntime.getCompiler( context ).createLocalReference( context,
first, context.getCurrentType() );
             }
             
             if ( ExpressionNode.class.isInstance( _children[0] ) )
@@ -94,7 +94,7 @@ class ASTTest
 
             if ( !OgnlRuntime.isBoolean( second ) && !context.getCurrentType().isPrimitive()
)
             {
-                second = OgnlRuntime.getCompiler().createLocalReference( context, second,
context.getCurrentType() );
+                second = OgnlRuntime.getCompiler( context ).createLocalReference( context,
second, context.getCurrentType() );
             }
             
             if ( ExpressionNode.class.isInstance( _children[1] ) )
@@ -107,7 +107,7 @@ class ASTTest
 
             if ( !OgnlRuntime.isBoolean( third ) && !context.getCurrentType().isPrimitive()
)
             {
-                third = OgnlRuntime.getCompiler().createLocalReference( context, third, context.getCurrentType()
);
+                third = OgnlRuntime.getCompiler( context ).createLocalReference( context,
third, context.getCurrentType() );
             
             }
             

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTVarRef.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTVarRef.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTVarRef.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTVarRef.java Sun Oct
23 11:35:10 2011
@@ -122,7 +122,7 @@ public class ASTVarRef
         String post = "";
         if ( context.getCurrentType() != null )
         {
-            pre = "((" + OgnlRuntime.getCompiler().getInterfaceClass( context.getCurrentType()
).getName() + ")";
+            pre = "((" + OgnlRuntime.getCompiler( context ).getInterfaceClass( context.getCurrentType()
).getName() + ")";
             post = ")";
         }
 

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ClassResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ClassResolver.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ClassResolver.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ClassResolver.java Sun
Oct 23 11:35:10 2011
@@ -22,7 +22,7 @@ package org.apache.commons.ognl;
 import java.util.Map;
 
 /**
- * This interface defines an object that will resolve a class from a string and a ognl context
table.
+ * This interface defines an object that will resolve a class from a string and an ognl context
table.
  * 
  * @author Luke Blanshard (blanshlu@netscape.net)
  * @author Drew Davidson (drew@ognl.org)

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/DefaultClassResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/DefaultClassResolver.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/DefaultClassResolver.java
(original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/DefaultClassResolver.java
Sun Oct 23 11:35:10 2011
@@ -23,7 +23,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 /**
- * Default class resolution. Uses Class.forName() to look up classes by name. It also looks
in the "java.lang" package
+ * Default class resolution. Uses ClassLoader.loadClass() to look up classes by name. It
also looks in the "java.lang" package
  * if the class named does not give a package specifier, allowing easier usage of these classes.
  * 
  * @author Luke Blanshard (blanshlu@netscape.net)
@@ -35,24 +35,38 @@ public class DefaultClassResolver
     private final Map<String, Class<?>> classes = new HashMap<String, Class<?>>(
101 );
 
     /**
+     * Resolves a class for a given className
+     *
+     * @param className The name of the Class
+     * @return The resulting Class object
+     * @throws ClassNotFoundException If the class could not be found
+     */
+    public Class<?> classForName( String className )
+        throws ClassNotFoundException
+    {
+        return classForName( className, null );
+    }
+
+    /**
      * {@inheritDoc}
      */
-    public Class<?> classForName( String className, Map<String, Object> context
)
+    public Class<?> classForName( String className, Map<String, Object> unused
)
         throws ClassNotFoundException
     {
         Class<?> result = classes.get( className );
 
         if ( result == null )
         {
+            ClassLoader classLoader = ClassLoader.getSystemClassLoader();
             try
             {
-                result = Class.forName( className );
+                result = classLoader.loadClass(className);
             }
             catch ( ClassNotFoundException ex )
             {
                 if ( className.indexOf( '.' ) == -1 )
                 {
-                    result = Class.forName( "java.lang." + className );
+                    result = classLoader.loadClass( "java.lang." + className );
                     classes.put( "java.lang." + className, result );
                 }
             }

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ObjectPropertyAccessor.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ObjectPropertyAccessor.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ObjectPropertyAccessor.java
(original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ObjectPropertyAccessor.java
Sun Oct 23 11:35:10 2011
@@ -262,7 +262,7 @@ public class ObjectPropertyAccessor
             }
 
             context.setCurrentType( m.getReturnType() );
-            context.setCurrentAccessor( OgnlRuntime.getCompiler().getSuperOrInterfaceClass(
m, m.getDeclaringClass() ) );
+            context.setCurrentAccessor( OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass(
m, m.getDeclaringClass() ) );
 
             return "." + m.getName() + "()";
 
@@ -303,7 +303,7 @@ public class ObjectPropertyAccessor
             {
                 Class<?> wrapClass = OgnlRuntime.getPrimitiveWrapperClass( parm );
                 conversion =
-                    OgnlRuntime.getCompiler().createLocalReference( context,
+                    OgnlRuntime.getCompiler( context ).createLocalReference( context,
                                                                     "(("
                                                                         + wrapClass.getName()
                                                                         + ")org.apache.commons.ognl.OgnlOps#convertValue($3,"
@@ -315,7 +315,7 @@ public class ObjectPropertyAccessor
             else if ( parm.isArray() )
             {
                 conversion =
-                    OgnlRuntime.getCompiler().createLocalReference( context,
+                    OgnlRuntime.getCompiler( context ).createLocalReference( context,
                                                                     "("
                                                                         + ExpressionCompiler.getCastString(
parm )
                                                                         + ")org.apache.commons.ognl.OgnlOps#toArray($3,"
@@ -326,7 +326,7 @@ public class ObjectPropertyAccessor
             else
             {
                 conversion =
-                    OgnlRuntime.getCompiler().createLocalReference( context,
+                    OgnlRuntime.getCompiler( context ).createLocalReference( context,
                                                                     "("
                                                                         + parm.getName()
                                                                         + ")org.apache.commons.ognl.OgnlOps#convertValue($3,"
@@ -334,7 +334,7 @@ public class ObjectPropertyAccessor
             }
 
             context.setCurrentType( m.getReturnType() );
-            context.setCurrentAccessor( OgnlRuntime.getCompiler().getSuperOrInterfaceClass(
m, m.getDeclaringClass() ) );
+            context.setCurrentAccessor( OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass(
m, m.getDeclaringClass() ) );
 
             return "." + m.getName() + "(" + conversion + ")";
 

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlContext.java Sun Oct
23 11:35:10 2011
@@ -65,7 +65,7 @@ public class OgnlContext
 
     private static boolean DEFAULT_KEEP_LAST_EVALUATION = false;
 
-    public static final ClassResolver DEFAULT_CLASS_RESOLVER = new DefaultClassResolver();
+    public static final DefaultClassResolver DEFAULT_CLASS_RESOLVER = new DefaultClassResolver();
 
     public static final TypeConverter DEFAULT_TYPE_CONVERTER = new DefaultTypeConverter();
 

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlRuntime.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlRuntime.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlRuntime.java (original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/OgnlRuntime.java Sun Oct
23 11:35:10 2011
@@ -188,6 +188,9 @@ public class OgnlRuntime
 
     static final IntHashMap<Integer, Boolean> _methodPermCache = new IntHashMap<Integer,
Boolean>();
 
+    static final Map<OgnlContext, OgnlExpressionCompiler> expressionCompilerMap = new
HashMap<OgnlContext, OgnlExpressionCompiler>();
+
+
     static ClassCacheInspector _cacheInspector;
 
     /**
@@ -195,24 +198,6 @@ public class OgnlRuntime
      */
     private static OgnlExpressionCompiler _compiler;
 
-    /**
-     * Lazy loading of Javassist library
-     */
-    static
-    {
-        try
-        {
-            Class.forName( "javassist.ClassPool" );
-            _compiler = new ExpressionCompiler();
-        }
-        catch ( ClassNotFoundException e )
-        {
-            throw new IllegalArgumentException(
-                                                "Javassist library is missing in classpath!
Please add missed dependency!",
-                                                e );
-        }
-    }
-
     private static Map<Class<?>, Class<?>> PRIMITIVE_WRAPPER_CLASSES =
new IdentityHashMap<Class<?>, Class<?>>();
 
     /**
@@ -430,7 +415,7 @@ public class OgnlRuntime
 
         try
         {
-            Class.forName( "java.lang.annotation.Annotation" );
+            OgnlRuntime.classForName( null, "java.lang.annotation.Annotation" );
             _jdk15 = true;
         }
         catch ( Exception e )
@@ -467,15 +452,38 @@ public class OgnlRuntime
         _compiler = compiler;
     }
 
+    /**
+     * @deprecated use getCompiler(OgnlContext) instead
+     */
     public static OgnlExpressionCompiler getCompiler()
     {
-        return _compiler;
+        return _compiler != null ? _compiler : getCompiler( null );
+    }
+
+    public static OgnlExpressionCompiler getCompiler( OgnlContext ognlContext )
+    {
+        OgnlExpressionCompiler ognlExpressionCompiler = expressionCompilerMap.get(ognlContext);
+        if (ognlExpressionCompiler == null) {
+            try
+            {
+                OgnlRuntime.classForName( ognlContext, "javassist.ClassPool" );
+                ognlExpressionCompiler = new ExpressionCompiler();
+                expressionCompilerMap.put(ognlContext, ognlExpressionCompiler);
+            }
+            catch ( ClassNotFoundException e )
+            {
+                throw new IllegalArgumentException(
+                                                    "Javassist library is missing in classpath!
Please add missed dependency!",
+                                                    e );
+            }
+        }
+        return ognlExpressionCompiler;
     }
 
     public static void compileExpression( OgnlContext context, Node expression, Object root
)
         throws Exception
     {
-        _compiler.compileExpression( context, expression, root );
+        getCompiler( context ).compileExpression( context, expression, root );
     }
 
     /**

Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java
(original)
+++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java
Sun Oct 23 11:35:10 2011
@@ -156,7 +156,7 @@ public class ExpressionCompiler
             || ( root != null && ASTRootVarRef.class.isInstance( expression ) ) )
         {
 
-            Class<?> castClass = OgnlRuntime.getCompiler().getRootExpressionClass(
expression, context );
+            Class<?> castClass = OgnlRuntime.getCompiler( context ).getRootExpressionClass(
expression, context );
 
             if ( castClass.isArray() || ASTRootVarRef.class.isInstance( expression )
                 || ASTThisVarRef.class.isInstance( expression ) )

Modified: commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/TestOgnlRuntime.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/TestOgnlRuntime.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/TestOgnlRuntime.java (original)
+++ commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/TestOgnlRuntime.java Sun
Oct 23 11:35:10 2011
@@ -45,7 +45,8 @@ public class TestOgnlRuntime
         Method m = OgnlRuntime.getReadMethod( list.getClass(), "total" );
         assertNotNull( m );
 
-        assertEquals( ListSource.class, OgnlRuntime.getCompiler().getSuperOrInterfaceClass(
m, list.getClass() ) );
+        OgnlContext context = (OgnlContext) Ognl.createDefaultContext( null );
+        assertEquals( ListSource.class, OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass(
m, list.getClass() ) );
     }
 
     @Test
@@ -57,7 +58,8 @@ public class TestOgnlRuntime
         Method m = OgnlRuntime.getReadMethod( list.getClass(), "iterator" );
         assertNotNull( m );
 
-        assertEquals( Iterable.class, OgnlRuntime.getCompiler().getSuperOrInterfaceClass(
m, list.getClass() ) );
+        OgnlContext context = (OgnlContext) Ognl.createDefaultContext( null );
+        assertEquals( Iterable.class, OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass(
m, list.getClass() ) );
     }
 
     @Test
@@ -69,7 +71,8 @@ public class TestOgnlRuntime
         Method m = OgnlRuntime.getWriteMethod( form.getClass(), "clientId" );
         assertNotNull( m );
 
-        assertEquals( IComponent.class, OgnlRuntime.getCompiler().getSuperOrInterfaceClass(
m, form.getClass() ) );
+        OgnlContext context = (OgnlContext) Ognl.createDefaultContext( null );
+        assertEquals( IComponent.class, OgnlRuntime.getCompiler( context ).getSuperOrInterfaceClass(
m, form.getClass() ) );
     }
 
     @Test

Modified: commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ASTMethodTest.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ASTMethodTest.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ASTMethodTest.java
(original)
+++ commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/test/ASTMethodTest.java
Sun Oct 23 11:35:10 2011
@@ -59,7 +59,7 @@ public class ASTMethodTest
         assert Map.class.isAssignableFrom( context.getPreviousType() );
         assert context.getPreviousAccessor() == null;
 
-        assertEquals( OgnlRuntime.getCompiler().castExpression( context, p, ".get(\"value\")"
), ".get(\"value\")" );
+        assertEquals( OgnlRuntime.getCompiler( context ).castExpression( context, p, ".get(\"value\")"
), ".get(\"value\")" );
         assert context.get( ExpressionCompiler.PRE_CAST ) == null;
 
         // now test one context level further to see casting work properly on base object
types
@@ -79,7 +79,7 @@ public class ASTMethodTest
         assertEquals( Object.class, context.getPreviousType() );
         assert Map.class.isAssignableFrom( context.getPreviousAccessor() );
 
-        assertEquals( OgnlRuntime.getCompiler().castExpression( context, prop, ".getBean3()"
), ").getBean3()" );
+        assertEquals( OgnlRuntime.getCompiler( context ).castExpression( context, prop, ".getBean3()"
), ").getBean3()" );
 
     }
 }

Modified: commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/test/objects/BeanProviderAccessor.java
URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/test/objects/BeanProviderAccessor.java?rev=1187867&r1=1187866&r2=1187867&view=diff
==============================================================================
--- commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/test/objects/BeanProviderAccessor.java
(original)
+++ commons/proper/ognl/trunk/src/test/java/org/apache/commons/ognl/test/objects/BeanProviderAccessor.java
Sun Oct 23 11:35:10 2011
@@ -76,7 +76,7 @@ public class BeanProviderAccessor
 
             ExpressionCompiler.addCastString( context,
                                               "(("
-                                                  + OgnlRuntime.getCompiler().getInterfaceClass(
provider.getBean( beanName ).getClass() ).getName()
+                                                  + OgnlRuntime.getCompiler( context ).getInterfaceClass(
provider.getBean( beanName ).getClass() ).getName()
                                                   + ")" );
 
             return ".getBean(\"" + beanName + "\"))";



Mime
View raw message