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

Bug if the @Id field is private but has a public getter #192

Open
wants to merge 4 commits into
base: development
Choose a base branch
from

Conversation

pfichtner
Copy link

When having a private @id annotated field that has an public getter spring-data-mock fails with

com.mmnaseri.utils.spring.data.error.DataOperationExecutionException: Method call resulted in internal error: public java.lang.Object com.mmnaseri.utils.spring.data.repository.CrudRepositorySupport.save(java.lang.Object)
        at com.mmnaseri.utils.spring.data.domain.impl.MethodInvocationDataStoreOperation.execute(MethodInvocationDataStoreOperation.java:43)
        at com.mmnaseri.utils.spring.data.proxy.impl.DataOperationInvocationHandler.invoke(DataOperationInvocationHandler.java:92)
        at com.sun.proxy.$Proxy4.save(Unknown Source)
        at com.mmnaseri.utils.spring.data.dsl.factory.RepositoryFactoryBuilderTest.privateIdFieldIssue(RepositoryFactoryBuilderTest.java:485)
Caused by: java.lang.IllegalStateException: Failed to set property value through the field private java.lang.Long com.mmnaseri.utils.spring.data.dsl.factory.RepositoryFactoryBuilderTest$EntityWithAnnotatedIdFieldAndGetter.id
        at com.mmnaseri.utils.spring.data.tools.PropertyUtils.setPropertyValue(PropertyUtils.java:162)
        at com.mmnaseri.utils.spring.data.repository.CrudRepositorySupport.save(CrudRepositorySupport.java:51)
        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 com.mmnaseri.utils.spring.data.domain.impl.MethodInvocationDataStoreOperation.execute(MethodInvocationDataStoreOperation.java:38)
        ... 40 more

This is because

only checks if the field is not final when changing it to be accessible. The code also should check if the field is private.

Testcase showing the problem added, please move the code as desired.

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

Successfully merging this pull request may close these issues.

1 participant