-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Getting "NoSuchPropertyException" Randomly #623
Comments
Unfortunately that was fixed by upgrading OGNL but I am afraid we already are in the latest version. I would suggest trying to isolate the case and pass it to the OGNL project. |
Thanks for your reply @emacarron. I'm sorry that did you mean this case had been fixed in mybatis-3.3.1? Is this the problem of OGNL project like that in #199 ? |
Yes. Looks like a OGNL problem but we already are in the latest version. BTW, ognl repo is here, maybe Lukasz knows what to do, please open an issue there. |
3.0.11 isn't the latest OGNL version, maybe you should try to upgrade to the latest one to fix this issue. |
@infear-on-the-way , MyBatis 3.3.0 includes OGNL 3.0.11 And...thanks for the comment, @lukaszlenart :-) |
Thanks for your apply @lukaszlenart @harawata . I will try to upgrade MyBatis to 3.3.1, but could you help to tell the cause of the problem and the difference between these two versions? |
Here you have the whole list of changes to OGNL 3.1.2 https://github.com/jkuhnert/ognl#release-notes---version-312 and probably your issue is related to this https://issues.apache.org/jira/browse/OGNL-252 |
Thank you @lukaszlenart ! @infear-on-the-way did you have a chance to check newer MyBatis versions? Can we close this issue? |
I have the same issue with MyBatis 3.4.0, using Spring 4.3.0.RELEASE and MyBatis-Spring 1.3.0. On server start, the first requests fails; but execute correctly the same requests after. The property name change randomly. The properties, of course, exists in the object. Stacktrace:
|
Hi @rwtq2ksw , Thanks for the info.
This implies that the problem involves race condition. |
Yes, all properties have public getter methods. |
Thank you for trying, @rwtq2ksw ! I am trying to figure out what happens by reading the code, but it is tricky and I want to narrow down the possibilities a little bit... 😕 |
@infear-on-the-way @rwtq2ksw , This could happen if the getter method generates a synthetic method, in theory. That exception is thrown if this line is executed. OgnlRuntime#getGetMethod() could return null when multiple threads reach this line simultaneously. And OgnlRuntime#getReadMethod() could return null when the getter generates a synthetic (a.k.a. bridge) method [1]. [1] It basically means that the method has a different return type than its super class or interface. public interface HasId<T> {
public T getId();
}
public class Person implements HasId<Integer> {
public Integer getId() {
return id;
}
// ...
} public class Parent {
private Number id;
public Number getId() {
return id;
}
}
public class Child extends Parent {
public Integer getId() {
return id;
}
// ...
} |
@harawata, No, sorry, I don't have getter methods override methods of super class/interface. I have a super class, but not override methods. I tried to debug the Ognl class used in OgnlCache, but I can't access to the source. Eclipse says: Source not found. The OgnlCache.java shows correctly (and Mybatis classes), but Ognl classes no. I'm using Maven to include mybatis. org.mybatis mybatis 3.4.0 |
Hm...OK. To narrow down the possibilities, could you execute the following test case and see if it passes? @Test
public void testReadMethod() throws Exception {
assertNotNull(OgnlRuntime.getReadMethod(EventViewDto.class, "dialAux", null));
} Please make sure to use the same Java version as your server that is experiencing the problem.
Try disabling 'Resolve dependencies from Workspace projects' in the Project Properties -> Maven and then right-click the project -> Maven -> Download Sources. Thank you for your time! |
Hi @harawata , Has this issue been fixed? I got this problem in Mybatis 3.4.1, and the Java version is I am using is 1.8.0_11. Any suggestion to resolve this problem? |
Hi @dannyliiii If your problem is the one that I have found, it should be fixed by upgrading to Java version 1.8.0_25 or later (1.8.0_101 is the latest). If it didn't help, we need your help.
|
Thanks @harawata My problem seems gone after updating Java to 1.8.0_101. If it happens again in the future I will test it and let you know. |
Good! Thanks for the info, @dannyliiii ! |
Hi @infear-on-the-way @rwtq2ksw, Can you resolve this issue via upgrading JDK version ? |
Same error on 1.8.0_40 and 1.8.0_112 when using the demo app apove on MacOS. |
Hi @arebya , I have tested the demo app on 1.8.0_40 many times, but could not reproduce the error. |
I am sorry, but I have no idea how it reproduces on your environment. |
I think I have found the cause of this exception. My Mybatis's version is 3.3.1, and I had this problem too. I see the ognl source, in OgnlRuntime.java:
When one thread of mapper called first time, there is not method in the cacheGetMethod instance(1939 line), if this thread runs to 1944 line, another thread of the same mapper called this line too, then one of this two threads runs to 1950 line , another thread cacheGetMethod.containsKey(targetClass, propertyName) will returns null. Then this Exception occurs. I am sorry to my english is very poor. But I hope my discovery is usefull to anybody! |
I add a interceptor of mybatis to fix this problem. when the NoSuchPropertyException occurs, I retry once. |
@salten , Please see my comments above #623 (comment) , #623 (comment) If you got this exception with the recent version of Java 8, please investigate why getReadMethod() returns null. @Test
public void testReadMethod() throws Exception {
assertNotNull(OgnlRuntime.getReadMethod(EventViewDto.class, "dialAux", null));
} @arebya , |
@harawata
And I add a breakpront at line 1944: if (cacheGetMethod.containsKey(targetClass, propertyName)) {
when the two threads broke at the breakpoint at line 1944, I let one thread run to the line 1950, then let the two threads go on running, then the result of one thread will null。 There is no relation to the version of jdk, I think. The problem is the method 'getGetMethod' in the OgnlRuntime class in not thread-safed(synchronized). |
You did not read my comments... 😔 getGetMethod() is called from getMethodValue() public static final Object getMethodValue(OgnlContext context, Object target, String propertyName, boolean checkAccessAndExistence) throws OgnlException, IllegalAccessException, NoSuchMethodException, IntrospectionException
{
Object result = null;
Method m = getGetMethod(context, (target == null) ? null : target.getClass() , propertyName);
if (m == null)
m = getReadMethod((target == null) ? null : target.getClass(), propertyName, null);
... As you can see, even if getGetMethod() returned null, NoSuchPropertyException is not thrown if getReadMethod() returned non-null value. |
I will close this issue because this is clearly an OGNL issue (stack trace shows MyBatis passes the right parameters to OGNL) and this thread got too long to read. |
@harawata
The getReadMethod is :m = getReadMethod((target == null) ? null : target.getClass(), propertyName, 0);
And the method "getReadMethod" is always return null.......
Maybe your source version is different to mine...... |
@salten , Thank you for the follow-up! MyBatis 3.3.1 (and 3.4.0) includes OGNL 3.1.2. In your case, upgrading MyBatis to 3.4.2 may fix the problem because this problem does not exist in the included OGNL [1] even though the race condition in getGetMethod() still exists. [1] Note that there still is another getReadMethod() issue with synthetic methods which causes the same exception on Java 6 and 7. p.s. |
@harawata |
You are really genius! |
very good,i have this problem too |
I also run into it... |
@salten |
Hi,
We are using mybatis-3.3.0. Recently we got one strange error from mybatis code while executing a query that gets executed successfully many times during the day, but failed several times.
Below is the stacktrace:
Any help to find root cause of above error will be greatly appreciated.
Ps. We have met a similar problem(#199) when using mybatis-3.1.0, which has fixed in mybatis-3.3.0. Is this the same cause?
MyBatis version
3.3.1
Database vendor and version
Test case or example project
Steps to reproduce
Expected result
Actual result
The text was updated successfully, but these errors were encountered: