Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this noncompliant code example, OUT_STR_LEN must always be exactly two greater than IN_STR_LEN. The These definitions fail to reflect this requirement. :

Code Block
bgColor#FFcccc
public static final int IN_STR_LEN = 18;
public static final int OUT_STR_LEN = 12;

Compliant Solution

The In this compliant solution, the relationship between the two values should be is represented in the definitions.:

Code Block
bgColor#ccccff
public static final int IN_STR_LEN = 18;
public static final int OUT_STR_LEN = IN_STR_LEN + 2;

...

In this noncompliant code example, there appears to be an underlying relationship between the two constants , when in fact there is nonewhere none exists.

Code Block
bgColor#FFcccc
public static final int ADULT_AGE = 18;
public static final int ALCOHOL_AGE = ADULT_AGE + 3;

A programmer performing routine maintenance may modify the definition for ADULT_AGE but fail to recognize the resulting change in the definition for ALCOHOL_AGE.

Compliant Solution

The definitions should In this compliant solution, the definitions reflect the independence of the two constants.

...

Search for vulnerabilities resulting from the violation of this guideline on the CERT website.

Automated Detection

Automated is not currently feasible.

Bibliography

Wiki Markup
\[[JLS 2005|AA. Bibliography#JLS 05]\] [Section 4.12.4|http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.12.4]

...