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

IllegalAccessException: reopen the issue #453 #734

Closed
Toshibam opened this issue Jan 4, 2019 · 0 comments
Closed

IllegalAccessException: reopen the issue #453 #734

Toshibam opened this issue Jan 4, 2019 · 0 comments

Comments

@Toshibam
Copy link

Toshibam commented Jan 4, 2019

Whats your runtime?

  • Dozer version: 6.4.1
  • OS version: Windows 10
  • JDK version: 1.8

Whats the problem?

updated from version 5.5.1 to 6.4.1, existing unit tests failed.
Same error as issue #453:
IllegalAccessException: Can not set static final long field xxx.serialVersionUID to java.lang.Long

the class is auto-generated by JAXB via .xsd with serialVersionUID = 1L

@garethahealy I tried with a simple test, the problem seems because of "final".
I can of course use your work-around to add field-exclude for the serialVersionUID. But I'm afraid other unkonw fields have same issue, I cannot always use work-around in the mapping.xml file.
Could you fix this by checking if the destinational filed is "final"?
Thanks

Observed Results:

17:41:39.876 [main] ERROR - c.g.d.core.MappingProcessor : Field mapping error -->
MapId: null
Type: null
Source parent class: my_package.v1.MyClass
Source field name: serialVersionUID
Source field type: class java.lang.Long
Source field value: 1
Dest parent class: my_package.MyClass
Dest field name: serialVersionUID
Dest field type: long
com.github.dozermapper.core.MappingException: java.lang.IllegalAccessException: Can not set static final long field my_package.MyClass.serialVersionUID to java.lang.Long
at com.github.dozermapper.core.util.MappingUtils.throwMappingException(MappingUtils.java:78)
at com.github.dozermapper.core.propertydescriptor.FieldPropertyDescriptor$ChainedPropertyDescriptor.setPropertyValue(FieldPropertyDescriptor.java:144)
at com.github.dozermapper.core.propertydescriptor.FieldPropertyDescriptor.setPropertyValue(FieldPropertyDescriptor.java:88)
at com.github.dozermapper.core.fieldmap.FieldMap.writeDestValue(FieldMap.java:99)
at com.github.dozermapper.core.MappingProcessor.writeDestinationValue(MappingProcessor.java:1001)
at com.github.dozermapper.core.MappingProcessor.mapFromFieldMap(MappingProcessor.java:412)
at com.github.dozermapper.core.MappingProcessor.mapField(MappingProcessor.java:355)
at com.github.dozermapper.core.MappingProcessor.map(MappingProcessor.java:315)
at com.github.dozermapper.core.MappingProcessor.mapToDestObject(MappingProcessor.java:264)
at com.github.dozermapper.core.MappingProcessor.createByCreationDirectiveAndMap(MappingProcessor.java:237)
at com.github.dozermapper.core.MappingProcessor.mapCustomObject(MappingProcessor.java:576)
at com.github.dozermapper.core.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:513)
at com.github.dozermapper.core.MappingProcessor.addOrUpdateToList(MappingProcessor.java:882)
at com.github.dozermapper.core.MappingProcessor.addOrUpdateToList(MappingProcessor.java:956)
at com.github.dozermapper.core.MappingProcessor.mapListToList(MappingProcessor.java:792)
at com.github.dozermapper.core.MappingProcessor.mapCollection(MappingProcessor.java:642)
at com.github.dozermapper.core.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:501)
at com.github.dozermapper.core.MappingProcessor.mapFromFieldMap(MappingProcessor.java:405)
at com.github.dozermapper.core.MappingProcessor.mapField(MappingProcessor.java:355)
at com.github.dozermapper.core.MappingProcessor.map(MappingProcessor.java:315)
at com.github.dozermapper.core.MappingProcessor.mapToDestObject(MappingProcessor.java:264)
at com.github.dozermapper.core.MappingProcessor.createByCreationDirectiveAndMap(MappingProcessor.java:237)
at com.github.dozermapper.core.MappingProcessor.mapGeneral(MappingProcessor.java:210)
at com.github.dozermapper.core.MappingProcessor.map(MappingProcessor.java:133)
at com.github.dozermapper.core.MappingProcessor.map(MappingProcessor.java:128)
at com.github.dozermapper.core.DozerBeanMapper.map(DozerBeanMapper.java:129)
at my_package.MyClass.ClassToBeTested.methedToBeTested(ClassToBeTested.java:24)
at my_package.MyClass.ClassTest.testmethedToBeTested(ClassTest.java:67)
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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
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.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.IllegalAccessException: Can not set static final long field my_package.MyClass.serialVersionUID to java.lang.Long
at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:76)
at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:80)
at sun.reflect.UnsafeQualifiedStaticLongFieldAccessorImpl.set(UnsafeQualifiedStaticLongFieldAccessorImpl.java:77)
at java.lang.reflect.Field.set(Field.java:764)
at com.github.dozermapper.core.propertydescriptor.FieldPropertyDescriptor$ChainedPropertyDescriptor.setPropertyValue(FieldPropertyDescriptor.java:141)
... 49 common frames omitted

Expected Results:

with old version 5.5.1, no such issue.

Link to GitHub repo with Unit test

_ with 6.5.0-SNAPSHOT, add one test case in FieldPropertyDescriptorTest, and change a bit the class "Container":
public static class Container implements Serializable {
private final static long serialVersionUID = 1L;
....
}
@test(expected = IllegalAccessException.class)
public void setPropertyValue_serialVersionUID() {
// Arrange
String filedName = "serialVersionUID";
FieldPropertyDescriptor descriptor = new FieldPropertyDescriptor(
Container.class, filedName, false, 0, null, null, destBeanCreator);
Container destination = new Container();

// Act
descriptor.setPropertyValue(destination, 1L, mock(FieldMap.class));

}

@Toshibam Toshibam changed the title Reopen the issue 453 IllegalAccessException: Reopen the issue #453 Jan 4, 2019
@Toshibam Toshibam changed the title IllegalAccessException: Reopen the issue #453 IllegalAccessException: reopen the issue #453 Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants