Default methods support on mappers, does not work for non-public mappers. #905

Closed
mchiareli opened this Issue Jan 25, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@mchiareli

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.

@harawata harawata added the bug label Jan 25, 2017

@harawata harawata self-assigned this Jan 25, 2017

@harawata harawata added this to the 3.4.3 milestone Jan 25, 2017

@kazuki43zoo

This comment has been minimized.

Show comment
Hide comment
@kazuki43zoo

kazuki43zoo Jan 25, 2017

Member

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 ?

Member

kazuki43zoo commented Jan 25, 2017

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 ?

@harawata harawata closed this in 1fe27a1 Jan 25, 2017

@harawata

This comment has been minimized.

Show comment
Hide comment
@harawata

harawata Jan 25, 2017

Member

@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

Member

harawata commented Jan 25, 2017

@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

@mchiareli

This comment has been minimized.

Show comment
Hide comment
@mchiareli

mchiareli Jan 25, 2017

@harawata i tried with my app, and everything worked fine with the snapshot. any idea when you releasing it?

Thanks for the quick support.

@harawata i tried with my app, and everything worked fine with the snapshot. any idea when you releasing it?

Thanks for the quick support.

@harawata

This comment has been minimized.

Show comment
Hide comment
@harawata

harawata Jan 27, 2017

Member

@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!

Member

harawata commented Jan 27, 2017

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment