Skip to content

Commit 338fc94

Browse files
authored
Merge pull request #1217 from kazuki43zoo/gh-1211_upgrade-to-ognl-3.2
Upgrade to ognl 3.2.x #1211
2 parents 8e80c18 + 43f7cec commit 338fc94

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
<dependency>
153153
<groupId>ognl</groupId>
154154
<artifactId>ognl</artifactId>
155-
<version>3.1.16</version> <!-- Keep to use 3.1.x because 3.2.2+ occurred a RuntimeException on OgnlContext -->
155+
<version>3.2.6</version>
156156
<scope>compile</scope>
157157
<optional>true</optional>
158158
</dependency>

src/main/java/org/apache/ibatis/scripting/xmltags/OgnlCache.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
*/
3333
public final class OgnlCache {
3434

35+
private static final OgnlMemberAccess MEMBER_ACCESS = new OgnlMemberAccess();
3536
private static final Map<String, Object> expressionCache = new ConcurrentHashMap<String, Object>();
3637

3738
private OgnlCache() {
@@ -40,7 +41,7 @@ private OgnlCache() {
4041

4142
public static Object getValue(String expression, Object root) {
4243
try {
43-
Map<Object, OgnlClassResolver> context = Ognl.createDefaultContext(root, new OgnlClassResolver());
44+
Map context = Ognl.createDefaultContext(root, MEMBER_ACCESS, new OgnlClassResolver(), null);
4445
return Ognl.getValue(parseExpression(expression), context, root);
4546
} catch (OgnlException e) {
4647
throw new BuilderException("Error evaluating expression '" + expression + "'. Cause: " + e, e);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright 2009-2018 the original author or authors.
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 org.apache.ibatis.scripting.xmltags;
17+
18+
import ognl.MemberAccess;
19+
20+
import java.lang.reflect.AccessibleObject;
21+
import java.lang.reflect.Member;
22+
import java.lang.reflect.Modifier;
23+
import java.util.Map;
24+
25+
/**
26+
* The {@link MemberAccess} class that based on <a href=
27+
* 'https://github.com/jkuhnert/ognl/blob/OGNL_3_2_1/src/java/ognl/DefaultMemberAccess.java'>DefaultMemberAccess</a>.
28+
*
29+
* @author Kazuki Shimizu
30+
* @since 3.5.0
31+
*
32+
* @see <a href=
33+
* 'https://github.com/jkuhnert/ognl/blob/OGNL_3_2_1/src/java/ognl/DefaultMemberAccess.java'>DefaultMemberAccess</a>
34+
* @see <a href='https://github.com/jkuhnert/ognl/issues/47'>#47 of ognl</a>
35+
*/
36+
class OgnlMemberAccess implements MemberAccess {
37+
38+
@Override
39+
public Object setup(Map context, Object target, Member member, String propertyName) {
40+
Object result = null;
41+
if (isAccessible(context, target, member, propertyName)) {
42+
AccessibleObject accessible = (AccessibleObject) member;
43+
if (!accessible.isAccessible()) {
44+
result = Boolean.FALSE;
45+
accessible.setAccessible(true);
46+
}
47+
}
48+
return result;
49+
}
50+
51+
@Override
52+
public void restore(Map context, Object target, Member member, String propertyName,
53+
Object state) {
54+
if (state != null) {
55+
((AccessibleObject) member).setAccessible(((Boolean) state));
56+
}
57+
}
58+
59+
@Override
60+
public boolean isAccessible(Map context, Object target, Member member, String propertyName) {
61+
return Modifier.isPublic(member.getModifiers());
62+
}
63+
64+
}

0 commit comments

Comments
 (0)