Skip to content

Class reference is failed when include 'or' at a package name #103

@kazuki43zoo

Description

@kazuki43zoo

If package name includes "or" (e.g. "jp.or.example"), the Ognl#parseExpression(String) is failed as follow:

  • Code
    public void test_class_reference()
        throws Throwable
    {
        OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null, new DefaultMemberAccess(false));
        {
            Node expr = (Node) Ognl.parseExpression("@java.util.UUID@randomUUID()"); // It's OK
            Object v = expr.getValue(context, null);
            System.out.println(v);
        }
        {
            Node expr = (Node) Ognl.parseExpression("@jp.or.example.IdUtils@generateId()"); // It's failed on parsing phase
            Object v = expr.getValue(context, null);
            System.out.println(v);
        }
    }
  • Stack Trace
ognl.ExpressionSyntaxException: Malformed OGNL expression: @jp.or.example.IdUtils@generateId()
 [ognl.ParseException: Encountered " "or" "or "" at line 1, column 5.
Was expecting:
    <IDENT> ...
    ]
	at ognl.Ognl.parseExpression(Ognl.java:179)
	at org.ognl.test.enhance.TestExpressionCompiler.test_class_reference(TestExpressionCompiler.java:55)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at junit.framework.TestCase.runTest(TestCase.java:176)
	at junit.framework.TestCase.runBare(TestCase.java:141)
	at junit.framework.TestResult$1.protect(TestResult.java:122)
	at junit.framework.TestResult.runProtected(TestResult.java:142)
	at junit.framework.TestResult.run(TestResult.java:125)
	at junit.framework.TestCase.run(TestCase.java:129)
	at junit.framework.TestSuite.runTest(TestSuite.java:252)
	at junit.framework.TestSuite.run(TestSuite.java:247)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: ognl.ParseException: Encountered " "or" "or "" at line 1, column 5.
Was expecting:
    <IDENT> ...
    
	at ognl.OgnlParser.generateParseException(OgnlParser.java:3232)
	at ognl.OgnlParser.jj_consume_token(OgnlParser.java:3098)
	at ognl.OgnlParser.className(OgnlParser.java:1822)
	at ognl.OgnlParser.classReference(OgnlParser.java:1795)
	at ognl.OgnlParser.staticReference(OgnlParser.java:1762)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions