Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Wiki Markup In a JVM, "Two classes are the same class (and consequently the same type) if they are loaded by the same class loader, and they have the same fully qualified name" \[ [JVMSpec 1999|AA. References#JVMSpec 99]\]. Two classes with the same name but different package names are distinct, as are two classes with the same fully qualified name loaded by different class loaders.

It could be necessary to check whether a given object has a specific class type or whether two objects have the same class type associated with them, for example, when implementing the equals() method. If the comparison is performed incorrectly, the code could assume that the two objects are of the same class when they are not. As a result, class names must not be compared.

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

OBJ09-J

high

unlikely

low

P9

L2

Related Guidelines

MITRE CWE

CWE-486. Comparison of classes by name

Bibliography

...

[[Christudas 2005AA. References#Christudas 05]]

Internals of Java Class Loading

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2336e7c5-5e91-45ff-8238-ef41c168700a"><ac:plain-text-body><![CDATA [ [[JVMSpec 1999AA. References#JVMSpec 99] ]

[§2.8.1, Class Names

http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="401a768d-5c36-4d51-9abd-a6dd4232b027"><ac:plain-text-body><![CDATA[

[ [McGraw 1998AA. References#Mcgraw 98] ]

Twelve rules for Developing More Secure Java Code ]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="421f9b36-f85f-4188-aac2-68c0cedfebea"><ac:plain-text-body><![CDATA[

[ [Wheeler 2003AA. References#Wheeler 03] ]

[Java Secure Programming for Linux and UNIX HOWTO

http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/java.html]

]]></ac:plain-text-body></ac:structured-macro>

...

      04. Object Orientation (OBJ)      OBJ10-J. Do not use public static nonfinal variables