Can NetBeans generate an automatic serial version identifier for a Java class?

I would like to remove some warnings for some classes by creating an automatic version serial number. In Eclipse, this is trivial - the IDE can automatically generate it and add it to the class. However, I do not see this functionality in NetBeans. Is this available? If so, where is it? If not, is there a plugin that can enable it?

+6
java serialversionuid netbeans
source share
5 answers

Actually my solution to this β€œproblem” was to deactivate this warning in my project configuration (I use Eclipse, but I think this is the same for NetBeans) as IMHO this is a wrong warning: not having , serialVersion is the safest choice, because the JVM computes one that is unique at startup (something like a class hash), and when explicitly added, it loads you to take care to update this if and only if you make incompatible changes to your the code.

So, if you don’t care, it’s better to avoid this value (in this way it is only compatible with a version compatible with confidence , but with some false positives: it considers it to be incompatible, but actually it would be) instead of putting there is a fixed value that you (possibly in my case) forgot to update when necessary, which will lead to actual errors of reality (false-negatives: it considers that it is compatible, but it is not).

+9
source share

This is trivial to do manually if you do not need to remain compatible with existing serialized instances. Just copy this line to the class:

private static final long serialVersionUID = 1L; 

Note that for serialVersionUID there is absolutely no requirement to be unique to all classes.

+5
source share

NetBeans doesn't seem to support this feature, but plugins do.

Please take a look

link 1 , link 2 and link 3

+5
source share

To disable these warnings in Netbeans:

  • Open: Tools β†’ Options
  • Open: Editor β†’ Tips Tab
  • Select language: Java
  • Uncheck Javac Standard Alerts -> Serialization
  • Ok

I also had to clear ~ / .netbeans / 6.8 / var / cache and restart Netbeans to clear the warnings from the task list.

+1
source share

(For the user who is asking the same question now)
I am using nb7.4 and found this plugin from nb6.5 to nb7.4
plugin
I tested it in nb7.4 and worked well. For the meaning of the service version of id, look at
serialVersionUID
if you explicitly add it, you can make all changes to your class without changing the uid until you have serialized and saved your class: if you create a serialization series of class A

end then save it to the database
end, then change class A not compatible with old class A,
when someone tries to load a serialized object from the last class A into a new class A, it may have a problem.

When you change the class A and make it incompatible with the last class A, you need to change the uid, so if someone tries to load it, it will get InvalidClassExceptions.

0
source share

All Articles