GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Incorrect serialVersionUID field — CodeQL query help documentation

Incorrect serialVersionUID field¶

ID: java/incorrect-serial-version-uid
Kind: problem
Security severity: 
Severity: warning
Precision: medium
Tags:
   - quality
   - reliability
   - correctness
Query suites:
   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

A serializable class that uses the serialVersionUID field to act as an object version number must declare the field to be final, static, and of type long for it to be used by the Java serialization framework.

Recommendation¶

Make sure that the serialVersionUID field in a serialized class is final, static, and of type long.

Example¶

In the following example, WrongNote defines serialVersionUID using the wrong type, so that it is not used by the Java serialization framework. However, Note defines it correctly so that it is used by the framework.

class WrongNote implements Serializable {
	// BAD: serialVersionUID must be static, final, and 'long'
	private static final int serialVersionUID = 1;
	
	//...
}

class Note implements Serializable {
	// GOOD: serialVersionUID is of the correct type
	private static final long serialVersionUID = 1L;
}

References¶

  • Java API Specification: Serializable.

  • JavaWorld: Ensure proper version control for serialized objects.

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.