JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
Java


JAVA.ID.STYLE : Naming Style Violation (Java)

Summary

A class, method, field, or parameter is named in a non-standard way.

Class and method names in Java are traditionally written in a standard way, based on camelization of words. The names of classes start with a capital letter, while the names of fields and methods normally start with a small letter. In particular, a method should not be called as the same class where it is defined, since it might be misunderstood as a constructor. Moreover, a class should not be named as one of its superclasses or superinterfaces, up to the package name, since this can introduce confusion and, potentially, bugs.

Properties

Class Name Naming Style Violation (Java)
Significance style
Mnemonic JAVA.ID.STYLE
Categories
CWE CWE:710 Improper Adherence to Coding Standards
Availability Available for Java and Kotlin.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Naming Style Violation (Java)"

Example

// package1/BadNames.java
package package1;

public class BadNames {

  public final static String TAG = "BADNAMES";

  public final int Value;                         /* "Naming Style Violation (Java)" warning issued here
                                                   * - field name is capitalized
                                                   */

  public BadNames(int x) {
      Value = x;
  }

  public void Test() {                            /* "Naming Style Violation (Java)" warning issued here
                                                   * - method name is capitalized
                                                   */
      System.out.println(TAG + ": hello");
      new BadNames(45);
  }

  public void BadNames() {                        /* "Naming Style Violation (Java)" warning issued here
                                                   * - non-constructor method name matches class name
                                                   * - method name is capitalized
                                                   */
      System.out.println(TAG + ": hello");
  }

  private class inner {                           /* "Naming Style Violation (Java)" warning issued here
                                                   * - inner class name is not capitalized
                                                   */
  }
}
// package2/BadNames.java
package package2;

public class BadNames extends package1.BadNames { /* "Naming Style Violation (Java)" warning issued here
                                                   * - class has same simple name as its superclass
                                                   */

  public BadNames(int x) {
      super(x);
  }
}

Resolution

Modify the name in order to comply to the standard. In particular, avoid methods or fields starting with a capital letter, unless they are constants.

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.