Bug 57294 - Ignore serialVersionUID hiding another field
Summary: Ignore serialVersionUID hiding another field
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: 3.0 M9   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-02 14:33 EST by Andriy Rozeluk CLA
Modified: 2013-11-15 10:23 EST (History)
1 user (show)

See Also:


Attachments
ignore serialization fields during fieldHiding (1.23 KB, patch)
2004-04-05 23:06 EDT, Michael Fraenkel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andriy Rozeluk CLA 2004-04-02 14:33:52 EST
When I enabled the compiler warning Advanced -> Field declaration hides another
field or variable, I get the warning:

The field Two.serialVersionUID is hiding a field from type One.

This is pretty simple to reproduce:
public class One implements Serializable{
  static final long serialVersionUID = 1234567890L;
}

public class Two extends One{
  static final long serialVersionUID = 987654321L;
}

I'd suggest that serialVersionUID should be ignored for this set of warnings.
Comment 1 Philipe Mulet CLA 2004-04-05 18:57:21 EDT
I agree. We already treat it special when flagging unused private members.
Comment 2 Michael Fraenkel CLA 2004-04-05 23:06:52 EDT
Created attachment 9237 [details]
ignore serialization fields during fieldHiding

This checks for the serialVersionUID and serialPersistentFields.
Does it matter that there is no check to see if the class implements
java.io.Serializable?
Comment 3 Andriy Rozeluk CLA 2004-04-06 08:11:51 EDT
It doesn't particularly matter to me if it checks that the class implements
java.io.Serializable. As far as I know it's legal (though silly/useless) to
define serialVersionUID whether it does or not.

This is offtopic, I know, but I think it'd be great to have a separate rule
which checks that a Serializable class:
-defines a serialVersionUID
-contains only members that are Serializable, transient or static
-has a unique serialVersionUID (check and compare)
-does not extend a class that *can't* be serialized, such as a socket or stream
or database connection etc

I've already implemented the above checks in my code by abusing Javadoc doclets,
so I don't really need it. But perhaps someone else could benefit from such a thing.
Comment 4 Philipe Mulet CLA 2004-04-08 10:10:01 EDT
Patch looks good. This is the check we had in #unusedPrivateField.
Fixed. Added regression test: NegativeTest#test416.
Comment 5 Olivier Thomann CLA 2004-05-18 13:49:10 EDT
Verified in 200405180816
Comment 6 Ian deSouza CLA 2013-11-15 10:23:03 EST
I think this bug is back in the Kepler release