This page provides accurate and valuable information on enhancing security in Java by minimizing the use of and restricting access to mutable objects. It emphasizes the importance of favoring immutability for value types, creating safe copies of mutable input and output values,
and avoiding the exposure of references to mutable objects. These practices are crucial for preventing unintended modifications and potential security vulnerabilities in Java applications.
Security Coding Guideline 6 from Oracle
The use of mutable objects may seem harmless but these guidelines explore why this is not the case. This is a large topic as one can conclude from the guidelines. It is a good read so going through it is not a waste of time.
Familiarize yourself with the guideline headings for the exam.
- java.util.Date mutable API Class
One interesting API note:
The java.util.Date
is an example of a mutable API class. In an application, it would be preferrable to use the new
Java Date and Time API (java.time.*) which has been designed to be immutable, and this will help you write secure applications.