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: Can not set static final long field xxx.serialVersionUID to java.lang.Long #453

Closed
detollenaere opened this issue Jul 28, 2017 · 13 comments

Comments

@detollenaere
Copy link

detollenaere commented Jul 28, 2017

Whats your runtime?

  • Dozer version: 6.0.0
  • OS version: windows 8
  • JDK version: 1.8

Whats the problem?

I tried to migrate dozer version in a project from 5.5.1 to 6.0.0 and I have an error. Here is my case:

packageA:

Interface IA extend Serializable
{
[...]
}


Class ExampleA implement IA 
{
	private static final long serialVersionUID = 1L;
	
	[...]
}


Class Source 
{
	private IA field;
	
	public IA getField()
	{
		return field;
	}

	public void setField(IAfield)
	{
		this.field = field;
	}
}

packageB:

Interface IB extend Serializable
{
[...]
}


Class ExampleB implement IB 
{
	private static final long serialVersionUID = 1L;
	
	[...]
}

Class Destination 
{
	private IA field;
	
	public IB getField()
	{
		return field;
	}

	public void setField(IB field)
	{
		this.field = field;
	}
}

dozer config:

<mapping>
	<class-a>extensionOfSource
	</class-a>
	<class-b>extensionOfDestination
	</class-b>
	<field>
		<a>field</a>
		<b>field</b>
		<a-hint>ExampleA</a-hint>
		<b-hint>ExampleB</b-hint>
	</field>
</mapping>

In runtime, I have the following error:

Source parent class: packageA.ExampleA
Source field name: serialVersionUID
Source field type: class java.lang.Long
Source field value: 4925595665648744886
Dest parent class: packageB.ExampleB
Dest field name: serialVersionUID
Dest field type: long: org.dozer.MappingException: java.lang.IllegalAccessException: Can not set static final long field packageB.ExampleB.serialVersionUID to java.lang.Long

Any ideas ? Bug or we need to migrate/correct a configuration ?

@garethahealy
Copy link
Collaborator

@detollenaere ; why are you trying to set serialVersionUID? you typically would not do that.

https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html

@detollenaere
Copy link
Author

@garethahealy : I just migrate the dependencies, so I don' have a complete view on why this structure has been choosen but It's not a problem for me to declare a serialVersionUID into a class and there is no setter for this field.
This field is not explicitly declared into dozer xml mapping file.
It seems that fields "serialVersionUID " were ignored with previous version (5.5.1) but are take into account in version 6.0.0.

@garethahealy
Copy link
Collaborator

@detollenaere ; OK, can you create a github repo with an example class/mapping and unit test please. Makes debugging/fixing the issue so much easier.

@garethahealy
Copy link
Collaborator

@detollenaere ; just as a quick work-around. Can you exclude the serialVersionUID?

@detollenaere
Copy link
Author

ok Il wil check that as soon as possible (I have to work on another topic since). Thanks for you quick reply

@garethahealy
Copy link
Collaborator

@detollenaere ; have added a test for this, but i don't see the issue. I think its the same as you've described.

@garethahealy
Copy link
Collaborator

@detollenaere ; any update?

@detollenaere
Copy link
Author

@garethahealy Thanks for the test! I confess that I had not much time to add one myself. I am very busy at the moment but I will check this week! (I'm cloning the git as I write this). Thanks again.

@detollenaere
Copy link
Author

@garethahealy I just made a few modifications on your testcase to match exactly my case but I did not reproduce the bug.. I think so it's due to a specific configuration on my project. For now, we simply use the last 5.x version as workaround. When I'll get more time I'll try to isolate each parts of the project (it's a big project..) to find the cause.

@garethahealy
Copy link
Collaborator

@detollenaere ; thanks for the update.

@garethahealy
Copy link
Collaborator

@detollenaere ; closing case. when you get time, if you hit problem again, please re-open.

@Toshibam
Copy link

Toshibam commented Jan 3, 2019

@garethahealy
Hi,
I met the same error message when I update the version from 5.5.1 to 6.4.1
the class has serialVersionUID, because the class is auto-generated by JAXB via .xsd

I can use your suggested work-around to exclude the serialVersionUID.
But I still doubt, 6.4.1 has bug which may fail to map single field (without setter/getter). I will try to write more unit tests to check if such doubt happens.

Please notice the error message: ".. cannot set ... long to ... Long," maybe you can find something with this hint.

Thanks

@Toshibam
Copy link

Toshibam commented Jan 3, 2019

@garethahealy

It seems for simple mapping like your above test, no such error.

my code, the mapping is a bit complex. The error happens in one class which is inside the mapping class.
I will attach more details tomorrow.

talk to you later.

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

3 participants