The new support for default methods is not working for mapper with package modifiers,
I have a sample case in a fork here,
https://github.com/mchiareli/mybatis-3
I just changed the modifier of the mapper used to test the default methods, and the test breaks.
Comment From: kazuki43zoo
Hi @harawata ,
I've added PACKAGE
and PUBLIC
as allowed modes as follow:
return constructor.newInstance(declaringClass,
(MethodHandles.Lookup.PRIVATE | MethodHandles.Lookup.PACKAGE | MethodHandles.Lookup.PUBLIC))
.unreflectSpecial(method, declaringClass).bindTo(proxy).invokeWithArguments(args);
It's work fine. This solution is good or bad ?
Comment From: harawata
@mchiareli ,
Thank you for taking the time to report. It would be great if you could try the latest 3.4.3-SNAPSHOT with your solution.
@kazuki43zoo , Just committed a similar fix and the tests are passing, so it should be OK. =)
For future reference, it throws an exception like this in 3.4.2.
java.lang.reflect.UndeclaredThrowableException
at org.apache.ibatis.submitted.usesjava8.default_method.$Proxy6.defaultGetUser(Unknown Source)
at org.apache.ibatis.submitted.usesjava8.default_method.DefaultMethodTest.shouldInvokeDefaultMethodOfPackagePrivateMapper(DefaultMethodTest.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalAccessException: class is not public: org.apache.ibatis.submitted.usesjava8.default_method.PackageMapper.defaultGetUser(Object[])User/invokeSpecial, from org.apache.ibatis.submitted.usesjava8.default_method.PackageMapper/2
at java.lang.invoke.MemberName.makeAccessException(MemberName.java:852)
at java.lang.invoke.MethodHandles$Lookup.checkAccess(MethodHandles.java:1532)
at java.lang.invoke.MethodHandles$Lookup.checkMethod(MethodHandles.java:1470)
at java.lang.invoke.MethodHandles$Lookup.getDirectMethodCommon(MethodHandles.java:1619)
at java.lang.invoke.MethodHandles$Lookup.getDirectMethodNoSecurityManager(MethodHandles.java:1613)
at java.lang.invoke.MethodHandles$Lookup.unreflectSpecial(MethodHandles.java:1232)
at org.apache.ibatis.binding.MapperProxy.invokeDefaultMethod(MapperProxy.java:83)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
... 26 more
Comment From: mchiareli
@harawata i tried with my app, and everything worked fine with the snapshot. any idea when you releasing it?
Thanks for the quick support.
Comment From: harawata
@mchiareli , Thank you for verifying the fix!
any idea when you releasing it?
It might take a while as 3.4.2 was released just a few weeks ago. I am sorry for the inconvenience!
Comment From: srinivas453
Hi All,
I am getting "org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)" error when I use default methods in mapper interfaces. I am using MyBatis 3.5.4 with EJB 3.1 in WebSphere 8.5.5.16 & Java 8.
Any suggestion and/or help is greatly appreciated
Thank you.