Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use a Class located in default package in OGNL expressions #1768

Closed
jan-krakora opened this issue Dec 4, 2019 · 2 comments
Closed
Assignees
Labels
bug on dependency library Indicates a bug on dependency library
Milestone

Comments

@jan-krakora
Copy link

MyBatis version

3.5.3

Steps to reproduce

Create a class Ognl in default (root) package with a public static method
public static boolean test(Object o) { return true; }

then use it in an OGNL expression in an mapper like
<if test="@Ognl@test(myParam)">...</if>

Expected result

Application should not fail

Actual result

Application crashes with stack trace:

...
Caused by: java.lang.ClassNotFoundException: Cannot find class: java.lang.Ognl
	at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:200)
	at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89)
	at org.apache.ibatis.io.Resources.classForName(Resources.java:261)
	at org.apache.ibatis.scripting.xmltags.OgnlClassResolver.toClassForName(OgnlClassResolver.java:34)
	at org.apache.ibatis.ognl.DefaultClassResolver.classForName(DefaultClassResolver.java:58)
	at org.apache.ibatis.ognl.OgnlRuntime.classForName(OgnlRuntime.java:1167)
	at org.apache.ibatis.ognl.OgnlRuntime.callStaticMethod(OgnlRuntime.java:1545)

See org.apache.ibatis.ognl.DefaultClassResolver

Any class that is searched and its className is without '.' is always prefixed with 'java.lang.'. This behavior was not in MyBatis 3.4.6.

@harawata
Copy link
Member

harawata commented Dec 5, 2019

Thank you for the report, @jan-krakora ,

You really should avoid using the default package.
Still, OGNL probably should handle it properly, so I have sent a PR to OGNL [1].

[1] MyBatis simply includes OGNL source using maven shade plugin.

@harawata harawata added the bug on dependency library Indicates a bug on dependency library label Dec 23, 2019
@harawata harawata added this to the 3.5.4 milestone Dec 23, 2019
@harawata harawata self-assigned this Dec 23, 2019
@harawata
Copy link
Member

This should be fixed in the latest 3.5.4 SNAPSHOT.
Please let us know if there is any issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug on dependency library Indicates a bug on dependency library
Projects
None yet
Development

No branches or pull requests

2 participants