Standard Analyses

SemmleCode Professional comes with a wide range of pre-packaged analyses, from architectural properties and metrics, to statement-level checks for likely bugs and violations of best practice.


Incorrect serialVersionUID Field

This query finds classes whose serialVersionUID field is not public and static and of type long.

How to Interpret the Query Results

The query flags all offending classes and provides a list of all detected occurrences in the results view.

How to Address the Query Results

Ensure that the class has a valid serial version UID field.

Source Code
import default

from Field f
where f.hasName("serialVersionUID") and 
      (   not f.hasModifier("final")
       or not f.hasModifier("static")
       or not f.getType().hasName("long"))
select f, "serialVersionUID should be final, static, and of type long"
References

JavaWorld article Ensure proper version control for serialized objects