├── docs ├── ognl-logo-avatar.png └── ognl-logo-social.png ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── ognl └── src │ ├── test │ └── java │ │ ├── ClassInDefaultPackage.java │ │ ├── ognl │ │ ├── test │ │ │ ├── objects │ │ │ │ ├── TestClass.java │ │ │ │ ├── IForm.java │ │ │ │ ├── FormImpl.java │ │ │ │ ├── Inherited.java │ │ │ │ ├── Copy.java │ │ │ │ ├── StaticInterface.java │ │ │ │ ├── Model.java │ │ │ │ ├── ListSource.java │ │ │ │ ├── IContentProvider.java │ │ │ │ ├── TestInherited1.java │ │ │ │ ├── TestInherited2.java │ │ │ │ ├── BaseIndexed.java │ │ │ │ ├── GenericObject.java │ │ │ │ ├── FirstBean.java │ │ │ │ ├── SecondBean.java │ │ │ │ ├── GameGeneric.java │ │ │ │ ├── IFormComponent.java │ │ │ │ ├── Cracker.java │ │ │ │ ├── GenericService.java │ │ │ │ ├── IComponent.java │ │ │ │ ├── Two.java │ │ │ │ ├── SubclassSyntheticObject.java │ │ │ │ ├── PersonGenericObject.java │ │ │ │ ├── ITreeContentProvider.java │ │ │ │ ├── SimpleEnum.java │ │ │ │ ├── BaseSyntheticObject.java │ │ │ │ ├── ComponentSubclass.java │ │ │ │ ├── GenericCracker.java │ │ │ │ ├── SearchCriteria.java │ │ │ │ ├── SetterReturns.java │ │ │ │ ├── FormComponentImpl.java │ │ │ │ ├── TestImpl.java │ │ │ │ ├── OtherEnum.java │ │ │ │ ├── IndexedMapObject.java │ │ │ │ ├── SimpleNumeric.java │ │ │ │ ├── GetterMethods.java │ │ │ │ ├── TestModel.java │ │ │ │ ├── GameGenericObject.java │ │ │ │ ├── GenericServiceImpl.java │ │ │ │ ├── ComponentImpl.java │ │ │ │ ├── GenericRoot.java │ │ │ │ ├── TreeContentProvider.java │ │ │ │ ├── ListSourceImpl.java │ │ │ │ ├── BeanProviderImpl.java │ │ │ │ ├── Entry.java │ │ │ │ ├── BaseBean.java │ │ │ │ ├── PropertyHolder.java │ │ │ │ ├── Messages.java │ │ │ │ ├── BaseGeneric.java │ │ │ │ ├── IndexedSetObject.java │ │ │ │ ├── Bean1.java │ │ │ │ ├── OtherObjectIndexed.java │ │ │ │ ├── MenuItem.java │ │ │ │ ├── MyMap.java │ │ │ │ ├── ObjectIndexed.java │ │ │ │ ├── BeanProvider.java │ │ │ │ ├── CorrectedObject.java │ │ │ │ ├── EvenOdd.java │ │ │ │ ├── BaseObjectIndexed.java │ │ │ │ ├── SearchTab.java │ │ │ │ ├── Component.java │ │ │ │ └── Bean2.java │ │ │ ├── race │ │ │ │ ├── Base.java │ │ │ │ ├── Person.java │ │ │ │ └── RaceTest.java │ │ │ ├── IsTruckTest.java │ │ │ ├── InExpressionTest.java │ │ │ ├── util │ │ │ │ ├── EnhancedClassLoader.java │ │ │ │ ├── ContextClassLoader.java │ │ │ │ └── NameFactory.java │ │ │ ├── ASTChainTest.java │ │ │ ├── CorrectedObjectNullHandler.java │ │ │ ├── OgnlExceptionTest.java │ │ │ ├── ASTSequenceTest.java │ │ │ ├── ProtectedInnerClassTest.java │ │ │ ├── GenericsTest.java │ │ │ ├── NullHandlerTest.java │ │ │ ├── QuotingTest.java │ │ │ ├── NestedMethodTest.java │ │ │ ├── accessors │ │ │ │ └── PropertyAccessTest.java │ │ │ ├── NullRootTest.java │ │ │ ├── SimpleNavigationChainTreeTest.java │ │ │ └── InheritedMethodsTest.java │ │ └── ExcludedObjectMemberAccess.java │ │ ├── com │ │ └── sun │ │ │ └── test │ │ │ └── AnotherInternalClass.java │ │ └── sun │ │ └── test │ │ ├── PublicTestInterface.java │ │ └── SimulatedInternalClass.java │ └── main │ └── java │ └── ognl │ ├── internal │ ├── entry │ │ ├── CacheEntry.java │ │ ├── ClassCacheEntryFactory.java │ │ ├── CacheEntryFactory.java │ │ ├── MethodAccessEntryValue.java │ │ ├── DeclaredMethodCacheEntryFactory.java │ │ ├── FieldCacheEntryFactory.java │ │ ├── MethodCacheEntry.java │ │ ├── GenericMethodParameterTypeCacheEntry.java │ │ ├── MethodAccessCacheEntryFactory.java │ │ └── DeclaredMethodCacheEntry.java │ ├── Cache.java │ ├── CacheException.java │ ├── ClassCache.java │ ├── CacheFactory.java │ ├── HashMapCacheFactory.java │ └── HashMapClassCache.java │ ├── ClassResolver.java │ ├── enhance │ ├── EnhancedClassLoader.java │ ├── ContextClassLoader.java │ ├── LocalReference.java │ ├── UnsupportedCompilationException.java │ └── OrderedReturn.java │ ├── ExpressionSyntaxException.java │ ├── MapElementsAccessor.java │ ├── CollectionElementsAccessor.java │ ├── EnumerationElementsAccessor.java │ ├── IteratorElementsAccessor.java │ ├── AbstractMemberAccess.java │ ├── ObjectNullHandler.java │ ├── ClassCacheInspector.java │ ├── InappropriateExpressionException.java │ ├── IteratorEnumeration.java │ ├── MethodFailedException.java │ ├── NodeType.java │ ├── DefaultTypeConverter.java │ ├── EnumerationIterator.java │ ├── ASTDivide.java │ ├── ASTSubtract.java │ ├── AccessibleObjectHandler.java │ ├── ASTRemainder.java │ ├── ASTShiftLeft.java │ ├── ArrayElementsAccessor.java │ ├── ASTShiftRight.java │ ├── OgnlInvokePermission.java │ ├── PrimitiveTypes.java │ ├── NumericCasts.java │ ├── ASTEq.java │ ├── ASTLess.java │ ├── ASTXor.java │ ├── ASTBitOr.java │ ├── ASTNotEq.java │ ├── ASTLessEq.java │ ├── ObjectElementsAccessor.java │ ├── ASTGreater.java │ ├── ASTGreaterEq.java │ ├── ASTMultiply.java │ ├── package.html │ ├── ASTKeyValue.java │ ├── NumberElementsAccessor.java │ ├── NumericDefaults.java │ ├── NumericLiterals.java │ ├── ASTBitNegate.java │ ├── ASTBitAnd.java │ ├── ElementsAccessor.java │ ├── NumericValues.java │ ├── ASTThisVarRef.java │ ├── PrimitiveDefaults.java │ ├── TypeConverter.java │ ├── SetPropertyAccessor.java │ └── ASTNot.java ├── .gitignore ├── renovate.json ├── .claude └── settings.json ├── SECURITY.md └── .github ├── FUNDING.yml └── workflows ├── ognl-3-4-x.yml ├── claude.yml ├── claude-code-review.yml └── performance.yml /docs/ognl-logo-avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orphan-oss/ognl/HEAD/docs/ognl-logo-avatar.png -------------------------------------------------------------------------------- /docs/ognl-logo-social.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orphan-oss/ognl/HEAD/docs/ognl-logo-social.png -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orphan-oss/ognl/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip -------------------------------------------------------------------------------- /ognl/src/test/java/ClassInDefaultPackage.java: -------------------------------------------------------------------------------- 1 | @SuppressWarnings("unused") 2 | class ClassInDefaultPackage { 3 | public static final int CONST = 99; 4 | } 5 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/TestClass.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public abstract class TestClass { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/IForm.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public interface IForm extends IComponent { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/FormImpl.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class FormImpl extends ComponentImpl implements IForm { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/Inherited.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public interface Inherited { 7 | 8 | String getMyString(); 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.ipr 3 | *.iws 4 | target 5 | .idea 6 | build 7 | .java-version 8 | .mvn/wrapper/maven-wrapper.jar 9 | .DS_Store 10 | **/.DS_Store 11 | .claude/settings.local.json 12 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/Copy.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class Copy { 7 | 8 | public int size() { 9 | return 1; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/StaticInterface.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | public interface StaticInterface { 4 | static String staticMethod() { 5 | return "static"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/Model.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class Model { 7 | 8 | public int getOptionCount() { 9 | return 1; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/ListSource.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | public interface ListSource { 4 | 5 | int getTotal(); 6 | 7 | Object addValue(Object value); 8 | 9 | Object getName(); 10 | } 11 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/IContentProvider.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 7 | */ 8 | public interface IContentProvider { 9 | 10 | public List getElements(); 11 | } 12 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/TestInherited1.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class TestInherited1 implements Inherited { 7 | 8 | public String getMyString() { 9 | return "inherited1"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/TestInherited2.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class TestInherited2 implements Inherited { 7 | 8 | public String getMyString() { 9 | return "inherited2"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/BaseIndexed.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * Class used to test inheritance. 5 | */ 6 | public class BaseIndexed { 7 | 8 | public Object getLine(int index) { 9 | return "line:" + index; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/GenericObject.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * Used by {@link BaseGeneric} to reference a class type. 5 | */ 6 | public interface GenericObject { 7 | 8 | int getId(); 9 | 10 | String getDisplayName(); 11 | } 12 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/FirstBean.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package ognl.test.objects; 5 | 6 | 7 | /** 8 | * 9 | */ 10 | public class FirstBean extends BaseBean { 11 | 12 | public String getName() { 13 | return "FirstBean"; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/SecondBean.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package ognl.test.objects; 5 | 6 | 7 | /** 8 | * 9 | */ 10 | public class SecondBean extends BaseBean { 11 | public String getName() { 12 | return "SecondBean"; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/GameGeneric.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class GameGeneric extends BaseGeneric { 7 | 8 | public GameGeneric() { 9 | _value = new GameGenericObject(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/IFormComponent.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public interface IFormComponent extends IComponent { 7 | 8 | String getClientId(); 9 | 10 | IForm getForm(); 11 | 12 | void setForm(IForm form); 13 | } 14 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/Cracker.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Generic test object. 7 | */ 8 | public interface Cracker { 9 | 10 | T getParam(); 11 | 12 | void setParam(T param); 13 | } 14 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/race/Base.java: -------------------------------------------------------------------------------- 1 | package ognl.test.race; 2 | 3 | public class Base { 4 | private Boolean yn = true; 5 | 6 | public Boolean getYn() { 7 | return yn; 8 | } 9 | 10 | public void setYn(Boolean yn) { 11 | this.yn = yn; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/GenericService.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | public interface GenericService { 4 | 5 | String getFullMessageFor(PersonGenericObject person, Object... arguments); 6 | 7 | String getFullMessageFor(GameGenericObject game, Object... arguments); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/IComponent.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public interface IComponent { 7 | 8 | String getClientId(); 9 | 10 | void setClientId(String id); 11 | 12 | int getCount(String index); 13 | 14 | void setCount(String index, int count); 15 | } 16 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/race/Person.java: -------------------------------------------------------------------------------- 1 | package ognl.test.race; 2 | 3 | public class Person extends Base { 4 | private String name = "abc"; 5 | 6 | public String getName() { 7 | return name; 8 | } 9 | 10 | public void setName(String name) { 11 | this.name = name; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/Two.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class Two { 7 | 8 | public String getMessage(String mes) { 9 | return "[" + mes + "]"; 10 | } 11 | 12 | public boolean hasChildren(String name) { 13 | return name.length() > 2; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/SubclassSyntheticObject.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * Simple subclass. 7 | */ 8 | public class SubclassSyntheticObject extends BaseSyntheticObject { 9 | 10 | public ArrayList getList() { 11 | return new ArrayList(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/PersonGenericObject.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class PersonGenericObject implements GenericObject { 7 | 8 | public int getId() { 9 | return 1; 10 | } 11 | 12 | public String getDisplayName() { 13 | return "Henry Collins"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/ITreeContentProvider.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 7 | */ 8 | public interface ITreeContentProvider extends IContentProvider { 9 | 10 | public Collection getChildren(Object parentElement); 11 | 12 | public boolean hasChildren(Object parentElement); 13 | } 14 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/SimpleEnum.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public enum SimpleEnum { 7 | 8 | ONE(1); 9 | 10 | private int _value; 11 | 12 | private SimpleEnum(int value) { 13 | _value = value; 14 | } 15 | 16 | public int getValue() { 17 | return _value; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/BaseSyntheticObject.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Used to test OGNL-136 use of synthetic methods. 8 | */ 9 | public abstract class BaseSyntheticObject { 10 | 11 | protected List getList() { 12 | return new ArrayList(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base" 5 | ], 6 | "baseBranches": ["main", "ognl-3-4-x"], 7 | "packageRules": [ 8 | { 9 | "matchUpdateTypes": ["major","minor", "patch"], 10 | "matchCurrentVersion": "!/^0/", 11 | "automerge": true 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/ComponentSubclass.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class ComponentSubclass extends ComponentImpl { 7 | 8 | int _count = 0; 9 | 10 | public int getCount() { 11 | return _count; 12 | } 13 | 14 | public void setCount(int count) { 15 | _count = count; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/GenericCracker.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class GenericCracker implements Cracker { 7 | 8 | Integer _param; 9 | 10 | public Integer getParam() { 11 | return _param; 12 | } 13 | 14 | public void setParam(Integer param) { 15 | _param = param; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/SearchCriteria.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * Test for OGNL-131. 5 | */ 6 | public class SearchCriteria { 7 | 8 | String _displayName; 9 | 10 | public SearchCriteria(String name) { 11 | _displayName = name; 12 | } 13 | 14 | public String getDisplayName() { 15 | return _displayName; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/SetterReturns.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class SetterReturns { 7 | 8 | private String _value = ""; 9 | 10 | public String getValue() { 11 | return _value; 12 | } 13 | 14 | public SetterReturns setValue(String value) { 15 | _value += value; 16 | return this; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/FormComponentImpl.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class FormComponentImpl extends ComponentImpl implements IFormComponent { 7 | 8 | IForm _form; 9 | 10 | 11 | public IForm getForm() { 12 | return _form; 13 | } 14 | 15 | public void setForm(IForm form) { 16 | _form = form; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/TestImpl.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 8 | */ 9 | public class TestImpl extends TestClass { 10 | 11 | public Map getTheMap() { 12 | Map map = new HashMap(); 13 | map.put("key", "value"); 14 | return map; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/OtherEnum.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public enum OtherEnum { 7 | 8 | ONE(1); 9 | 10 | public static final String STATIC_STRING = "string"; 11 | 12 | private int _value; 13 | 14 | private OtherEnum(int value) { 15 | _value = value; 16 | } 17 | 18 | public int getValue() { 19 | return _value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/IndexedMapObject.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * Simple object used to test indexed map references using "#this" references. 5 | */ 6 | public class IndexedMapObject { 7 | 8 | String property; 9 | 10 | public IndexedMapObject(String property) { 11 | this.property = property; 12 | } 13 | 14 | public String getProperty() { 15 | return property; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/SimpleNumeric.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * Used for {@link ognl.test.PropertyArithmeticAndLogicalOperatorsTest}. 5 | */ 6 | public class SimpleNumeric { 7 | 8 | public double getBudget() { 9 | return 140; 10 | } 11 | 12 | public double getTimeBilled() { 13 | return 24.12; 14 | } 15 | 16 | public String getTableSize() { 17 | return "10"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/GetterMethods.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class GetterMethods { 7 | 8 | private int theInt = 1; 9 | 10 | public boolean isAllowDisplay(Object something) { 11 | return true; 12 | } 13 | 14 | public int getAllowDisplay() { 15 | return theInt; 16 | } 17 | 18 | public void setAllowDisplay(int val) { 19 | theInt = val; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/TestModel.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class TestModel { 7 | 8 | public Copy getCopy() { 9 | return new Copy(); 10 | } 11 | 12 | public Model getUnassignedCopyModel() { 13 | return new Model(); 14 | } 15 | 16 | public boolean isCanApproveCopy() { 17 | return true; 18 | } 19 | 20 | public Entry getEntry() { 21 | return new Entry(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/GameGenericObject.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class GameGenericObject implements GenericObject { 7 | 8 | public GameGenericObject() { 9 | super(); 10 | } 11 | 12 | public int getId() { 13 | return 20; 14 | } 15 | 16 | public String getDisplayName() { 17 | return "Halo 3"; 18 | } 19 | 20 | public String getHappy() { 21 | return "happy"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/GenericServiceImpl.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | public class GenericServiceImpl implements GenericService { 4 | 5 | public String getFullMessageFor(GameGenericObject game, Object... arguments) { 6 | game.getHappy(); 7 | 8 | return game.getDisplayName(); 9 | } 10 | 11 | public String getFullMessageFor(PersonGenericObject person, Object... arguments) { 12 | return person.getDisplayName(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/ComponentImpl.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class ComponentImpl implements IComponent { 7 | 8 | String _clientId; 9 | int _count = 0; 10 | 11 | public String getClientId() { 12 | return _clientId; 13 | } 14 | 15 | public void setClientId(String id) { 16 | _clientId = id; 17 | } 18 | 19 | public int getCount(String index) { 20 | return _count; 21 | } 22 | 23 | public void setCount(String index, int count) { 24 | _count = count; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/GenericRoot.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class GenericRoot { 7 | 8 | Root _root = new Root(); 9 | GenericCracker _cracker = new GenericCracker(); 10 | 11 | public Root getRoot() { 12 | return _root; 13 | } 14 | 15 | public void setRoot(Root root) { 16 | _root = root; 17 | } 18 | 19 | public GenericCracker getCracker() { 20 | return _cracker; 21 | } 22 | 23 | public void setCracker(GenericCracker cracker) { 24 | _cracker = cracker; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.claude/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "allow": [ 4 | "WebSearch", 5 | "WebFetch(domain:github.com)", 6 | "WebFetch(domain:raw.githubusercontent.com)", 7 | "Bash(mvn help:*)", 8 | "Bash(mvn test:*)", 9 | "Bash(git branch:*)", 10 | "Bash(git add:*)", 11 | "Bash(git commit:*)", 12 | "Bash(git push:*)", 13 | "Bash(git checkout:*)", 14 | "Bash(git reset:*)", 15 | "Bash(gh pr view:*)", 16 | "Bash(gh pr diff:*)", 17 | "Bash(gh pr create:*)", 18 | "mcp__jetbrains" 19 | ], 20 | "deny": [] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/TreeContentProvider.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.util.Collection; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | /** 8 | * 9 | */ 10 | public class TreeContentProvider implements ITreeContentProvider { 11 | 12 | 13 | public Collection getChildren(Object parentElement) { 14 | return Collections.EMPTY_LIST; 15 | } 16 | 17 | public boolean hasChildren(Object parentElement) { 18 | return true; 19 | } 20 | 21 | public List getElements() { 22 | return Collections.EMPTY_LIST; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use only the supported versions 6 | 7 | | Version | Supported | 8 | | ------- | ------------------ | 9 | | 3.4.x | :white_check_mark: | 10 | | 3.3.x | :x: | 11 | | 3.2.x | :x: | 12 | | 3.1.x | :x: | 13 | | 3.0.x | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Do not report security vulnerabilities using Github Issues, please contact [security@orphan.software](mailto:security@orphan.software) or contact [Tidelift Security](https://tidelift.com/security) directly before taking any action . 18 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/ListSourceImpl.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.io.Serial; 4 | import java.util.ArrayList; 5 | 6 | public class ListSourceImpl extends ArrayList implements ListSource { 7 | 8 | @Serial 9 | private static final long serialVersionUID = 6144140702137776331L; 10 | 11 | public ListSourceImpl() { 12 | } 13 | 14 | public int getTotal() { 15 | return super.size(); 16 | } 17 | 18 | public Object addValue(Object value) { 19 | return super.add(value); 20 | } 21 | 22 | public Object getName() { 23 | return null; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/BeanProviderImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package ognl.test.objects; 5 | 6 | import java.io.Serializable; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | 11 | /** 12 | * Implementation of {@link BeanProvider}. 13 | */ 14 | public class BeanProviderImpl implements Serializable, BeanProvider { 15 | private Map _map = new HashMap(); 16 | 17 | public BeanProviderImpl() { 18 | } 19 | 20 | public Object getBean(String name) { 21 | return _map.get(name); 22 | } 23 | 24 | public void setBean(String name, Object bean) { 25 | _map.put(name, bean); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/Entry.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * 5 | */ 6 | public class Entry { 7 | 8 | private int _size = 1; 9 | 10 | public int size() { 11 | return _size; 12 | } 13 | 14 | public Copy getCopy() { 15 | return new Copy(); 16 | } 17 | 18 | public boolean equals(Object o) { 19 | if (this == o) 20 | return true; 21 | if (o == null || getClass() != o.getClass()) 22 | return false; 23 | 24 | Entry entry = (Entry) o; 25 | return _size == entry._size; 26 | } 27 | 28 | public int hashCode() { 29 | return _size; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/BaseBean.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package ognl.test.objects; 5 | 6 | 7 | /** 8 | * Base class used to test inheritance class casting. 9 | */ 10 | public abstract class BaseBean { 11 | 12 | public abstract String getName(); 13 | 14 | public boolean getActive() { 15 | return true; 16 | } 17 | 18 | public boolean isActive2() { 19 | return true; 20 | } 21 | 22 | public Two getTwo() { 23 | return new Two(); 24 | } 25 | 26 | public String getMessage(String mes) { 27 | return "[" + mes + "]"; 28 | } 29 | 30 | public boolean hasChildren(String name) { 31 | return name.length() > 2; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/PropertyHolder.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | /** 4 | * Simple class used to test various kind of property resolutions. 5 | */ 6 | public class PropertyHolder { 7 | 8 | String _value = ""; 9 | String _search = "foo"; 10 | 11 | public String getValue() { 12 | return _value; 13 | } 14 | 15 | public void setValue(String value) { 16 | _value = value; 17 | } 18 | 19 | public boolean hasValue() { 20 | return _value != null && _value.length() > 0; 21 | } 22 | 23 | public void setSearch(String value) { 24 | _search = value; 25 | } 26 | 27 | public String getSearch() { 28 | return _search; 29 | } 30 | 31 | public void search() { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/Messages.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * 7 | */ 8 | public class Messages { 9 | 10 | Map _source; 11 | 12 | public Messages(Map source) { 13 | _source = source; 14 | } 15 | 16 | public String getMessage(String key) { 17 | return (String) _source.get(key); 18 | } 19 | 20 | public String format(String key, Object[] parms) { 21 | return "foo"; 22 | } 23 | 24 | public String format(String key, Object param1, Object param2, Object param3) { 25 | return "blah"; 26 | } 27 | 28 | public String format(String key, Object param1) { 29 | return "first"; 30 | } 31 | 32 | public String format(String key, Object param1, Object param2) { 33 | return "haha"; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [lukaszlenart] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: "maven/ognl:ognl" # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/BaseGeneric.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Used to test ognl handling of java generics. 7 | */ 8 | public class BaseGeneric { 9 | 10 | E _value; 11 | GenericService _service; 12 | protected I[] ids; 13 | 14 | public BaseGeneric() { 15 | _service = new GenericServiceImpl(); 16 | } 17 | 18 | public void setIds(I[] ids) { 19 | this.ids = ids; 20 | } 21 | 22 | public I[] getIds() { 23 | return this.ids; 24 | } 25 | 26 | public String getMessage() { 27 | return "Message"; 28 | } 29 | 30 | public E getValue() { 31 | return _value; 32 | } 33 | 34 | public GenericService getService() { 35 | return _service; 36 | } 37 | 38 | public String format(Object value) { 39 | return value.toString(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/IndexedSetObject.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * Test for OGNL-119. 7 | */ 8 | public class IndexedSetObject { 9 | 10 | private final HashMap things = new HashMap(); 11 | 12 | public IndexedSetObject() { 13 | things.put("x", new Container(1)); 14 | } 15 | 16 | public Object getThing(String index) { 17 | return things.get(index); 18 | } 19 | 20 | public void setThing(String index, Object value) { 21 | things.put(index, value); 22 | } 23 | 24 | public static class Container { 25 | private int val; 26 | 27 | public Container(int val) { 28 | this.val = val; 29 | } 30 | 31 | public int getVal() { 32 | return val; 33 | } 34 | 35 | public void setVal(int val) { 36 | this.val = val; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/entry/CacheEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal.entry; 20 | 21 | public interface CacheEntry { 22 | } 23 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/entry/ClassCacheEntryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal.entry; 20 | 21 | public interface ClassCacheEntryFactory extends CacheEntryFactory, T> { 22 | } 23 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/Bean1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.objects; 20 | 21 | public class Bean1 extends Object { 22 | private Bean2 bean2 = new Bean2(); 23 | 24 | public Bean2 getBean2() { 25 | return bean2; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/entry/CacheEntryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal.entry; 20 | 21 | import ognl.internal.CacheException; 22 | 23 | public interface CacheEntryFactory { 24 | 25 | V create(K key) throws CacheException; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/Cache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal; 20 | 21 | public interface Cache { 22 | 23 | void clear(); 24 | 25 | int getSize(); 26 | 27 | V get(K key) throws CacheException; 28 | 29 | V put(K key, V value); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/OtherObjectIndexed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.objects; 20 | 21 | public class OtherObjectIndexed extends BaseObjectIndexed { 22 | public OtherObjectIndexed() { 23 | super(); 24 | setAttribute("foo", "bar"); 25 | setAttribute("bar", "baz"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/CacheException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal; 20 | 21 | public class CacheException extends RuntimeException { 22 | 23 | private static final long serialVersionUID = 3909399641531596633L; 24 | 25 | public CacheException(Throwable e) { 26 | super(e.getMessage(), e); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ognl/src/test/java/com/sun/test/AnotherInternalClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.sun.test; 20 | 21 | /** 22 | * This class is in the "com.sun.test" package to simulate internal classes 23 | * for testing accessibility detection. 24 | */ 25 | public class AnotherInternalClass { 26 | public String getValue() { 27 | return "com.sun.internal"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/MenuItem.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * 8 | */ 9 | public class MenuItem { 10 | 11 | private String page; 12 | private String label; 13 | private List children = new ArrayList(); 14 | 15 | public MenuItem(String page, String label) { 16 | this(page, label, new ArrayList()); 17 | } 18 | 19 | public MenuItem(String page, String label, List children) { 20 | this.page = page; 21 | this.label = label; 22 | this.children = children; 23 | } 24 | 25 | public List getChildren() { 26 | return children; 27 | } 28 | 29 | public String getLabel() { 30 | return label; 31 | } 32 | 33 | public String getPage() { 34 | return page; 35 | } 36 | 37 | public String toString() { 38 | StringBuffer sb = new StringBuffer("MenuItem["); 39 | sb.append("page=" + getPage()); 40 | sb.append(",label=" + getLabel()); 41 | sb.append(",children=" + getChildren().size()); 42 | sb.append("]"); 43 | return sb.toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/MyMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.objects; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * This tests the interface inheritence test. This is a subinterface 25 | * of Map and therefore should inherit the Map property accessor. 26 | */ 27 | public interface MyMap extends Map { 28 | public String getDescription(); 29 | } 30 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/ObjectIndexed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.objects; 20 | 21 | public class ObjectIndexed extends BaseObjectIndexed { 22 | public ObjectIndexed() { 23 | super(); 24 | setAttribute("foo", "bar"); 25 | setAttribute("bar", "baz"); 26 | setAttribute("other", new OtherObjectIndexed()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ClassResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | /** 22 | * This interface defines an object that will resolve a class from a string 23 | * and a ognl context table. 24 | */ 25 | public interface ClassResolver> { 26 | 27 | Class classForName(String className, C context) throws ClassNotFoundException; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/ClassCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal; 20 | 21 | import ognl.ClassCacheInspector; 22 | 23 | /** 24 | * This is a highly specialized map for storing values keyed by Class objects. 25 | */ 26 | public interface ClassCache extends Cache, V> { 27 | 28 | void setClassInspector(ClassCacheInspector inspector); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /ognl/src/test/java/sun/test/PublicTestInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package sun.test; 20 | 21 | /** 22 | * Public interface in sun.test package for testing. 23 | *

24 | * Since this is an interface, isLikelyAccessible() will return true for it, 25 | * even though it's in a "sun." package. 26 | */ 27 | public interface PublicTestInterface { 28 | String testMethod(); 29 | } 30 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/BeanProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.objects; 20 | 21 | /** 22 | * Test interface to be used with a custom property accessor. 23 | */ 24 | public interface BeanProvider { 25 | 26 | /** 27 | * Gets a bean by name. 28 | */ 29 | Object getBean(String name); 30 | 31 | /** 32 | * Sets a new bean mapping. 33 | */ 34 | void setBean(String name, Object bean); 35 | } 36 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/CacheFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal; 20 | 21 | import ognl.internal.entry.CacheEntryFactory; 22 | import ognl.internal.entry.ClassCacheEntryFactory; 23 | 24 | public interface CacheFactory { 25 | 26 | Cache createCache(CacheEntryFactory entryFactory); 27 | 28 | ClassCache createClassCache(); 29 | 30 | ClassCache createClassCache(ClassCacheEntryFactory entryFactory); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/enhance/EnhancedClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * and/or LICENSE file distributed with this work for additional 5 | * information regarding copyright ownership. The ASF licenses 6 | * this file to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.enhance; 20 | 21 | public class EnhancedClassLoader extends ClassLoader { 22 | 23 | public EnhancedClassLoader(ClassLoader parentClassLoader) { 24 | super(parentClassLoader); 25 | } 26 | 27 | public Class defineClass(String enhancedClassName, byte[] byteCode) { 28 | return defineClass(enhancedClassName, byteCode, 0, byteCode.length); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ExpressionSyntaxException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | /** 22 | * Exception thrown if a malformed OGNL expression is encountered. 23 | */ 24 | public class ExpressionSyntaxException extends OgnlException { 25 | 26 | private static final long serialVersionUID = 3219409775304901172L; 27 | 28 | public ExpressionSyntaxException(String expression, Throwable reason) { 29 | super("Malformed OGNL expression: " + expression, reason); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/MapElementsAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.Enumeration; 22 | import java.util.Map; 23 | 24 | /** 25 | * Implementation of ElementsAccessor that returns an iterator over the map's values. 26 | */ 27 | public class MapElementsAccessor implements ElementsAccessor { 28 | 29 | public Enumeration getElements(Object target) { 30 | return new IteratorEnumeration(((Map) target).values().iterator()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/CollectionElementsAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.Collection; 22 | import java.util.Enumeration; 23 | 24 | /** 25 | * Implementation of ElementsAccessor that returns a collection's iterator. 26 | */ 27 | public class CollectionElementsAccessor implements ElementsAccessor { 28 | 29 | public Enumeration getElements(Object target) { 30 | return new IteratorEnumeration(((Collection) target).iterator()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/EnumerationElementsAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.Enumeration; 22 | 23 | /** 24 | * Implementation of the ElementsAccessor interface for Enumerations, which returns an 25 | * iterator that passes its calls through to the target Enumeration. 26 | */ 27 | public class EnumerationElementsAccessor implements ElementsAccessor { 28 | 29 | public Enumeration getElements(Object target) { 30 | return (Enumeration) target; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/IteratorElementsAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.Enumeration; 22 | import java.util.Iterator; 23 | 24 | /** 25 | * Implementation of the ElementsAccessor interface for Iterators, which simply returns 26 | * the target iterator itself. 27 | */ 28 | public class IteratorElementsAccessor implements ElementsAccessor { 29 | 30 | public Enumeration getElements(Object target) { 31 | return new IteratorEnumeration((Iterator) target); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/CorrectedObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.objects; 20 | 21 | public class CorrectedObject { 22 | public CorrectedObject() { 23 | } 24 | 25 | public void setStringValue(String value) { 26 | } 27 | 28 | public String getStringValue() { 29 | return null; 30 | } 31 | 32 | public String getIndexedStringValue(String key) { 33 | return null; 34 | } 35 | 36 | public void setIndexedStringValue(String key, String value) { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/AbstractMemberAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * and/or LICENSE file distributed with this work for additional 5 | * information regarding copyright ownership. The ASF licenses 6 | * this file to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.lang.reflect.Member; 22 | 23 | /** 24 | * Used as a based class 25 | */ 26 | abstract public class AbstractMemberAccess> implements MemberAccess { 27 | 28 | public Object setup(C context, Object target, Member member, String propertyName) { 29 | return null; 30 | } 31 | 32 | public void restore(C context, Object target, Member member, String propertyName, Object state) { 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ObjectNullHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | /** 22 | * Implementation of NullHandler that returns null in all cases, 23 | * so that NullPointerException will be thrown by the caller. 24 | */ 25 | public class ObjectNullHandler> implements NullHandler { 26 | public Object nullMethodResult(C context, Object target, String methodName, Object[] args) { 27 | return null; 28 | } 29 | 30 | public Object nullPropertyValue(C context, Object target, Object property) { 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ClassCacheInspector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | /** 22 | * Optional interface that may be registered with {@link OgnlRuntime#setClassCacheInspector(ClassCacheInspector)} 23 | * as a means to disallow caching of specific class types. 24 | */ 25 | public interface ClassCacheInspector { 26 | 27 | /** 28 | * Invoked just before storing a class type within a cache instance. 29 | * 30 | * @param type The class that is to be stored. 31 | * @return True if the class can be cached, false otherwise. 32 | */ 33 | boolean shouldCache(Class type); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/InappropriateExpressionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | /** 22 | * Exception thrown if an OGNL expression is evaluated in the wrong context; the usual 23 | * case is when an expression that does not end in a property reference is passed to 24 | * setValue. 25 | */ 26 | public class InappropriateExpressionException extends OgnlException { 27 | 28 | private static final long serialVersionUID = 1976942828887727759L; 29 | 30 | public InappropriateExpressionException(Node tree) { 31 | super("Inappropriate OGNL expression: " + tree); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/IteratorEnumeration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.Enumeration; 22 | import java.util.Iterator; 23 | 24 | /** 25 | * Maps an Iterator to an Enumeration 26 | */ 27 | public class IteratorEnumeration implements Enumeration { 28 | 29 | private final Iterator it; 30 | 31 | public IteratorEnumeration(Iterator it) { 32 | super(); 33 | this.it = it; 34 | } 35 | 36 | public boolean hasMoreElements() { 37 | return it.hasNext(); 38 | } 39 | 40 | public Object nextElement() { 41 | return it.next(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/MethodFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | /** 22 | * Exception thrown if a method or constructor call fails. 23 | */ 24 | public class MethodFailedException extends OgnlException { 25 | 26 | private static final long serialVersionUID = 2490616172311289862L; 27 | 28 | public MethodFailedException(Object source, String name) { 29 | super("Method \"" + name + "\" failed for object " + source); 30 | } 31 | 32 | public MethodFailedException(Object source, String name, Throwable reason) { 33 | super("Method \"" + name + "\" failed for object " + source, reason); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/NodeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import ognl.enhance.OgnlExpressionCompiler; 22 | 23 | /** 24 | * Used by some of the {@link OgnlExpressionCompiler} logic to determine the object 25 | * type of {@link Node}s during expression evaluation. 26 | */ 27 | public interface NodeType { 28 | 29 | /** 30 | * The type returned from the expression - if any. 31 | * 32 | * @return The type. 33 | */ 34 | Class getGetterClass(); 35 | 36 | /** 37 | * The type used to set the value - if any. 38 | * 39 | * @return The type. 40 | */ 41 | Class getSetterClass(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/HashMapCacheFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal; 20 | 21 | 22 | import ognl.internal.entry.CacheEntryFactory; 23 | import ognl.internal.entry.ClassCacheEntryFactory; 24 | 25 | public class HashMapCacheFactory implements CacheFactory { 26 | 27 | public Cache createCache(CacheEntryFactory entryFactory) { 28 | return new HashMapCache<>(entryFactory); 29 | } 30 | 31 | public ClassCache createClassCache() { 32 | return createClassCache(null); 33 | } 34 | 35 | public ClassCache createClassCache(ClassCacheEntryFactory entryFactory) { 36 | return new HashMapClassCache<>(entryFactory); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/entry/MethodAccessEntryValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal.entry; 20 | 21 | public class MethodAccessEntryValue { 22 | 23 | private final boolean isAccessible; 24 | private boolean notPublic; 25 | 26 | public MethodAccessEntryValue(boolean accessible) { 27 | this.isAccessible = accessible; 28 | } 29 | 30 | public MethodAccessEntryValue(boolean accessible, boolean notPublic) { 31 | isAccessible = accessible; 32 | this.notPublic = notPublic; 33 | } 34 | 35 | public boolean isAccessible() { 36 | return isAccessible; 37 | } 38 | 39 | public boolean isNotPublic() { 40 | return notPublic; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ognl/src/test/java/sun/test/SimulatedInternalClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package sun.test; 20 | 21 | /** 22 | * This class is intentionally in the "sun.test" package to simulate 23 | * an internal JDK class for testing purposes. 24 | *

25 | * The isLikelyAccessible() method will return false for classes in packages 26 | * starting with "sun.", which allows us to test the accessibility logic 27 | * without needing actual internal JDK classes. 28 | */ 29 | public class SimulatedInternalClass implements sun.test.PublicTestInterface { 30 | @Override 31 | public String testMethod() { 32 | return "internal"; 33 | } 34 | 35 | public String anotherMethod() { 36 | return "internal-another"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/entry/DeclaredMethodCacheEntryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal.entry; 20 | 21 | import java.lang.reflect.Method; 22 | import java.lang.reflect.Modifier; 23 | 24 | public class DeclaredMethodCacheEntryFactory extends MethodCacheEntryFactory { 25 | 26 | @Override 27 | protected boolean shouldCache(DeclaredMethodCacheEntry key, Method method) { 28 | if (key.type == null) { 29 | return true; 30 | } 31 | boolean isStatic = Modifier.isStatic(method.getModifiers()); 32 | if (key.type == DeclaredMethodCacheEntry.MethodType.STATIC) { 33 | return isStatic; 34 | } 35 | return !isStatic; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/entry/FieldCacheEntryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal.entry; 20 | 21 | import ognl.internal.CacheException; 22 | 23 | import java.lang.reflect.Field; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | public class FieldCacheEntryFactory implements ClassCacheEntryFactory> { 28 | 29 | public Map create(Class key) throws CacheException { 30 | Field[] declaredFields = key.getDeclaredFields(); 31 | Map result = new HashMap<>(declaredFields.length); 32 | for (Field field : declaredFields) { 33 | result.put(field.getName(), field); 34 | } 35 | return result; 36 | } 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/IsTruckTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.DefaultMemberAccess; 22 | import ognl.Ognl; 23 | import ognl.OgnlContext; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertTrue; 27 | 28 | class IsTruckTest { 29 | 30 | @Test 31 | void testIsTruckMethod() throws Exception { 32 | OgnlContext context = Ognl.createDefaultContext(null, new DefaultMemberAccess(false)); 33 | boolean actual = (Boolean) Ognl.getValue("isTruck", context, new TruckHolder()); 34 | 35 | assertTrue(actual); 36 | } 37 | 38 | } 39 | 40 | class TruckHolder { 41 | 42 | public boolean getIsTruck() { 43 | return true; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/DefaultTypeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.lang.reflect.Member; 22 | 23 | /** 24 | * Default type conversion. Converts among numeric types and also strings. 25 | */ 26 | public class DefaultTypeConverter> implements TypeConverter { 27 | 28 | public DefaultTypeConverter() { 29 | super(); 30 | } 31 | 32 | public Object convertValue(C context, Object value, Class toType) { 33 | return OgnlOps.convertValue(value, toType); 34 | } 35 | 36 | public Object convertValue(C context, Object target, Member member, String propertyName, Object value, Class toType) { 37 | return convertValue(context, value, toType); 38 | } 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/enhance/ContextClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * and/or LICENSE file distributed with this work for additional 5 | * information regarding copyright ownership. The ASF licenses 6 | * this file to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.enhance; 20 | 21 | import ognl.OgnlContext; 22 | 23 | public class ContextClassLoader> extends ClassLoader { 24 | 25 | private final C context; 26 | 27 | public ContextClassLoader(ClassLoader parentClassLoader, C context) { 28 | super(parentClassLoader); 29 | this.context = context; 30 | } 31 | 32 | protected Class findClass(String name) throws ClassNotFoundException { 33 | if ((context != null) && (context.getClassResolver() != null)) { 34 | return context.getClassResolver().classForName(name, context); 35 | } 36 | return super.findClass(name); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/EvenOdd.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.objects; 20 | 21 | public class EvenOdd { 22 | 23 | private boolean even = true; 24 | 25 | /** 26 | * Returns "even" or "odd". Whatever it returns on one invocation, it will 27 | * return the opposite on the next. By default, the first value returned is 28 | * "even". 29 | */ 30 | public String getNext() { 31 | String result = even ? "even" : "odd"; 32 | even = !even; 33 | return result; 34 | } 35 | 36 | public boolean isEven() { 37 | return even; 38 | } 39 | 40 | /** 41 | * Overrides the even flag. 42 | */ 43 | public void setEven(boolean value) { 44 | even = value; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/EnumerationIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.Enumeration; 22 | import java.util.Iterator; 23 | 24 | /** 25 | * Object that implements Iterator from an Enumeration 26 | */ 27 | public class EnumerationIterator implements Iterator { 28 | 29 | private Enumeration enumeration; 30 | 31 | public EnumerationIterator(Enumeration enumeration) { 32 | this.enumeration = enumeration; 33 | } 34 | 35 | public boolean hasNext() { 36 | return enumeration.hasMoreElements(); 37 | } 38 | 39 | public T next() { 40 | return enumeration.nextElement(); 41 | } 42 | 43 | public void remove() { 44 | throw new UnsupportedOperationException("remove() not supported by Enumeration"); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/InExpressionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.DefaultMemberAccess; 22 | import ognl.Ognl; 23 | import ognl.OgnlContext; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals; 27 | 28 | /** 29 | * Test for OGNL-118. 30 | */ 31 | class InExpressionTest { 32 | 33 | @Test 34 | void test_String_In() throws Exception { 35 | OgnlContext context = Ognl.createDefaultContext(null, new DefaultMemberAccess(false)); 36 | Object node = Ognl.parseExpression("#name in {\"Greenland\", \"Austin\", \"Africa\", \"Rome\"}"); 37 | Object root = null; 38 | 39 | context.put("name", "Austin"); 40 | assertEquals(Boolean.TRUE, Ognl.getValue(node, context, root)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/HashMapClassCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal; 20 | 21 | import ognl.ClassCacheInspector; 22 | import ognl.internal.entry.CacheEntryFactory; 23 | 24 | public class HashMapClassCache extends HashMapCache, T> implements ClassCache { 25 | 26 | private ClassCacheInspector inspector; 27 | 28 | public HashMapClassCache(CacheEntryFactory, T> entryFactory) { 29 | super(entryFactory); 30 | } 31 | 32 | public void setClassInspector(ClassCacheInspector inspector) { 33 | this.inspector = inspector; 34 | } 35 | 36 | public T put(Class key, T value) { 37 | if (inspector != null && !inspector.shouldCache(key)) { 38 | return value; 39 | } 40 | return super.put(key, value); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/entry/MethodCacheEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal.entry; 20 | 21 | public class MethodCacheEntry implements CacheEntry { 22 | 23 | public final Class targetClass; 24 | 25 | public MethodCacheEntry(Class targetClass) { 26 | this.targetClass = targetClass; 27 | } 28 | 29 | @Override 30 | public boolean equals(Object o) { 31 | if (this == o) { 32 | return true; 33 | } 34 | if (!(o instanceof MethodCacheEntry)) { 35 | return false; 36 | } 37 | 38 | MethodCacheEntry that = (MethodCacheEntry) o; 39 | 40 | return targetClass.equals(that.targetClass); 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | return targetClass.hashCode(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/util/EnhancedClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.util; 20 | 21 | public class EnhancedClassLoader extends ClassLoader { 22 | /*=================================================================== 23 | Constructors 24 | ===================================================================*/ 25 | public EnhancedClassLoader(ClassLoader parentClassLoader) { 26 | super(parentClassLoader); 27 | } 28 | 29 | /*=================================================================== 30 | Overridden methods 31 | ===================================================================*/ 32 | public Class defineClass(String enhancedClassName, byte[] byteCode) { 33 | return defineClass(enhancedClassName, byteCode, 0, byteCode.length); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTDivide.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTDivide> extends NumericExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = 7924993880701535061L; 27 | 28 | public ASTDivide(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTDivide(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | Object v2 = children[1].getValue(context, source); 39 | return OgnlOps.divide(v1, v2); 40 | } 41 | 42 | public String getExpressionOperator(int index) { 43 | return "/"; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTSubtract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTSubtract> extends NumericExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = -7677636672357878823L; 27 | 28 | public ASTSubtract(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTSubtract(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | Object v2 = children[1].getValue(context, source); 39 | return OgnlOps.subtract(v1, v2); 40 | } 41 | 42 | public String getExpressionOperator(int index) { 43 | return "-"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/AccessibleObjectHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * and/or LICENSE file distributed with this work for additional 5 | * information regarding copyright ownership. The ASF licenses 6 | * this file to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.lang.reflect.AccessibleObject; 22 | 23 | /** 24 | * This interface provides a mechanism for indirect reflection access processing 25 | * of AccessibleObject instances by OGNL. It can be used to provide different 26 | * behaviour as JDK reflection mechanisms evolve. 27 | * 28 | * @since 3.1.24 29 | */ 30 | public interface AccessibleObjectHandler { 31 | /** 32 | * Provides an appropriate implementation to change the accessibility of accessibleObject. 33 | * 34 | * @param accessibleObject the AccessibleObject upon which to apply the flag. 35 | * @param flag the new accessible flag value. 36 | */ 37 | void setAccessible(AccessibleObject accessibleObject, boolean flag); 38 | } 39 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTRemainder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTRemainder> extends NumericExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = -3811328375555237590L; 27 | 28 | public ASTRemainder(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTRemainder(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | Object v2 = children[1].getValue(context, source); 39 | return OgnlOps.remainder(v1, v2); 40 | } 41 | 42 | public String getExpressionOperator(int index) { 43 | return "%"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTShiftLeft.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTShiftLeft> extends NumericExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = 736476424938506175L; 27 | 28 | public ASTShiftLeft(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTShiftLeft(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | Object v2 = children[1].getValue(context, source); 39 | return OgnlOps.shiftLeft(v1, v2); 40 | } 41 | 42 | public String getExpressionOperator(int index) { 43 | return "<<"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ArrayElementsAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * and/or LICENSE file distributed with this work for additional 5 | * information regarding copyright ownership. The ASF licenses 6 | * this file to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.lang.reflect.Array; 22 | import java.util.Enumeration; 23 | 24 | /** 25 | * Implementation of ElementsAccessor that returns an iterator over a Java array. 26 | */ 27 | public class ArrayElementsAccessor implements ElementsAccessor { 28 | public Enumeration getElements(final Object target) { 29 | return new Enumeration() { 30 | private final int count = Array.getLength(target); 31 | private int index = 0; 32 | 33 | public boolean hasMoreElements() { 34 | return index < count; 35 | } 36 | 37 | public Object nextElement() { 38 | return Array.get(target, index++); 39 | } 40 | }; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTShiftRight.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTShiftRight> extends NumericExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = 9190099431531689455L; 27 | 28 | public ASTShiftRight(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTShiftRight(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | Object v2 = children[1].getValue(context, source); 39 | return OgnlOps.shiftRight(v1, v2); 40 | } 41 | 42 | public String getExpressionOperator(int index) { 43 | return ">>"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/OgnlInvokePermission.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.security.BasicPermission; 22 | 23 | /** 24 | * BasicPermission subclass that defines a permission token for invoking 25 | * methods within OGNL. This does not override any methods (except 26 | * constructors) and does not implement actions. It is similar in spirit 27 | * to the {@link java.lang.reflect.ReflectPermission} class in that it 28 | * guards access to methods. 29 | */ 30 | public class OgnlInvokePermission extends BasicPermission { 31 | 32 | private static final long serialVersionUID = -1075128617667321761L; 33 | 34 | public OgnlInvokePermission(String name) { 35 | super(name); 36 | } 37 | 38 | public OgnlInvokePermission(String name, String actions) { 39 | super(name, actions); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/PrimitiveTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | class PrimitiveTypes { 25 | 26 | private final Map> PRIMITIVE_TYPES = new HashMap<>(8); 27 | 28 | PrimitiveTypes() { 29 | PRIMITIVE_TYPES.put("boolean", Boolean.TYPE); 30 | PRIMITIVE_TYPES.put("byte", Byte.TYPE); 31 | PRIMITIVE_TYPES.put("short", Short.TYPE); 32 | PRIMITIVE_TYPES.put("char", Character.TYPE); 33 | PRIMITIVE_TYPES.put("int", Integer.TYPE); 34 | PRIMITIVE_TYPES.put("long", Long.TYPE); 35 | PRIMITIVE_TYPES.put("float", Float.TYPE); 36 | PRIMITIVE_TYPES.put("double", Double.TYPE); 37 | } 38 | 39 | Class get(String className) { 40 | return PRIMITIVE_TYPES.get(className); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/enhance/LocalReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * and/or LICENSE file distributed with this work for additional 5 | * information regarding copyright ownership. The ASF licenses 6 | * this file to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.enhance; 20 | 21 | /** 22 | * Container class for {@link OgnlExpressionCompiler} generated local method 23 | * block references. 24 | */ 25 | public interface LocalReference { 26 | 27 | /** 28 | * The name of the assigned variable reference. 29 | * 30 | * @return The name of the reference as it will be when compiled. 31 | */ 32 | String getName(); 33 | 34 | /** 35 | * The expression that sets the value, ie the part after <class type> refName = <expression>. 36 | * 37 | * @return The setting expression. 38 | */ 39 | String getExpression(); 40 | 41 | /** 42 | * The type of reference. 43 | * 44 | * @return The type. 45 | */ 46 | Class getType(); 47 | } 48 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/ASTChainTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.DefaultMemberAccess; 22 | import ognl.Ognl; 23 | import ognl.OgnlContext; 24 | import ognl.test.objects.IndexedSetObject; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import static org.junit.jupiter.api.Assertions.assertEquals; 28 | 29 | class ASTChainTest { 30 | 31 | @Test 32 | void getIndexedValue() throws Exception { 33 | OgnlContext context = Ognl.createDefaultContext(null, new DefaultMemberAccess(false)); 34 | IndexedSetObject root = new IndexedSetObject(); 35 | 36 | String expr = "thing[\"x\"].val"; 37 | 38 | assertEquals(1, Ognl.getValue(expr, context, root)); 39 | 40 | Ognl.setValue(expr, context, root, 2); 41 | 42 | assertEquals(2, Ognl.getValue(expr, context, root)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/NumericCasts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.math.BigDecimal; 22 | import java.math.BigInteger; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | /** 27 | * Constant strings for casting different primitive types. 28 | */ 29 | class NumericCasts { 30 | 31 | private final Map, String> NUMERIC_CASTS = new HashMap<>(6); 32 | 33 | NumericCasts() { 34 | NUMERIC_CASTS.put(Double.class, "(double)"); 35 | NUMERIC_CASTS.put(Float.class, "(float)"); 36 | NUMERIC_CASTS.put(Integer.class, "(int)"); 37 | NUMERIC_CASTS.put(Long.class, "(long)"); 38 | NUMERIC_CASTS.put(BigDecimal.class, "(double)"); 39 | NUMERIC_CASTS.put(BigInteger.class, ""); 40 | } 41 | 42 | String get(Class cls) { 43 | return NUMERIC_CASTS.get(cls); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/enhance/UnsupportedCompilationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * and/or LICENSE file distributed with this work for additional 5 | * information regarding copyright ownership. The ASF licenses 6 | * this file to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.enhance; 20 | 21 | /** 22 | * Thrown during bytecode enhancement conversions of ognl expressions to indicate 23 | * that a certain expression isn't currently supported as a pure java bytecode enhanced 24 | * version. 25 | * 26 | *

27 | * If this exception is thrown it is expected that ognl will fall back to default ognl 28 | * evaluation of the expression. 29 | *

30 | */ 31 | public class UnsupportedCompilationException extends RuntimeException { 32 | 33 | private static final long serialVersionUID = 37018630558258414L; 34 | 35 | public UnsupportedCompilationException(String message) { 36 | super(message); 37 | } 38 | 39 | public UnsupportedCompilationException(String message, Throwable cause) { 40 | super(message, cause); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /.github/workflows/ognl-3-4-x.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: Java CI - ognl-3-4-x 17 | 18 | on: 19 | push: 20 | branches: 21 | - ognl-3-4-x 22 | 23 | permissions: read-all 24 | 25 | env: 26 | MAVEN_OPTS: -Xmx2g -Xms1g 27 | LANG: en_US.utf8 28 | 29 | jobs: 30 | build: 31 | runs-on: ubuntu-latest 32 | steps: 33 | - name: Checkout code 34 | uses: actions/checkout@v6.0.1 35 | - name: Set up JDK 8 36 | uses: actions/setup-java@v5 37 | with: 38 | distribution: temurin 39 | java-version: 8 40 | cache: maven 41 | - name: Build with Maven on Java 9 42 | run: ./mvnw -B package -DskipTests 43 | - name: Test with Maven on Java 8 44 | run: ./mvnw -B verify 45 | - name: Deploy SNAPSHOT 46 | run: | 47 | echo "${{ secrets.MAVEN_SETTINGS }}" > ~/.m2/settings-ognl.xml 48 | ./mvnw -B -DskipTests=true deploy -s ~/.m2/settings-ognl.xml 49 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/CorrectedObjectNullHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.NullHandler; 22 | import ognl.OgnlContext; 23 | 24 | public class CorrectedObjectNullHandler implements NullHandler { 25 | 26 | private final String defaultValue; 27 | 28 | public CorrectedObjectNullHandler(String defaultValue) { 29 | super(); 30 | this.defaultValue = defaultValue; 31 | } 32 | 33 | public Object nullMethodResult(OgnlContext context, Object target, String methodName, Object[] args) { 34 | if (methodName.equals("getStringValue")) { 35 | return defaultValue; 36 | } 37 | return null; 38 | } 39 | 40 | public Object nullPropertyValue(OgnlContext context, Object target, Object property) { 41 | if (property.equals("stringValue")) { 42 | return defaultValue; 43 | } 44 | return null; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTEq.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTEq> extends ComparisonExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = 2327248469141797794L; 27 | 28 | public ASTEq(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTEq(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | Object v2 = children[1].getValue(context, source); 39 | return OgnlOps.equal(v1, v2) ? Boolean.TRUE : Boolean.FALSE; 40 | } 41 | 42 | public String getExpressionOperator(int index) { 43 | return "=="; 44 | } 45 | 46 | public String getComparisonFunction() { 47 | return "ognl.OgnlOps.equal"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/enhance/OrderedReturn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * and/or LICENSE file distributed with this work for additional 5 | * information regarding copyright ownership. The ASF licenses 6 | * this file to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.enhance; 20 | 21 | import ognl.Node; 22 | 23 | /** 24 | * Marks an ognl expression {@link Node} as needing to have the return portion of a 25 | * getter method happen in a specific part of the generated expression vs just having 26 | * the whole expression returned in one chunk. 27 | */ 28 | public interface OrderedReturn { 29 | 30 | /** 31 | * Get the core expression to execute first before any return foo logic is started. 32 | * 33 | * @return The core standalone expression that shouldn't be pre-pended with a return keyword. 34 | */ 35 | String getCoreExpression(); 36 | 37 | /** 38 | * Gets the last expression to be pre-pended with a return <expression> block. 39 | * 40 | * @return The expression representing the return portion of a statement; 41 | */ 42 | String getLastExpression(); 43 | } 44 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTLess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTLess> extends ComparisonExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = -5575803930862133743L; 27 | 28 | public ASTLess(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTLess(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | 39 | Object v2 = children[1].getValue(context, source); 40 | return OgnlOps.less(v1, v2) ? Boolean.TRUE : Boolean.FALSE; 41 | } 42 | 43 | public String getExpressionOperator(int index) { 44 | return "<"; 45 | } 46 | 47 | public String getComparisonFunction() { 48 | return "ognl.OgnlOps.less"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTXor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTXor> extends NumericExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = 5707892722708142594L; 27 | 28 | public ASTXor(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTXor(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | public void jjtClose() { 37 | flattenTree(); 38 | } 39 | 40 | protected Object getValueBody(C context, Object source) throws OgnlException { 41 | Object result = children[0].getValue(context, source); 42 | for (int i = 1; i < children.length; ++i) 43 | result = OgnlOps.binaryXor(result, children[i].getValue(context, source)); 44 | return result; 45 | } 46 | 47 | public String getExpressionOperator(int index) { 48 | return "^"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTBitOr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTBitOr> extends NumericExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = -1596881192315259748L; 27 | 28 | public ASTBitOr(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTBitOr(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | public void jjtClose() { 37 | flattenTree(); 38 | } 39 | 40 | protected Object getValueBody(C context, Object source) throws OgnlException { 41 | Object result = children[0].getValue(context, source); 42 | for (int i = 1; i < children.length; ++i) 43 | result = OgnlOps.binaryOr(result, children[i].getValue(context, source)); 44 | return result; 45 | } 46 | 47 | public String getExpressionOperator(int index) { 48 | return "|"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTNotEq.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTNotEq> extends ComparisonExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = -9161185502968425136L; 27 | 28 | public ASTNotEq(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTNotEq(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | Object v2 = children[1].getValue(context, source); 39 | 40 | return OgnlOps.equal(v1, v2) ? Boolean.FALSE : Boolean.TRUE; 41 | } 42 | 43 | public String getExpressionOperator(int index) { 44 | return "!="; 45 | } 46 | 47 | public String getComparisonFunction() { 48 | return "!ognl.OgnlOps.equal"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTLessEq.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTLessEq> extends ComparisonExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = 1564876674732452015L; 27 | 28 | public ASTLessEq(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTLessEq(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | Object v2 = children[1].getValue(context, source); 39 | return OgnlOps.greater(v1, v2) ? Boolean.FALSE : Boolean.TRUE; 40 | } 41 | 42 | public String getExpressionOperator(int index) { 43 | return "<="; 44 | } 45 | 46 | public String getComparisonFunction() { 47 | return "!ognl.OgnlOps.greater"; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ObjectElementsAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.Enumeration; 22 | 23 | /** 24 | * Implementation of ElementsAccessor that returns a single-element iterator, containing 25 | * the original target object. 26 | */ 27 | public class ObjectElementsAccessor implements ElementsAccessor { 28 | 29 | public Enumeration getElements(Object target) { 30 | 31 | final Object object = target; 32 | 33 | return new Enumeration<>() { 34 | private boolean seen = false; 35 | 36 | public boolean hasMoreElements() { 37 | return !seen; 38 | } 39 | 40 | public Object nextElement() { 41 | Object result = null; 42 | 43 | if (!seen) { 44 | result = object; 45 | seen = true; 46 | } 47 | return result; 48 | } 49 | }; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTGreater.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTGreater> extends ComparisonExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = -8158173472092839867L; 27 | 28 | public ASTGreater(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTGreater(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | Object v2 = children[1].getValue(context, source); 39 | 40 | return OgnlOps.greater(v1, v2) ? Boolean.TRUE : Boolean.FALSE; 41 | } 42 | 43 | public String getExpressionOperator(int index) { 44 | return ">"; 45 | } 46 | 47 | public String getComparisonFunction() { 48 | return "ognl.OgnlOps.greater"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTGreaterEq.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTGreaterEq> extends ComparisonExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = -5165257674133751294L; 27 | 28 | public ASTGreaterEq(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTGreaterEq(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | Object v1 = children[0].getValue(context, source); 38 | Object v2 = children[1].getValue(context, source); 39 | return OgnlOps.less(v1, v2) ? Boolean.FALSE : Boolean.TRUE; 40 | } 41 | 42 | public String getExpressionOperator(int index) { 43 | return ">="; 44 | } 45 | 46 | public String getComparisonFunction() { 47 | return "!ognl.OgnlOps.less"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTMultiply.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTMultiply> extends NumericExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = -3802338162124095297L; 27 | 28 | public ASTMultiply(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTMultiply(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | public void jjtClose() { 37 | flattenTree(); 38 | } 39 | 40 | protected Object getValueBody(C context, Object source) throws OgnlException { 41 | Object result = children[0].getValue(context, source); 42 | for (int i = 1; i < children.length; ++i) 43 | result = OgnlOps.multiply(result, children[i].getValue(context, source)); 44 | return result; 45 | } 46 | 47 | public String getExpressionOperator(int index) { 48 | return "*"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/package.html: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | OGNL Overview 24 | 25 |

OGNL stands for Object-Graph Navigation Language; it is an expression language 26 | for getting and setting properties of Java objects. You use the same expression 27 | for both getting and setting the value of a property.

28 | 29 |

OGNL started out as a way to set up associations between UI 30 | components and controllers using property names. As the desire for 31 | more complicated associations grew, Drew Davidson created what he 32 | called KVCL, for Key-Value Coding Language, egged on by Luke 33 | Blanshard. Luke then reimplemented the language using ANTLR, came up 34 | with the new name, and, egged on by Drew, filled it out to its current 35 | state.

36 | 37 |

We pronounce OGNL as a word, like the last syllables of a drunken 38 | pronunciation of "orthogonal" or like "ogg-null".

39 | 40 | 41 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/OgnlExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.OgnlException; 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; 25 | import static org.junit.jupiter.api.Assertions.assertInstanceOf; 26 | 27 | /** 28 | * Tests {@link OgnlException}. 29 | */ 30 | class OgnlExceptionTest { 31 | 32 | @Test 33 | void test_Throwable_Reason() { 34 | try { 35 | throwException(); 36 | } catch (OgnlException e) { 37 | assertInstanceOf(NumberFormatException.class, e.getReason()); 38 | assertEquals("Unable to parse input string.", e.getMessage()); 39 | } 40 | } 41 | 42 | void throwException() throws OgnlException { 43 | try { 44 | Integer.parseInt("45ac"); 45 | } catch (NumberFormatException et) { 46 | throw new OgnlException("Unable to parse input string.", et); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTKeyValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTKeyValue> extends SimpleNode { 24 | 25 | @Serial 26 | private static final long serialVersionUID = 5035649093189318943L; 27 | 28 | public ASTKeyValue(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTKeyValue(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Node getKey() { 37 | return children[0]; 38 | } 39 | 40 | protected Node getValue() { 41 | return (jjtGetNumChildren() > 1) ? children[1] : null; 42 | } 43 | 44 | /** 45 | * Returns null because this is a parser construct and does not evaluate 46 | */ 47 | protected Object getValueBody(C context, Object source) throws OgnlException { 48 | return null; 49 | } 50 | 51 | public String toString() { 52 | return getKey() + " -> " + getValue(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/ASTSequenceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.DefaultMemberAccess; 22 | import ognl.Ognl; 23 | import ognl.OgnlContext; 24 | import ognl.SimpleNode; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import static org.junit.jupiter.api.Assertions.assertFalse; 28 | import static org.junit.jupiter.api.Assertions.assertTrue; 29 | 30 | class ASTSequenceTest { 31 | 32 | @Test 33 | void isSequence() throws Exception { 34 | OgnlContext context = Ognl.createDefaultContext(null, new DefaultMemberAccess(false)); 35 | 36 | SimpleNode node = (SimpleNode) Ognl.parseExpression("#name"); 37 | assertFalse(node.isSequence(context)); 38 | 39 | node = (SimpleNode) Ognl.parseExpression("#name = 'boo', System.out.println(#name)"); 40 | assertTrue(node.isSequence(context)); 41 | 42 | node = (SimpleNode) Ognl.parseExpression("#name['foo'] = 'bar'"); 43 | assertFalse(node.isSequence(context)); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/ProtectedInnerClassTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.Ognl; 22 | import ognl.OgnlContext; 23 | import ognl.test.objects.Root; 24 | import org.junit.jupiter.api.BeforeEach; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import static org.junit.jupiter.api.Assertions.assertEquals; 28 | 29 | class ProtectedInnerClassTest { 30 | 31 | private Root root; 32 | private OgnlContext context; 33 | 34 | @BeforeEach 35 | void setUp() { 36 | root = new Root(); 37 | context = Ognl.createDefaultContext(root); 38 | } 39 | 40 | @Test 41 | void testListSize() throws Exception { 42 | Object actual = Ognl.getValue("list.size()", context, root); 43 | assertEquals(root.getList().size(), actual); 44 | } 45 | 46 | @Test 47 | void testListElement() throws Exception { 48 | Object actual = Ognl.getValue("list[0]", context, root); 49 | assertEquals(root.getList().get(0), actual); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/GenericsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.Ognl; 22 | import ognl.OgnlContext; 23 | import ognl.test.objects.BaseGeneric; 24 | import ognl.test.objects.GameGeneric; 25 | import ognl.test.objects.GameGenericObject; 26 | import org.junit.jupiter.api.BeforeEach; 27 | import org.junit.jupiter.api.Test; 28 | 29 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 30 | 31 | class GenericsTest { 32 | 33 | private BaseGeneric generic; 34 | private OgnlContext context; 35 | 36 | @BeforeEach 37 | void setUp() { 38 | generic = new GameGeneric(); 39 | context = Ognl.createDefaultContext(generic); 40 | } 41 | 42 | @Test 43 | void testIds() throws Exception { 44 | Long[] expected = new Long[]{1L, 101L}; 45 | Ognl.setValue("ids", context, generic, expected); 46 | Long[] actual = (Long[]) Ognl.getValue("ids", context, generic); 47 | 48 | assertArrayEquals(expected, actual); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/NumberElementsAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.Enumeration; 22 | import java.util.NoSuchElementException; 23 | 24 | /** 25 | * Implementation of ElementsAccessor that returns an iterator over integers from 0 up to 26 | * the given target. 27 | */ 28 | public class NumberElementsAccessor implements ElementsAccessor, NumericTypes { 29 | 30 | public Enumeration getElements(final Object target) { 31 | return new Enumeration<>() { 32 | private final int type = OgnlOps.getNumericType(target); 33 | private final long finish = OgnlOps.longValue(target); 34 | private long next = 0; 35 | 36 | public boolean hasMoreElements() { 37 | return next < finish; 38 | } 39 | 40 | public Object nextElement() { 41 | if (next >= finish) 42 | throw new NoSuchElementException(); 43 | return OgnlOps.newInteger(type, next++); 44 | } 45 | }; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/NumericDefaults.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.math.BigDecimal; 22 | import java.math.BigInteger; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | class NumericDefaults { 27 | 28 | private final Map, Object> NUMERIC_DEFAULTS = new HashMap<>(10); 29 | 30 | NumericDefaults() { 31 | NUMERIC_DEFAULTS.put(Boolean.class, Boolean.FALSE); 32 | NUMERIC_DEFAULTS.put(Byte.class, (byte) 0); 33 | NUMERIC_DEFAULTS.put(Short.class, (short) 0); 34 | NUMERIC_DEFAULTS.put(Character.class, (char) 0); 35 | NUMERIC_DEFAULTS.put(Integer.class, 0); 36 | NUMERIC_DEFAULTS.put(Long.class, 0L); 37 | NUMERIC_DEFAULTS.put(Float.class, 0.0f); 38 | NUMERIC_DEFAULTS.put(Double.class, 0.0); 39 | 40 | NUMERIC_DEFAULTS.put(BigInteger.class, BigInteger.ZERO); 41 | NUMERIC_DEFAULTS.put(BigDecimal.class, BigDecimal.ZERO); 42 | } 43 | 44 | Object get(Class cls) { 45 | return NUMERIC_DEFAULTS.get(cls); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/NumericLiterals.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.math.BigDecimal; 22 | import java.math.BigInteger; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | /** 27 | * Numeric primitive literal string expressions. 28 | */ 29 | class NumericLiterals { 30 | 31 | private final Map, String> NUMERIC_LITERALS = new HashMap<>(10); 32 | 33 | NumericLiterals() { 34 | NUMERIC_LITERALS.put(Integer.class, ""); 35 | NUMERIC_LITERALS.put(Integer.TYPE, ""); 36 | NUMERIC_LITERALS.put(Long.class, "l"); 37 | NUMERIC_LITERALS.put(Long.TYPE, "l"); 38 | NUMERIC_LITERALS.put(Float.class, "f"); 39 | NUMERIC_LITERALS.put(Float.TYPE, "f"); 40 | NUMERIC_LITERALS.put(Double.class, "d"); 41 | NUMERIC_LITERALS.put(Double.TYPE, "d"); 42 | 43 | NUMERIC_LITERALS.put(BigInteger.class, "d"); 44 | NUMERIC_LITERALS.put(BigDecimal.class, "d"); 45 | } 46 | 47 | String get(Class clazz) { 48 | return NUMERIC_LITERALS.get(clazz); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/util/ContextClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.util; 20 | 21 | import ognl.OgnlContext; 22 | 23 | public class ContextClassLoader extends ClassLoader { 24 | private OgnlContext context; 25 | 26 | /*=================================================================== 27 | Constructors 28 | ===================================================================*/ 29 | public ContextClassLoader(ClassLoader parentClassLoader, OgnlContext context) { 30 | super(parentClassLoader); 31 | this.context = context; 32 | } 33 | 34 | /*=================================================================== 35 | Overridden methods 36 | ===================================================================*/ 37 | protected Class findClass(String name) throws ClassNotFoundException { 38 | if ((context != null) && (context.getClassResolver() != null)) { 39 | return context.getClassResolver().classForName(name, context); 40 | } 41 | return super.findClass(name); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/BaseObjectIndexed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.objects; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | public class BaseObjectIndexed extends Object { 25 | private Map attributes = new HashMap(); 26 | 27 | public BaseObjectIndexed() { 28 | super(); 29 | } 30 | 31 | public Map getAttributes() { 32 | return attributes; 33 | } 34 | 35 | public Object getAttribute(String name) { 36 | return attributes.get(name); 37 | } 38 | 39 | public void setAttribute(String name, Object value) { 40 | attributes.put(name, value); 41 | } 42 | 43 | /* allow testing property name where types do not match */ 44 | public Object getOtherAttribute(String name) { 45 | return null; 46 | } 47 | 48 | public void setOtherAttribute(Object someObject, Object foo) { 49 | /* do nothing */ 50 | } 51 | 52 | 53 | /* test whether get only is found */ 54 | public Object getSecondaryAttribute(Object name) { 55 | return attributes.get(name); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/entry/GenericMethodParameterTypeCacheEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal.entry; 20 | 21 | import java.lang.reflect.Method; 22 | 23 | public class GenericMethodParameterTypeCacheEntry implements CacheEntry { 24 | 25 | final Method method; 26 | final Class type; 27 | 28 | public GenericMethodParameterTypeCacheEntry(Method method, Class type) { 29 | this.method = method; 30 | this.type = type; 31 | } 32 | 33 | @Override 34 | public boolean equals(Object o) { 35 | if (this == o) { 36 | return true; 37 | } 38 | if (!(o instanceof GenericMethodParameterTypeCacheEntry)) { 39 | return false; 40 | } 41 | 42 | GenericMethodParameterTypeCacheEntry that = (GenericMethodParameterTypeCacheEntry) o; 43 | 44 | return method.equals(that.method) && type.equals(that.type); 45 | } 46 | 47 | @Override 48 | public int hashCode() { 49 | int result = method.hashCode(); 50 | result = 31 * result + type.hashCode(); 51 | return result; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/util/NameFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.util; 20 | 21 | public class NameFactory extends Object { 22 | private String classBaseName; 23 | private int classNameCounter = 0; 24 | private String variableBaseName; 25 | private int variableNameCounter = 0; 26 | 27 | /*=================================================================== 28 | Constructors 29 | ===================================================================*/ 30 | public NameFactory(String classBaseName, String variableBaseName) { 31 | super(); 32 | this.classBaseName = classBaseName; 33 | this.variableBaseName = variableBaseName; 34 | } 35 | 36 | /*=================================================================== 37 | Public methods 38 | ===================================================================*/ 39 | public String getNewClassName() { 40 | return classBaseName + classNameCounter++; 41 | } 42 | 43 | public String getNewVariableName() { 44 | return variableBaseName + variableNameCounter++; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTBitNegate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTBitNegate> extends NumericExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = -5446238923267167955L; 27 | 28 | public ASTBitNegate(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTBitNegate(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | return OgnlOps.bitNegate(children[0].getValue(context, source)); 38 | } 39 | 40 | public String toString() { 41 | return "~" + children[0]; 42 | } 43 | 44 | public String toGetSourceString(C context, Object target) { 45 | String source = children[0].toGetSourceString(context, target); 46 | 47 | if (!(children[0] instanceof ASTBitNegate)) { 48 | return "~(" + super.coerceToNumeric(source, context, children[0]) + ")"; 49 | } else { 50 | return "~(" + source + ")"; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTBitAnd.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTBitAnd> extends NumericExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = -2637835347939234142L; 27 | 28 | public ASTBitAnd(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTBitAnd(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | public void jjtClose() { 37 | flattenTree(); 38 | } 39 | 40 | protected Object getValueBody(C context, Object source) throws OgnlException { 41 | Object result = children[0].getValue(context, source); 42 | for (int i = 1; i < children.length; ++i) 43 | result = OgnlOps.binaryAnd(result, children[i].getValue(context, source)); 44 | return result; 45 | } 46 | 47 | public String getExpressionOperator(int index) { 48 | return "&"; 49 | } 50 | 51 | public String coerceToNumeric(String source, C context, Node child) { 52 | return "(long)" + super.coerceToNumeric(source, context, child); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/NullHandlerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.Ognl; 22 | import ognl.OgnlRuntime; 23 | import ognl.test.objects.CorrectedObject; 24 | import org.junit.jupiter.api.BeforeEach; 25 | import org.junit.jupiter.params.ParameterizedTest; 26 | import org.junit.jupiter.params.provider.CsvSource; 27 | 28 | import static org.junit.jupiter.api.Assertions.assertEquals; 29 | 30 | class NullHandlerTest { 31 | 32 | private CorrectedObject root; 33 | 34 | @ParameterizedTest() 35 | @CsvSource({ 36 | "stringValue,corrected", 37 | "getStringValue(),corrected", 38 | "#root.stringValue,corrected", 39 | "#root.getStringValue(),corrected" 40 | }) 41 | void shouldBlockAccessReadToSpecificProperties(String expression, String expected) throws Exception { 42 | assertEquals(expected, Ognl.getValue(expression, root)); 43 | } 44 | 45 | @BeforeEach 46 | public void setUp() { 47 | OgnlRuntime.setNullHandler(CorrectedObject.class, new CorrectedObjectNullHandler("corrected")); 48 | 49 | this.root = new CorrectedObject(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/QuotingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.Ognl; 22 | import ognl.OgnlContext; 23 | import org.junit.jupiter.api.BeforeEach; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals; 27 | 28 | class QuotingTest { 29 | 30 | private OgnlContext context; 31 | 32 | @BeforeEach 33 | void setUp() { 34 | context = Ognl.createDefaultContext(null); 35 | } 36 | 37 | @Test 38 | void testCharacterQuoting() throws Exception { 39 | assertEquals('c', Ognl.getValue("'c'", context, (Object) null)); 40 | assertEquals('s', Ognl.getValue("'s'", context, (Object) null)); 41 | } 42 | 43 | @Test 44 | void testStringQuoting() throws Exception { 45 | assertEquals("string", Ognl.getValue("'string'", context, (Object) null)); 46 | assertEquals("string", Ognl.getValue("\"string\"", context, (Object) null)); 47 | assertEquals("bar", Ognl.getValue("'' + 'bar'", context, (Object) null)); 48 | assertEquals("yyyy年MM月dd日", Ognl.getValue("'yyyy年MM月dd日'", context, (Object) null)); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/SearchTab.java: -------------------------------------------------------------------------------- 1 | package ognl.test.objects; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | /** 8 | * Test for OGNL-131. 9 | */ 10 | public class SearchTab { 11 | 12 | /** 13 | * Flags stating which search criteria are selected 14 | */ 15 | private List> searchCriteriaSelections = new ArrayList>(); 16 | 17 | { 18 | searchCriteriaSelections.add(Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE)); 19 | searchCriteriaSelections.add(Arrays.asList(Boolean.FALSE, Boolean.TRUE, Boolean.TRUE)); 20 | } 21 | 22 | public List> getSearchCriteriaSelections() { 23 | return this.searchCriteriaSelections; 24 | } 25 | 26 | public void setSearchCriteriaSelections(List> selections) { 27 | this.searchCriteriaSelections = selections; 28 | } 29 | 30 | /** 31 | * Filters that can be applied to this tabs searches 32 | */ 33 | private List searchCriteria = new ArrayList(); 34 | 35 | { 36 | searchCriteria.add(new SearchCriteria("Crittery critters")); 37 | searchCriteria.add(new SearchCriteria("Woodland creatures")); 38 | } 39 | 40 | public List getSearchCriteria() { 41 | return this.searchCriteria; 42 | } 43 | 44 | public void setSearchCriteria(List searchCriteria) { 45 | this.searchCriteria = searchCriteria; 46 | } 47 | 48 | /** 49 | * 2D list of options available for each criteria 50 | */ 51 | private List> searchCriteriaOptions = new ArrayList>(); 52 | 53 | public List> getSearchCriteriaOptions() { 54 | return this.searchCriteriaOptions; 55 | } 56 | 57 | public void setSearchCriteriaOptions(List> searchCriteriaOptions) { 58 | 59 | this.searchCriteriaOptions = searchCriteriaOptions; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/ExcludedObjectMemberAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 OGNL Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package ognl; 17 | 18 | import java.lang.reflect.Member; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | /** 24 | * This class provides simple functionality for mark / unmark an object as inaccessible 25 | */ 26 | public class ExcludedObjectMemberAccess extends DefaultMemberAccess { 27 | private final List excludedObjects = new ArrayList<>(); // Any field or method in this list will be inaccessible 28 | 29 | public ExcludedObjectMemberAccess(boolean allowAllAccess) { 30 | super(allowAllAccess); 31 | } 32 | 33 | public ExcludedObjectMemberAccess(boolean allowPrivateAccess, boolean allowProtectedAccess, boolean allowPackageProtectedAccess) { 34 | super(allowPrivateAccess, allowProtectedAccess, allowPackageProtectedAccess); 35 | } 36 | 37 | public boolean isAccessible(OgnlContext context, Object target, Member member, String propertyName) { 38 | if (excludedObjects.contains(member)) { 39 | return false; 40 | } 41 | 42 | return super.isAccessible(context, target, member, propertyName); 43 | } 44 | 45 | public void exclude(Object obj) { 46 | excludedObjects.add(obj); 47 | } 48 | 49 | public void removeExclusion(Object obj) { 50 | excludedObjects.remove(obj); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/NestedMethodTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.Ognl; 22 | import ognl.OgnlContext; 23 | import ognl.test.objects.Component; 24 | import org.junit.jupiter.api.BeforeEach; 25 | import org.junit.jupiter.api.Test; 26 | 27 | import static org.junit.jupiter.api.Assertions.assertEquals; 28 | 29 | class NestedMethodTest { 30 | 31 | private Component component; 32 | private OgnlContext context; 33 | 34 | @BeforeEach 35 | void setUp() { 36 | component = new Component(); 37 | context = Ognl.createDefaultContext(component); 38 | } 39 | 40 | @Test 41 | void testToDisplayPictureUrl() throws Exception { 42 | Object actual = Ognl.getValue("toDisplay.pictureUrl", context, component); 43 | assertEquals(component.getToDisplay().getPictureUrl(), actual); 44 | } 45 | 46 | @Test 47 | void testPageCreateRelativeAsset() throws Exception { 48 | Object actual = Ognl.getValue("page.createRelativeAsset(toDisplay.pictureUrl)", context, component); 49 | assertEquals(component.getPage().createRelativeAsset(component.getToDisplay().getPictureUrl()), actual); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ElementsAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.Enumeration; 22 | 23 | /** 24 | * This interface defines a method for getting the "elements" of an object, which means 25 | * any objects that naturally would be considered to be contained by the object. So for a 26 | * collection, you would expect this method to return all the objects in that collection; 27 | * while for an ordinary object you would expect this method to return just that object. 28 | * 29 | *

An implementation of this interface will often require that its target objects all 30 | * be of some particular type. For example, the MapElementsAccessor class requires that 31 | * its targets all implement the Map interface. 32 | */ 33 | public interface ElementsAccessor { 34 | /** 35 | * Returns an iterator over the elements of the given target object. 36 | * 37 | * @param target the object to get the elements of 38 | * @return an iterator over the elements of the given object 39 | * @throws OgnlException if there is an error getting the given object's elements 40 | */ 41 | Enumeration getElements(Object target) throws OgnlException; 42 | } 43 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/Component.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.objects; 20 | 21 | public class Component extends Object { 22 | private URLStorage toDisplay = new URLStorage(); 23 | private Page page = new Page(); 24 | 25 | public static class URLStorage extends Object { 26 | private String pictureUrl = "http://www.picturespace.com/pictures/100"; 27 | 28 | public String getPictureUrl() { 29 | return pictureUrl; 30 | } 31 | 32 | public void setPictureUrl(String value) { 33 | pictureUrl = value; 34 | } 35 | } 36 | 37 | public static class Page extends Object { 38 | public Object createRelativeAsset(String value) { 39 | return "/toplevel/" + value; 40 | } 41 | } 42 | 43 | public Component() { 44 | super(); 45 | } 46 | 47 | public Page getPage() { 48 | return page; 49 | } 50 | 51 | public void setPage(Page value) { 52 | page = value; 53 | } 54 | 55 | public URLStorage getToDisplay() { 56 | return toDisplay; 57 | } 58 | 59 | public void setToDisplay(URLStorage value) { 60 | toDisplay = value; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/NumericValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.math.BigDecimal; 22 | import java.math.BigInteger; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | /** 27 | * Constant strings for getting the primitive value of different native types on the generic {@link Number} object 28 | * interface. (or the less generic BigDecimal/BigInteger types) 29 | */ 30 | class NumericValues { 31 | 32 | private final Map, String> NUMERIC_VALUES = new HashMap<>(9); 33 | 34 | NumericValues() { 35 | NUMERIC_VALUES.put(Double.class, "doubleValue()"); 36 | NUMERIC_VALUES.put(Float.class, "floatValue()"); 37 | NUMERIC_VALUES.put(Integer.class, "intValue()"); 38 | NUMERIC_VALUES.put(Long.class, "longValue()"); 39 | NUMERIC_VALUES.put(Short.class, "shortValue()"); 40 | NUMERIC_VALUES.put(Byte.class, "byteValue()"); 41 | NUMERIC_VALUES.put(BigDecimal.class, "doubleValue()"); 42 | NUMERIC_VALUES.put(BigInteger.class, "doubleValue()"); 43 | NUMERIC_VALUES.put(Boolean.class, "booleanValue()"); 44 | } 45 | 46 | String get(Class cls) { 47 | return NUMERIC_VALUES.get(cls); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/entry/MethodAccessCacheEntryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal.entry; 20 | 21 | import ognl.internal.CacheException; 22 | 23 | import java.lang.reflect.Method; 24 | import java.lang.reflect.Modifier; 25 | 26 | public class MethodAccessCacheEntryFactory implements CacheEntryFactory { 27 | 28 | public static final MethodAccessEntryValue INACCESSIBLE_NON_PUBLIC_METHOD = new MethodAccessEntryValue(false, true); 29 | 30 | public static final MethodAccessEntryValue ACCESSIBLE_NON_PUBLIC_METHOD = new MethodAccessEntryValue(true, true); 31 | 32 | public static final MethodAccessEntryValue PUBLIC_METHOD = new MethodAccessEntryValue(true); 33 | 34 | public MethodAccessEntryValue create(Method method) throws CacheException { 35 | final boolean notPublic = !Modifier.isPublic(method.getModifiers()) 36 | || !Modifier.isPublic(method.getDeclaringClass().getModifiers()); 37 | if (!notPublic) { 38 | return PUBLIC_METHOD; 39 | } 40 | if (!method.isAccessible()) { 41 | return INACCESSIBLE_NON_PUBLIC_METHOD; 42 | } 43 | return ACCESSIBLE_NON_PUBLIC_METHOD; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /.github/workflows/claude.yml: -------------------------------------------------------------------------------- 1 | name: Claude Code 2 | 3 | on: 4 | issue_comment: 5 | types: [created] 6 | pull_request_review_comment: 7 | types: [created] 8 | issues: 9 | types: [opened, assigned] 10 | pull_request_review: 11 | types: [submitted] 12 | 13 | jobs: 14 | claude: 15 | if: | 16 | (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || 17 | (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || 18 | (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || 19 | (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) 20 | runs-on: ubuntu-latest 21 | permissions: 22 | contents: read 23 | pull-requests: read 24 | issues: read 25 | id-token: write 26 | actions: read # Required for Claude to read CI results on PRs 27 | steps: 28 | - name: Checkout repository 29 | uses: actions/checkout@v6 30 | with: 31 | fetch-depth: 1 32 | 33 | - name: Run Claude Code 34 | id: claude 35 | uses: anthropics/claude-code-action@v1 36 | with: 37 | claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} 38 | 39 | # This is an optional setting that allows Claude to read CI results on PRs 40 | additional_permissions: | 41 | actions: read 42 | 43 | # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it. 44 | # prompt: 'Update the pull request description to include a summary of changes.' 45 | 46 | # Optional: Add claude_args to customize behavior and configuration 47 | # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md 48 | # or https://docs.claude.com/en/docs/claude-code/cli-reference for available options 49 | # claude_args: '--allowed-tools Bash(gh pr:*)' 50 | 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/internal/entry/DeclaredMethodCacheEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.internal.entry; 20 | 21 | public class DeclaredMethodCacheEntry extends MethodCacheEntry { 22 | 23 | MethodType type; 24 | 25 | public enum MethodType { 26 | STATIC, NON_STATIC 27 | } 28 | 29 | public DeclaredMethodCacheEntry(Class targetClass) { 30 | super(targetClass); 31 | } 32 | 33 | public DeclaredMethodCacheEntry(Class targetClass, MethodType type) { 34 | super(targetClass); 35 | this.type = type; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object o) { 40 | if (this == o) { 41 | return true; 42 | } 43 | if (!(o instanceof DeclaredMethodCacheEntry)) { 44 | return false; 45 | } 46 | if (!super.equals(o)) { 47 | return false; 48 | } 49 | 50 | DeclaredMethodCacheEntry that = (DeclaredMethodCacheEntry) o; 51 | 52 | return type == that.type; 53 | 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | int result = super.hashCode(); 59 | result = 31 * result + (type != null ? type.hashCode() : 0); 60 | return result; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/race/RaceTest.java: -------------------------------------------------------------------------------- 1 | package ognl.test.race; 2 | 3 | import ognl.Ognl; 4 | import ognl.OgnlContext; 5 | import ognl.OgnlException; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.util.concurrent.CountDownLatch; 9 | import java.util.concurrent.atomic.AtomicInteger; 10 | 11 | import static org.junit.jupiter.api.Assertions.assertEquals; 12 | 13 | class RaceTest { 14 | 15 | @Test 16 | void testOgnlRace() { 17 | int concurrent = 128; 18 | final int batchCount = 2000; 19 | final CountDownLatch start = new CountDownLatch(1); 20 | final CountDownLatch wait = new CountDownLatch(concurrent); 21 | final AtomicInteger errCount = new AtomicInteger(0); 22 | 23 | final Person person = new Person(); 24 | for (int i = 0; i < concurrent; i++) { 25 | Thread thread = new Thread(() -> { 26 | try { 27 | start.await(); 28 | } catch (InterruptedException e) { 29 | // ignore 30 | } 31 | for (int j = 0; j < batchCount; j++) { 32 | if (j % 2 == 0) { 33 | runValue(person, "yn", errCount); 34 | } else { 35 | runValue(person, "name", errCount); 36 | } 37 | } 38 | wait.countDown(); 39 | }); 40 | thread.setName("work-" + i); 41 | thread.start(); 42 | } 43 | start.countDown(); 44 | try { 45 | wait.await(); 46 | } catch (InterruptedException e) { 47 | // ignore 48 | } 49 | assertEquals(0, errCount.get()); 50 | } 51 | 52 | 53 | private void runValue(Person person, String name, AtomicInteger errCount) { 54 | OgnlContext context = Ognl.createDefaultContext(person); 55 | try { 56 | Ognl.getValue(name, context); 57 | } catch (OgnlException e) { 58 | errCount.incrementAndGet(); 59 | // ignore 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /.github/workflows/claude-code-review.yml: -------------------------------------------------------------------------------- 1 | name: Claude Code Review 2 | 3 | on: 4 | # pull_request: 5 | # types: [ opened, synchronize ] 6 | # Optional: Only run on specific file changes 7 | # paths: 8 | # - "src/**/*.ts" 9 | # - "src/**/*.tsx" 10 | # - "src/**/*.js" 11 | # - "src/**/*.jsx" 12 | workflow_dispatch: 13 | 14 | jobs: 15 | claude-review: 16 | # Skip bot PRs (especially Renovate) to avoid workflow file modification conflicts 17 | if: github.event.pull_request.user.type != 'Bot' 18 | 19 | runs-on: ubuntu-latest 20 | permissions: 21 | contents: read 22 | pull-requests: read 23 | issues: read 24 | id-token: write 25 | 26 | steps: 27 | - name: Checkout repository 28 | uses: actions/checkout@v6 29 | with: 30 | fetch-depth: 1 31 | 32 | - name: Run Claude Code Review 33 | id: claude-review 34 | uses: anthropics/claude-code-action@v1 35 | with: 36 | claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} 37 | prompt: | 38 | REPO: ${{ github.repository }} 39 | PR NUMBER: ${{ github.event.pull_request.number }} 40 | 41 | Please review this pull request and provide feedback on: 42 | - Code quality and best practices 43 | - Potential bugs or issues 44 | - Performance considerations 45 | - Security concerns 46 | - Test coverage 47 | 48 | Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback. 49 | 50 | Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR. 51 | 52 | # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md 53 | # or https://docs.claude.com/en/docs/claude-code/cli-reference for available options 54 | claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"' 55 | 56 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTThisVarRef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import ognl.enhance.UnsupportedCompilationException; 22 | 23 | import java.io.Serial; 24 | 25 | public class ASTThisVarRef> extends ASTVarRef { 26 | 27 | @Serial 28 | private static final long serialVersionUID = -398279289206640857L; 29 | 30 | public ASTThisVarRef(int id) { 31 | super(id); 32 | } 33 | 34 | public ASTThisVarRef(OgnlParser p, int id) { 35 | super(p, id); 36 | } 37 | 38 | protected Object getValueBody(C context, Object source) throws OgnlException { 39 | return context.getCurrentObject(); 40 | } 41 | 42 | protected void setValueBody(C context, Object target, Object value) throws OgnlException { 43 | context.setCurrentObject(value); 44 | } 45 | 46 | public String toString() { 47 | return "#this"; 48 | } 49 | 50 | public String toGetSourceString(C context, Object target) { 51 | throw new UnsupportedCompilationException("Unable to compile this references."); 52 | } 53 | 54 | public String toSetSourceString(C context, Object target) { 55 | throw new UnsupportedCompilationException("Unable to compile this references."); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/accessors/PropertyAccessTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.accessors; 20 | 21 | import ognl.DefaultMemberAccess; 22 | import ognl.Ognl; 23 | import ognl.OgnlContext; 24 | import ognl.OgnlException; 25 | import ognl.OgnlRuntime; 26 | import ognl.test.objects.BeanProvider; 27 | import ognl.test.objects.BeanProviderAccessor; 28 | import ognl.test.objects.EvenOdd; 29 | import ognl.test.objects.Root; 30 | import org.junit.jupiter.api.BeforeEach; 31 | import org.junit.jupiter.api.Test; 32 | 33 | import static org.junit.jupiter.api.Assertions.assertEquals; 34 | 35 | class PropertyAccessTest { 36 | 37 | @BeforeEach 38 | void setUp() { 39 | OgnlRuntime.setPropertyAccessor(BeanProvider.class, new BeanProviderAccessor()); 40 | } 41 | 42 | @Test 43 | void testPropertyAccess() throws OgnlException { 44 | // given 45 | OgnlContext context = Ognl.createDefaultContext(null, new DefaultMemberAccess(false)); 46 | 47 | Root root = new Root(); 48 | root.getBeans().setBean("evenOdd", new EvenOdd()); 49 | 50 | // when 51 | Object result = Ognl.getValue("beans.evenOdd.next", context, root); 52 | 53 | // then 54 | assertEquals("even", result); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/PrimitiveDefaults.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.math.BigDecimal; 22 | import java.math.BigInteger; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | class PrimitiveDefaults { 27 | 28 | private final Map, Object> PRIMITIVE_DEFAULTS = new HashMap, Object>(13); 29 | 30 | PrimitiveDefaults() { 31 | PRIMITIVE_DEFAULTS.put(Boolean.TYPE, Boolean.FALSE); 32 | PRIMITIVE_DEFAULTS.put(Boolean.class, Boolean.FALSE); 33 | PRIMITIVE_DEFAULTS.put(Byte.TYPE, (byte) 0); 34 | PRIMITIVE_DEFAULTS.put(Byte.class, (byte) 0); 35 | PRIMITIVE_DEFAULTS.put(Short.TYPE, (short) 0); 36 | PRIMITIVE_DEFAULTS.put(Short.class, (short) 0); 37 | PRIMITIVE_DEFAULTS.put(Character.TYPE, (char) 0); 38 | PRIMITIVE_DEFAULTS.put(Integer.TYPE, 0); 39 | PRIMITIVE_DEFAULTS.put(Long.TYPE, 0L); 40 | PRIMITIVE_DEFAULTS.put(Float.TYPE, 0.0f); 41 | PRIMITIVE_DEFAULTS.put(Double.TYPE, 0.0); 42 | PRIMITIVE_DEFAULTS.put(BigInteger.class, BigInteger.ZERO); 43 | PRIMITIVE_DEFAULTS.put(BigDecimal.class, BigDecimal.ZERO); 44 | } 45 | 46 | Object get(Class cls) { 47 | return PRIMITIVE_DEFAULTS.get(cls); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/TypeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.lang.reflect.Member; 22 | 23 | /** 24 | * Interface for accessing the type conversion facilities within a context. 25 | */ 26 | public interface TypeConverter> { 27 | /** 28 | * Converts the given value to a given type. The OGNL context, target, member and 29 | * name of property being set are given. This method should be able to handle 30 | * conversion in general without any context, target, member or property name specified. 31 | * 32 | * @param context OGNL context under which the conversion is being done 33 | * @param target target object in which the property is being set 34 | * @param member member (Constructor, Method or Field) being set 35 | * @param propertyName property name being set 36 | * @param value value to be converted 37 | * @param toType type to which value is converted 38 | * @return Converted value of type toType or TypeConverter.NoConversionPossible to indicate that the 39 | * conversion was not possible. 40 | */ 41 | Object convertValue(C context, Object target, Member member, String propertyName, Object value, Class toType); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/NullRootTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.Ognl; 22 | import ognl.OgnlContext; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | import static org.junit.jupiter.api.Assertions.assertNull; 29 | 30 | class NullRootTest { 31 | 32 | @Test 33 | void testNullValue() throws Exception { 34 | OgnlContext context = Ognl.createDefaultContext(null); 35 | Map root = new HashMap<>(); 36 | root.put("key1", null); 37 | String expr = "key1.key2.key3"; 38 | assertNull(Ognl.getValue(expr, context, root)); 39 | } 40 | 41 | @Test 42 | void testEmptyRoot() throws Exception { 43 | OgnlContext context = Ognl.createDefaultContext(null); 44 | Map root = new HashMap<>(); 45 | String expr = "key1.key2.key3"; 46 | assertNull(Ognl.getValue(expr, context, root)); 47 | } 48 | 49 | @Test 50 | void testNullRoot() throws Exception { 51 | OgnlContext context = Ognl.createDefaultContext(null); 52 | Map root = null; 53 | String expr = "key1.key2.key3"; 54 | assertNull(Ognl.getValue(expr, context, root)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/SimpleNavigationChainTreeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.Ognl; 22 | import ognl.OgnlContext; 23 | import org.junit.jupiter.api.BeforeEach; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertFalse; 27 | import static org.junit.jupiter.api.Assertions.assertTrue; 28 | 29 | class SimpleNavigationChainTreeTest { 30 | 31 | private OgnlContext context; 32 | 33 | @BeforeEach 34 | void setUp() { 35 | context = Ognl.createDefaultContext(null); 36 | } 37 | 38 | @Test 39 | void testName() throws Exception { 40 | assertTrue(Ognl.isSimpleNavigationChain(Ognl.parseExpression("name"), context)); 41 | } 42 | 43 | @Test 44 | void testNameWithIndex() throws Exception { 45 | assertFalse(Ognl.isSimpleNavigationChain(Ognl.parseExpression("name[i]"), context)); 46 | } 47 | 48 | @Test 49 | void testNameWithAddition() throws Exception { 50 | assertFalse(Ognl.isSimpleNavigationChain(Ognl.parseExpression("name + foo"), context)); 51 | } 52 | 53 | @Test 54 | void testNameWithProperty() throws Exception { 55 | assertTrue(Ognl.isSimpleNavigationChain(Ognl.parseExpression("name.foo"), context)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/SetPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.util.Set; 22 | 23 | /** 24 | * Implementation of PropertyAccessor that uses numbers and dynamic subscripts as 25 | * properties to index into Lists. 26 | */ 27 | public class SetPropertyAccessor> extends ObjectPropertyAccessor implements PropertyAccessor { 28 | 29 | public Object getProperty(C context, Object target, Object name) throws OgnlException { 30 | Set set = (Set) target; 31 | 32 | if (name instanceof String) { 33 | Object result; 34 | 35 | if (name.equals("size")) { 36 | result = set.size(); 37 | } else { 38 | if (name.equals("iterator")) { 39 | result = set.iterator(); 40 | } else { 41 | if (name.equals("isEmpty")) { 42 | result = set.isEmpty() ? Boolean.TRUE : Boolean.FALSE; 43 | } else { 44 | result = super.getProperty(context, target, name); 45 | } 46 | } 47 | } 48 | return result; 49 | } 50 | 51 | throw new NoSuchPropertyException(target, name); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/objects/Bean2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test.objects; 20 | 21 | public class Bean2 extends Object { 22 | private Bean3 bean3 = new Bean3(); 23 | 24 | private boolean _pageBreakAfter = false; 25 | 26 | public String code = "code"; 27 | 28 | public Long getId() { 29 | return 1l; 30 | } 31 | 32 | public Bean3 getBean3() { 33 | return bean3; 34 | } 35 | 36 | public long getMillis() { 37 | return 1000 * 60 * 2; 38 | } 39 | 40 | public boolean isCarrier() { 41 | return false; 42 | } 43 | 44 | public boolean isPageBreakAfter() { 45 | return _pageBreakAfter; 46 | } 47 | 48 | public void setPageBreakAfter(boolean value) { 49 | _pageBreakAfter = value; 50 | } 51 | 52 | public void togglePageBreakAfter() { 53 | _pageBreakAfter ^= true; 54 | } 55 | 56 | public boolean equals(Object o) { 57 | if (this == o) return true; 58 | if (o == null || getClass() != o.getClass()) return false; 59 | 60 | Bean2 bean2 = (Bean2) o; 61 | 62 | if (_pageBreakAfter != bean2._pageBreakAfter) return false; 63 | 64 | return true; 65 | } 66 | 67 | public int hashCode() { 68 | return (_pageBreakAfter ? 1 : 0); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /ognl/src/main/java/ognl/ASTNot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl; 20 | 21 | import java.io.Serial; 22 | 23 | public class ASTNot> extends BooleanExpression { 24 | 25 | @Serial 26 | private static final long serialVersionUID = 1202881695483879532L; 27 | 28 | public ASTNot(int id) { 29 | super(id); 30 | } 31 | 32 | public ASTNot(OgnlParser p, int id) { 33 | super(p, id); 34 | } 35 | 36 | protected Object getValueBody(C context, Object source) throws OgnlException { 37 | return OgnlOps.booleanValue(children[0].getValue(context, source)) ? Boolean.FALSE : Boolean.TRUE; 38 | } 39 | 40 | public String getExpressionOperator(int index) { 41 | return "!"; 42 | } 43 | 44 | public String toGetSourceString(C context, Object target) { 45 | try { 46 | 47 | String srcString = super.toGetSourceString(context, target); 48 | 49 | if (srcString == null || srcString.trim().isEmpty()) { 50 | srcString = "null"; 51 | } 52 | 53 | context.setCurrentType(Boolean.TYPE); 54 | 55 | return "(! ognl.OgnlOps.booleanValue(" + srcString + ") )"; 56 | 57 | } catch (Throwable t) { 58 | throw OgnlOps.castToRuntime(t); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /.github/workflows/performance.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: JMH Benchmarks 17 | 18 | on: 19 | workflow_dispatch: 20 | push: 21 | branches: 22 | - main 23 | 24 | permissions: read-all 25 | 26 | env: 27 | MAVEN_OPTS: -Xmx2g -Xms1g 28 | LANG: en_US.utf8 29 | 30 | jobs: 31 | build: 32 | runs-on: ubuntu-latest 33 | steps: 34 | - name: Checkout code 35 | uses: actions/checkout@v6.0.1 36 | - name: Set up cache 37 | uses: actions/cache@v5.0.1 38 | with: 39 | path: ~/.m2/repository 40 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 41 | restore-keys: | 42 | ${{ runner.os }}-maven- 43 | - name: Set up JDK 17 44 | uses: actions/setup-java@v5 45 | with: 46 | distribution: temurin 47 | java-version: 17 48 | - name: Build with Maven 49 | run: ./mvnw -B package -DskipTests 50 | - name: Run benchmarks with Maven 51 | env: 52 | OPTIONS: publishSummary 53 | run: | 54 | echo '### Benchmarks summary 🚀' >> $GITHUB_STEP_SUMMARY 55 | ./mvnw -B verify -Pbenchmarks -DskipTests 56 | - name: Upload JMH results 57 | uses: actions/upload-artifact@v6 58 | with: 59 | name: jmh-results 60 | path: benchmarks/target/ognl-runtime-benchmark-results.json 61 | -------------------------------------------------------------------------------- /ognl/src/test/java/ognl/test/InheritedMethodsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package ognl.test; 20 | 21 | import ognl.DefaultMemberAccess; 22 | import ognl.Node; 23 | import ognl.Ognl; 24 | import ognl.OgnlContext; 25 | import ognl.test.objects.BaseBean; 26 | import ognl.test.objects.FirstBean; 27 | import ognl.test.objects.Root; 28 | import ognl.test.objects.SecondBean; 29 | import org.junit.jupiter.api.Test; 30 | 31 | import static org.junit.jupiter.api.Assertions.assertEquals; 32 | 33 | /** 34 | * Tests functionality of casting inherited method expressions. 35 | */ 36 | class InheritedMethodsTest { 37 | 38 | private static final Root ROOT = new Root(); 39 | 40 | @Test 41 | void test_Base_Inheritance() throws Exception { 42 | OgnlContext context = Ognl.createDefaultContext(null, new DefaultMemberAccess(false)); 43 | String expression = "map.bean.name"; 44 | BaseBean first = new FirstBean(); 45 | BaseBean second = new SecondBean(); 46 | 47 | ROOT.getMap().put("bean", first); 48 | 49 | Node node = Ognl.compileExpression(context, ROOT, expression); 50 | 51 | assertEquals(first.getName(), node.getAccessor().get(context, ROOT)); 52 | 53 | ROOT.getMap().put("bean", second); 54 | 55 | assertEquals(second.getName(), node.getAccessor().get(context, ROOT)); 56 | } 57 | } 58 | --------------------------------------------------------------------------------