Skip to content

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