Java Hints
There are 203 total hints/inspections, 40 of them in current development version only.
There are 25 total suggestions/actions, 12 of them in current development version only.
APIs
- Be aware that this API will be optional in Java EE 7 platform.
- Warn user about usage of APIs from technologies which will be made optional in Java EE 7 specification. These APIs are not deprecated and can be used but because they will be optional they may or may not be available in future Java EE 7 compliant platforms. Since NetBeans 7.0
- Exporting non-public type through public API
- Checks that return types and parameter types of all public methods and all types of public fields are publicly available from other packages. Having private or package private types in a package API is useless. In NetBeans 6.8 or earlier
- Utility class with visible constructor[ Disabled by default ]
- Finds out classes containing only static elements with public or protected constructors. In NetBeans 6.8 or earlier
- Utility class without constructor[ Disabled by default ]
- Finds out classes containing only static elements and still being instantiable. In NetBeans 6.8 or earlier
Abstraction
- Type cast is too strong[ Disabled by default ]
- Reports type casts, which are too strict and casting to a more general type would be sufficient for for the actual expression. Sometimes, an instance is casted to a specific subtype, but methods invoked or fields used from the casted instance are actually defined by some supertype. In that case cast to too specific type introduces an unnecessary coupling to the code and limits its extensibility. <p/>This inspection will suggest to use the most general type which would satisfy the expression's needs. In current development version
Assignment Issues
- Assignment replaceable with operator-assignment[ Disabled by default ]
- Reports instances of assignment operations which can be replaced by operator-assignment. Code using operator-assignment may be clearer, and theoretically more performant. Since NetBeans 6.9
- Assignment to catch-block parameter[ Disabled by default ]
- Reports any instances of assignment to variable declared as a catch block parameter. While occasionally intended, this construct can be confusing. Since NetBeans 6.9
- Assignment to for-loop parameter[ Disabled by default ]
- Reports any instances of assignment to variable declared in a for statement in the body of that statement. It also reports any attempt to increment or decrement the variable. While occasionally intended, this construct can be extremely confusing, and is often the result of a typo. Since NetBeans 6.9
- Assignment to method parameter[ Disabled by default ]
- Reports any instances of assignment to a variable declared as a method parameter. It also reports any attempt to increment or decrement the variable. While occasionally intended, this construct can be extremely confusing, and is often the result of a typo. Since NetBeans 6.9
- Nested assignment[ Disabled by default ]
- Reports any instances of assignment expressions nested inside other expressions. While admirably terse, such expressions may be confusing, and violate the general design principle that a given construct should do precisely one thing. Since NetBeans 6.9
- Value of increment/decrement expression used[ Disabled by default ]
- Reports any instances of increment or decrement expressions nested inside other expressions. While admirably terse, such expressions may be confusing, and violate the general design principle that a given construct should do precisely one thing. Since NetBeans 6.9
Bitwise Operations
- Incompatible mask
- This inspection reports any instances of bitwise mask expressions which are guaranteed to evaluate to false. Expressions checked are of the form (var & constant1) == constant2 or (var | constant1) == constant2, where constant1and constant2 are incompatible bitmask constants. Since NetBeans 6.9
- Pointless bitwise expression
- This inspection reports any instances of pointless bitwise expressions. Such expressions include anding with zero, oring by zero, and shift by zero. Such expressions may be the result of automated refactorings not completely followed through to completion, and in any case are unlikely to be what the developer intended to do. Since NetBeans 6.9
- Shift operation outside of the reasonable range
- This inspection reports any instances of shift operations where the value shifted by is constant and outside of the reasonable range. Integer shift operations outside of the range 0..31 and long shift operations outside of therange 0..63 are reported. Shifting by negative or overly large values is almost certainly a coding error. Since NetBeans 6.9
Braces
- Do-While Loops Should Use Braces[ Disabled by default ]
- Do-While Loops Should Use Braces In NetBeans 6.8 or earlier
- For Loops Should Use Braces[ Disabled by default ]
- Warns if a
forloop does not have its body wrapped in curly braces.
In NetBeans 6.8 or earlier
- If-Else Statements Should Use Braces[ Disabled by default ]
- If-Else Statements Should Use Braces In NetBeans 6.8 or earlier
- While Loops Should Use Braces[ Disabled by default ]
- While Loops Should Use Braces In NetBeans 6.8 or earlier
Class Structure
- Class may be interface[ Disabled by default ]
- Reports any concrete or abstract classes which may be simplified to be interfaces. This occurs if the class has no superclass (other than Object), has no fields declared that are not static, final, and public, and has no methods declared that are not public and abstract, and no inner classes that cannot themselves be interfaces. Since NetBeans 6.9
- Final class[ Disabled by default ]
- Reports any instances of classes being declared final. Some coding standards discourage final classes. Since NetBeans 6.9
- Final method[ Disabled by default ]
- Reports any instances of methods being declared final. Some coding standards discourage final classes. Since NetBeans 6.9
- Final method in final class[ Disabled by default ]
- Reports any instances of methods being declared final in classes that are declared final. This is unnecessary, and may be confusing. Since NetBeans 6.9
- Final private method
- Reports any instances of methods being declared final and private. As private methods cannot be meaningfully overridden, declaring them final is redundant. Since NetBeans 6.9
- Final static method
- Reports any instances of methods being declared final and static. As static methods cannot be meaningfully overridden, declaring them final is redundant. Since NetBeans 6.9
- Marker interface[ Disabled by default ]
- Reports marker interfaces which have no methods or fields. Such interfaces may be confusing, and normally indicate a design failure. Interfaces which extend two or more other interfaces will not be reported. Since NetBeans 6.9
- Multiple top-level classes in file[ Disabled by default ]
- Reports any instances of multiple top-level classes in a single java file. Putting multiple top-level classes in a file can be confusing, and may degrade the usefulness of various software tools. Since NetBeans 6.9
- No-op method in abstract class[ Disabled by default ]
- Reports any instances of no-op methods in abstract classes. It is usually a better design to make such methods abstract themselves, so that classes which inherit the methods will not forget to provide their own implementations. Since NetBeans 6.9
- Organize members[ Disabled by default ]
- Checks whether members order corresponds to the specified code style rules Since NetBeans 7.3
- Protected member in final class[ Disabled by default ]
- Reports any instances of members being declared protected in classes that are declared final. Such members may be declared private or package-visible instead. Since NetBeans 6.9
- Public constructor in non-public class[ Disabled by default ]
- Reports all constructors in non-public classes that are declared public. Since NetBeans 6.9
Code Maturity Issues
- Obsolete Collection
- This inspection reports any uses of java.util.Vector or java.util.Hashtable. While still supported, these classes were made obsolete by the JDK1.2 collection classes, and should probably not be used in new development. Since NetBeans 6.9
- Print Stack Trace
- This inspection reports any uses Throwable.printStackTrace() without arguments. These are often temporary debugging statements, and should probably be either removed from production code, or replaced by a more robust logging facility. Since NetBeans 6.9
- System out / err[ Disabled by default ]
- This inspection reports any uses of System.out or System.err. These are often temporary debugging statements, and should probably be either removed from production code, or replaced by a more robust logging facility. Since NetBeans 6.9
- Thread Dump Stack
- This inspection reports any uses Thread.dumpStack(). These are often temporary debugging statements, and should probably be either removed from production code,or replaced by a more robust logging facility. Since NetBeans 6.9
Empty Statements
- '
- In NetBeans 6.8 or earlier
- Empty statement
- Checks for empty statements in blocks usually represented as superfluous semicolon. Since NetBeans 6.9
- Empty statement after 'do'
- Checks for 'do/while' statements in form
do;. Since NetBeans 6.9
while
- Empty statement after 'for'
- Checks for 'for' statements in form
for(...);. Since NetBeans 6.9
- Empty statement after 'if/else'[ Disabled by default ]
- Checks for 'if/else' statements in form
if(...);. Since NetBeans 6.9
else;
- Empty statement after 'while'
- Checks for 'while' statements in form
while(...);. Since NetBeans 6.9
Encapsulation
- Access of Private Field of Another Object[ Disabled by default ]
- Warns about access of private fields of another objects Since NetBeans 6.9
- Assignment to Array Field from Parameter[ Disabled by default ]
- Warns about assignment of array into fields Since NetBeans 6.9
- Assignment to Collection Field from Parameter[ Disabled by default ]
- Warns about assignment of java.util.Collection into fields Since NetBeans 6.9
- Assignment to Date or Calendar Field from Parameter[ Disabled by default ]
- Warns about assignment of java.util.Date or java.util.Calendar into fields Since NetBeans 6.9
- Package Field[ Disabled by default ]
- Warns about existence of package visible variables Since NetBeans 6.9
- Package Visible Inner Class[ Disabled by default ]
- Warns about existence of package visible inner class Since NetBeans 6.9
- Protected Field[ Disabled by default ]
- Warns about existence of protected variables Since NetBeans 6.9
- Protected Inner Class[ Disabled by default ]
- Warns about existence of protected visible inner class Since NetBeans 6.9
- Public Field[ Disabled by default ]
- Warns about existence of public variables Since NetBeans 6.9
- Public Inner Class[ Disabled by default ]
- Warns about existence of public visible inner class Since NetBeans 6.9
- Return of Array Field[ Disabled by default ]
- Warns about return of array fields Since NetBeans 6.9
- Return of Collection Field[ Disabled by default ]
- Warns about return of collection fields Since NetBeans 6.9
- Return of Date or Calendar Field[ Disabled by default ]
- Warns about return of java.util.Date or java.util.Calendar fields Since NetBeans 6.9
Error Fixes
- Create Field
- Settings for Create Field Fix Since NetBeans 6.9
- Create Local Variable
- Settings for the Create Local Variable error fix Since NetBeans 6.9
- Implementation of EJBContainer is missing on project's classpath
- Find out whether implementation of EJBContainer necessary for successful execution of unit test is available. Since NetBeans 7.0
- Java EE API is missing on project classpath.
- Find out whether Java EE API is available on project classpath. Java EE API is necessary for successful test execution. This hint also warns about incorrect usage of javaee-web-api artifact - that artifact is suitable only for compilation but not for test execution because body of all API methods was removed from the bytecode. Since NetBeans 7.0
- Surround with try-catch
- Settings for the Surround with try-catch error fix Since NetBeans 6.9
Finalization
- finalize() called explicitly
- Warns about an explicit call of the Object.finalize() Since NetBeans 6.9
- finalize() declared
- Warns about implementations of Object.finalize() Since NetBeans 6.9
- finalize() does not call super.finalize()
- Warns about implementations of Object.finalize() which do not call supertype implementation Since NetBeans 6.9
- finalize() not declared protected[ Disabled by default ]
- Warns about non protected implementations of Object.finalize() Since NetBeans 6.9
General
- .equals Method not Checking Type
- Implementation of .equals methods not checking the type of the input parameter In NetBeans 6.8 or earlier
- Accessing static via reference
- Java language allows access to static fields thru instance variables, however this is often misleading and harder to read. In NetBeans 6.8 or earlier
- Assignment To Itself
- Assignment To Itself In NetBeans 6.8 or earlier
- Comparing Strings using == or !=
- Checks for usages of == or != operator for comparing Strings.
String comparisons should generally be done using the equals() method. In NetBeans 6.8 or earlier
- Field hides another field
- Declaration of a field in a class can hide declaration of another field in superclasses. Although possible, this is not very good programming style. In NetBeans 6.8 or earlier
- Generate missing hashCode or equals
- Checks whether a class which overrides equals method also overrides hashCode. In NetBeans 6.8 or earlier
- Local variable hides a field
- Declaration of a variable in a method can hide declaration of a field declared in the surrounding class. Although possible, this is not very good programming style. In NetBeans 6.8 or earlier
- Redundant conditional statement
- Redundant conditional statement In current development version
- Redundant if statement
- Redundant if statement In current development version
- Remove Unnecessary Continue Statement
- Remove Unnecessary Continue Statement In current development version
- Remove Unnecessary Label in break
- Remove Unnecessary Label in break statement In current development version
- Remove Unnecessary Label in continue
- Remove Unnecessary Label in continue statement In current development version
- Remove Unnecessary Return Statement
- Remove Unnecessary Return Statement Since NetBeans 7.1
- Unnecessary Throwable.initCause
- Finds invocations of Throwable.initCause which can be replaced with simple constructor invocation. When the "Never alter result of getMessage()" checkbox is unchecked,
(IllegalStateException) new IllegalStateException().initCause(ex)will be rewritten tonew IllegalStateException(ex), which will alter the value of getMessage(). When the checkbox is checked, the code will becomenew IllegalStateException(null, ex). Similar rule holds for creating the exception fromgetMessage()orgetLocalizedMessage()of the cause. Since NetBeans 6.9
- Use Functional Operations
- Use functional operations instead of imperative style loop. In current development version
- Wrong Package
- Wrong Package In NetBeans 6.8 or earlier
Imports
- Import From The Same Package
- Import From The Same Package In NetBeans 6.8 or earlier
- Import From java.lang Package
- Import From java.lang Package In NetBeans 6.8 or earlier
- Import from Excluded
- Import from package or class which has been labelled "Excluded" in the Code Completer In NetBeans 6.8 or earlier
- Organize imports[ Disabled by default ]
- Checks whether import statements correspond to the specified code style rules Since NetBeans 7.1
- Star import[ Disabled by default ]
- Star import In NetBeans 6.8 or earlier
- Unused Import
- Unused Import In NetBeans 6.8 or earlier
Initialization
- Passing suspicious parameter in the constructor
- Using this as parameter can be dangerous in the contructor because the object is not fully initialized. Since NetBeans 6.9
- Problematic call in the constructor
- Calling methods that can be overridden can be dangerous in the contructor because in the moment when the overridden method is called the object is not fully initialized. Since NetBeans 6.9
- Static non-final variable used during initialization
- Using static non-final variables can be dangerous in the initialization code because their values may depend on the order of initialization statements Since NetBeans 6.9
JDK 1.5 and later
- AbstractProcessor.getSupportedAnnotationTypes() is overridden
- Overriding Processor.getSupportedAnnotationTypes() may lead to unnecessary classloading during development, and may prevent important optimalizations. consider using @javax.annotation.processing.SupportedAnnotationTypes Since NetBeans 7.2
- Add @Override Annotation
- Add @Override Annotation In NetBeans 6.8 or earlier
- Add Underscores[ Disabled by default ]
- Proposed to add underscores to integer literals to improve their readability Since NetBeans 7.2
- Can Use Diamond
- Warns about places where the diamond operator in JDK 7 can be used instead of explicit type parameters Since NetBeans 7.1
- Convert to Lambda
- Convert to Lambda In current development version
- Convert to try-with-resources
- Converts try finally block to try-with-resources Since NetBeans 7.0
- Don't use Annotation as super interface
- Despite the compiler permitting such constructs, Annotations should not be used as superinterfaces. In NetBeans 6.8 or earlier
- Join catch sections using multicatch
- Join catch sections using multicatch Since NetBeans 7.0
- Static imports[ Disabled by default ]
- Convert method to static import. Feedback to http://www.netbeans.org/issues/show_bug.cgi?id=89258 Since NetBeans 6.9
- String.indexOf can be replaced with String.contains
- Finds usages of String.indexOf that can be replaced with String.contains In current development version
- Too broad 'catch' clause
- Reports catch clauses, which catch a supertype rather than the actually thrown exception type. Such broad catches may provide inappropriate reports or overly general exception handling. <p/>Sometimes the method produces more than one exception type which can be handled by catching their common supertype. "Report common supertypes" option controls whether such situations will be reported. The generic exceptions configured for the Use Specific Catch<b> hint are always reported. In current development version
- Use JDK 5 for-loop
- Replaces simple uses of Iterator with a corresponding for-loop. Since NetBeans 7.3
- Use specific catch
- Converts catch (Throwable) or catch (Exception) to multicatch (when java source level is 7 and above) or to several catch clauses (for earlier Java platforms) catching the exceptions thrown by the try body. The watched exception types can be configured; fully qualified names must be used. Since NetBeans 7.0
- Use switch over Strings where possible.
- Marks cascades of ifs which can be converted to switch over Strings . Since NetBeans 6.9
Java Code Metrics
- Anonymous class has too many methods[ Disabled by default ]
- Reports anonymous class with many methods. Anonymous classes typically implement a very simple interface, and should be very simple. It is recommended to create at least named local class, if the anonymous class' complexity grows. In current development version
- Anonymous class is too complex[ Disabled by default ]
- Reports anonymous classes, whose cyclomatic complexity exceeds the configured limit. The complexity of a class is computed as a sum of complexities of its methods. Anonymous classes should have far less responsibilities and lower complexity than a regular class In current development version
- Arithmetic expression too complex[ Disabled by default ]
- Reports arithmetic expressions, which include more than the defined number of operations. Expression with many operands are harder to read and often could be split into several assignment statements to interim result variables. In current development version
- Class has too many constructors[ Disabled by default ]
- Reports classes which define too many constructors. In current development version
- Class has too many fields[ Disabled by default ]
- Reports a class which holds too many fields. The state kept by the class is too large and it should be investigated if the state can be split into several state classes, often also separating manipulation methods and reduce the overall class complexity. In current development version
- Class has too many methods[ Disabled by default ]
- Reports class, which contains too many methods. The options allows to ignore simple bean property accessors - lazy getters, or setters which fire change events are not considered 'simple'. Implementations of superclass (not implementation of interface methods) abstract methods can be also ignored. In current development version
- Class is too complex[ Disabled by default ]
- Reports classes, whose cyclomatic complexity exceeds the configured limit. The complexity of a class is computed as a sum of complexities of its methods. In current development version
- Class is too coupled[ Disabled by default ]
- Reports classes which are too coupled (use too many) other types. References to java system libraries (
java.**andjavax.**) can be ignored. In current development version
- Constructor declares too many parameters[ Disabled by default ]
- Reports constructor that take too many parameters. Constructors typically take more parameters than a regular method, especially when initializing a large object.<p/>Large nuber of parameters indicate a bad design. It's likely that yet more parameters will be added in the future, so creational patterns like Builder should be considered. In current development version
- Logical expression too complex[ Disabled by default ]
- Reports logical expressions, which include more than the defined number of operations. Expression with many operands are harder to read and often could be split into several assignment statements to interim result variables. In current development version
- Method body is too long[ Disabled by default ]
- Reports methods, which have too long body. Longer methods require scrolling back and forth, and typically can be refactored into several methods called from a mediating method. Splitting a long method into several named pieces may also help code reuse. Some coding practices even demand that a method should fit a screen size, so it can be easily scanned and understood by the developer. In current development version
- Method declares too many parameters[ Disabled by default ]
- Reports method that take too many parameters. Methods with large nuber of parameters indicate a bad design. It's likely that yet more parameters will be added in the future, so the parameters should be grouped into a Command Object, improving maintenance costs. Alternatively, the method could be refactored into several methods, each doing part of the task and requiring less parameters at input. In current development version
- Method is too complex[ Disabled by default ]
- The inspection reports method, whose <b>Cyclomatic Complexity exceeds a configurable value. The Cyclomatic Complexity measures a number of potential branching points (or cycles) in a method. It is believed that methods with high cyclomatic complexity usually do too much and should be split to several, more focused, methods. Such complex methods are also prone to code duplication between their execution paths and are hard to sustain. Usually it is recommended that cyclomatic complexity of a method is 5 or below; less than 10 may be also acceptable for more elaborate algorithms. In current development version
- Method or constructor declares too many exceptions[ Disabled by default ]
- Reports methods which declare many exceptions in their throws clause. Method that produce a large number of exception types are hard to use, as the caller must handle all the outcomes or complicate its own declaration with exceptions. The error handling code grows more complex. <p/>The inspection also processes constructors. In current development version
- Method with multiple loops[ Disabled by default ]
- Methods that contains multiple loop statements. In current development version
- Method with multiple negations[ Disabled by default ]
- Methods with multiple negated expressions (unary ! or !=) are said to confuse readers, true (non-negated) expressions are considered easier to read and understand. Consider to change the logic to use true instead of false values. In current development version
- Method with multiple return points[ Disabled by default ]
- Reports methods, which exit at multiple places using return statement. Such methods may be confusing and are harder to refactor. The inspection can ignore conditional guard returns - a return statement, which is the sole statement in an if branch. Optionally, all equals methods can be ignored, as contents of equals is traditionally generated using early returns on type or value mismatch. In current development version
- Too coupled method[ Disabled by default ]
- Reports methods which are too coupled - that refer to too many other types. Methods that refer to large number of types are fragile: they tend to fail or require refactoring if the referenced type(s) change. It is also more difficult to move the method which has many dependencies to another module. <p/>References to the method class' itself and its superclasses are ignored. With Ignore dependencies on Java Platform, references to
java.**andjavax.**classes are also ignored. In current development version
- Too deep nesting[ Disabled by default ]
- Reports methods whose bodies contain statements nested too deep. Such methods are are less readable, contain indent space and allow less screen space for code reading. Methods can be often refactored and split to improve code readability. In current development version
JavaDoc
- Create Javadoc
- Create Javadoc In NetBeans 6.8 or earlier
- Error in Javadoc
- Error in Javadoc In NetBeans 6.8 or earlier
JavaEE
- Instantiation replaceable with @EJB injection
- Finds instantiations of a bean which can be injected by @EJB annotation Since NetBeans 7.2
Logging
- Logger declaration is not static final
- Each class should have one unique logger. If declared as a field it should be static and final. Since NetBeans 6.9
- Multiple loggers
- There are several loggers declared for a single class. Since NetBeans 6.9
- No loggers[ Disabled by default ]
- There is no logger declared for a class. Since NetBeans 6.9
- String concatenation in logger
- It is not performance efficient to concatenate strings in logger messages. It is better to use a template message with placeholders that are replaced by concrete values only when the message is really going to be logged. Since NetBeans 6.9
Maven
- Resolve Missing Class Dependency
- Resolve missing class dependency and add to project POM Since NetBeans 6.9
NetBeans Development
- Empty cancel() for cancelable tasks[ Disabled by default ]
- Warn about empty cancel() methods for cancelable tasks In NetBeans 6.8 or earlier
- HelpCtx issues
- Warnings about misuse of org.openide.util.HelpCtx. Since NetBeans 7.2
- Illegal Use of instanceOf operator[ Disabled by default ]
- Show illegal use of instanceof on javax.lang.model.elements, javax.lang.model.type and com.sun.source.tree In NetBeans 6.8 or earlier
- Use @NbBundle.Messages
- Use @NbBundle.Messages in preference to Bundle.properties plus NbBundle.getMessage(...). Since NetBeans 7.0
Performance
- .getClass() replaceable with .class[ Disabled by default ]
- Finds instantions of a class directly followed by invocation of .getClass() on the newly constructed object Since NetBeans 6.9
- Collections without initial capacity[ Disabled by default ]
- Looks for instatiations of collections with missing initial capacity. Only collections backed-up with an array are tested. Since NetBeans 6.9
- Creating new Boolean
- Creating new Boolean is inefficient and typically useless. Since NetBeans 6.9
- Length one String in String.indexOf[ Disabled by default ]
- Length one String literal in String.indexOf can be replaced with a character literal Since NetBeans 6.9
- Manual array copy
- Finds occurrences of manual array copying via for loop Since NetBeans 6.9
- Map replaceable with EnumMap
- Finds instantiations of Maps that can be replaced with EnumMap Since NetBeans 6.9
- Set replaceable with EnumSet
- Finds instantiations of Sets that can be replaced with EnumSet Since NetBeans 6.9
- String concatenation in StringBuilder.append
- Looks for string concatenation in the parameter of an invocation of the append method of StringBuilder or StringBuffer. Since NetBeans 6.9
- String constructor
- Use of java.lang.String constructor is usually useless. Since NetBeans 6.9
- String.equals("")[ Disabled by default ]
- Use of String.equals("") can be replaced with with String.length() == 0 (for JDK5 and lower) or String.isEmpty() (for JDK6 and higher) Since NetBeans 6.9
- String.intern() called on constant[ Disabled by default ]
- Invocations of String.intern() on compile-time constants are superfluous. Since NetBeans 6.9
- StringBuilder without initial capacity[ Disabled by default ]
- Looks for instantiations of StringBuilder or StringBuffer with missing initial capacity. Since NetBeans 6.9
- Usage of .size() == 0
- Use .isEmpty() or !.isEmpty() instead of .size() == 0 or .size() != 0 where possible. Since NetBeans 6.9
- Useless use of StringBuffer
- Use StringBuilder instead of StringBuffer where possible. Since NetBeans 6.9
- Zero element array passed to Collection.toArray[ Disabled by default ]
- Passing zero element array to Collection.toArray may affect performance Since NetBeans 7.2
Probable Bugs
- 'finally' block suppresses exceptions
- Reports usage of return statements in finally block. Such returndiscards the exception being thrown and causes the whole method to complete normally, which is usually not the desired outcome. Break and continue statements, which break out of the finally block are also reported. In current development version
- 'throw' inside 'finally' block
- Throwing an exception inside finally block will hide the original exception thrown from the associated try or catch blocks from enclosing exception handlers. Note that the exception can be still inspected using Throwable.getSuppressedException(), although it cannot be directly caught by a catch block. In current development version
- .equals on Array
- .equals on array Since NetBeans 6.9
- .equals on Incompatible Types
- .equals on incompatible types In NetBeans 6.8 or earlier
- .equals(null)
- Finds invocations of the Object.equals method with literal parameter 'null'. Since NetBeans 6.9
- @CheckReturnValue
- Verifies that a result of method marked with @CheckReturnValue is really checked. Since NetBeans 7.2
- Annotations without runtime Retention
- Warns about reflective access to annotations with CLASS or SOURCE retentions Since NetBeans 6.9
- Cloneable class does not implement clone().[ Disabled by default ]
- <html>Cloneable class should override clone(). If it does not, the clone operation uses the default java.lang.Object.clone(), which is usually not suitable. Lack of overriden clone indicate a possible error.</html> In current development version
- Confusing indentation
- Warns about indentation that suggests possible missing surrounding block In current development version
- Dead Branch
- Dead Branch Since NetBeans 7.1
- Incompatible cast/instanceof
- Incompatible cast surrounded with incompatible instanceof Since NetBeans 6.9
- Incorrect column index in ResultSet
- Reports Iincorrect column indices passed to various methods of java.sql.ResultSet Since NetBeans 6.9
- Malformed regular expression
- Warns about malformed regular expressions Since NetBeans 6.9
- Null Pointer Dereference
- Checks various problems related to dereferencing nulls Since NetBeans 7.3
- Result of new Object ignored
- Result of new Object ignored. Since NetBeans 6.9
- String.replaceAll(".", )
- Finds occurrences of calls to String.replaceAll(".", $target), which would replace all characters of the source string with $target. Since NetBeans 6.9
- Suspicious invocation of System.arraycopy
- Finds invocations of System.arraycopy with negative offsets, length or used on non-array objects. Since NetBeans 6.9
- Suspicious method call
- Warns about suspicious calls to Collection.remove/contains and Map.containsKey/containsValue/remove Since NetBeans 6.9
- Synchronizing on this in anonymous class
- <html>Synchronizing on this in anonymous or local class is probably a result of refactoring and possibly a mistake Since NetBeans 6.9
- Unbalanced read/write with arrays
- Unbalanced read/write with arrays Since NetBeans 7.1
- Unbalanced read/write with collections
- Unbalanced read/write with collections Since NetBeans 7.1
- Unused Assignment
- Unused Assignment Since NetBeans 7.1
- clone() does not call super.clone()
- Cloned instances should be allocated using super.clone() so fields are initialized properly. In current development version
- clone() does not throw CloneNotSupportedException
- If clone() does not declared to throw CloneNotSupportedException subclasses cannot prohibit cloning using standard Cloneable contract. In current development version
- clone() in a non-Cloneable class[ Disabled by default ]
- The contract for Object.clone() requires, that a class must implement Cloneable marker interface. If not, the clone() method will raise CloneNotSupportedException. Declaring Cloneable interface is often overlooked. In current development version
Standard Javac Warnings
- Deprecated[ Disabled by default ]
- Warn when code uses deprecated API. Since NetBeans 6.9
- Division By Zero[ Disabled by default ]
- Division By Zero Since NetBeans 6.9
- Empty Statement After If[ Disabled by default ]
- Empty Statement After If Since NetBeans 6.9
- Fallthrough[ Disabled by default ]
- Warn when a case can fall through to the next case. Since NetBeans 6.9
- Finally [ Disabled by default ]
- Warn when a finally block interrupts flow of a try/catch block. Since NetBeans 6.9
- Overrides[ Disabled by default ]
- Warn when an overriding method is not annotated with @Overrides Since NetBeans 6.9
- Raw Types[ Disabled by default ]
- Raw Types Since NetBeans 6.9
- Serialization[ Disabled by default ]
- Warn when a class which implements java.io.Serializable does not declare a serialVersionUID. Since NetBeans 6.9
- Unchecked[ Disabled by default ]
- Warn when unchecked conversions may cause ClassCastExceptions at runtime. Since NetBeans 6.9
- Unnecessary Cast[ Disabled by default ]
- Warn when an object is cast unnecessarily to the same type or a supertype. Since NetBeans 6.9
Suggestions
- Assign Return Value To New Variable
- Assign Return Value To New Variable In NetBeans 6.8 or earlier
- Assign Unused Constructor Parameter to Field
- Assign Unused Constructor Parameter to Field In NetBeans 6.8 or earlier
- Combine nested if
- Combine nested if In current development version
- Convert Anonymous to Member
- Convert Anonymous to Member In NetBeans 6.8 or earlier
- Convert integer constant to different base
- Convert integer constant to different base Since NetBeans 7.0
- Convert lambda body to use a block rather than an expression
- Converts lambda body to use a block rather than an expression In current development version
- Convert lambda expression to anonymous innerclass
- Converts lambda expression to anonymous innerclass In current development version
- Convert lambda to use explicit parameter types
- Converts lambda to use explicit parameter types In current development version
- Convert member reference to lambda expression
- Converts member references to a lambda expression In current development version
- Create Subclass
- Create Subclass Since NetBeans 7.2
- Create Test Class
- Create a test class for the selected source class. In current development version
- Declaration for instanceof
- Declaration for instanceof In NetBeans 6.8 or earlier
- Expand Enhanced For Loop
- Expand Enhanced For Loop Since NetBeans 7.1
- Fill Missing Cases to Switch
- Adds missing cases to switch statement. The default clause template should be one Java statement, occurrences of $expression will be replaced with the expression over which the switch statement works. Since NetBeans 7.2
- Flip .equals
- Allows to flip .equals parameter and call site Since NetBeans 6.9
- Generate All Test Methods
- Generate all test methods for the selected source class. In current development version
- Implement Abstract Methods
- Implement Abstract Methods. Since NetBeans 7.3
- Invert If
- Will invert an if statement; negate the condition and switch the statements from the then and else sections. Since NetBeans 7.3
- Join consecutive ifs into if-else
- Converts cases like
if - else { if }infoif - else ifIn current development version
- Join if conditions using ||
- Converts cases like
if (cond1) statement; else if (cond2} statement;intoif (cond1 || cond2) statement;In current development version
- Move initilization to constructor
- Moves a fields initilization expression to the constructors. Since NetBeans 7.3
- Split Declaration
- Splits declaration with initializer to a declaration and assignment Since NetBeans 7.2
- Split if
- Splits if into two ifs In current development version
- Split if condition
- Splits if whose condition is || into two ifs In current development version
Testing
- Incorrect order of parameters of Assert.assertEquals
- Incorrect order of parameters of Assert.assertEquals In current development version
- Incovertible parameters of Assert.assertEquals
- Incovertible parameters of Assert.assertEquals In current development version
- assertEquals for array parameters
- Warns about assertEquals whose parameters are arrays In current development version
Threading
- .notify invoked outside a synchronized context
- .notify invoked outside a synchronized context Since NetBeans 6.9
- .wait invoked outside a synchronized context
- .wait invoked outside a synchronized context Since NetBeans 6.9
- Double-checked locking
- Searches for examples of double checked locking - e.g. when a variable is tested before as well as inside a synchronized block. In NetBeans 6.8 or earlier
- Empty synchronized block
- Empty synchronized block are usually useless Since NetBeans 6.9
- Field Can Be Final
- Finds fields that can be made final, which can simplify sychronization and clarity In current development version
- Invoking Condition.notify()
- Invoking notify or notifyAll on java.util.concurrent.locks.Condition should probably be replaced with invoking signal or signalAll. Since NetBeans 6.9
- Invoking Condition.wait()
- Invoking notify or notifyAll on java.util.concurrent.locks.Condition is probably unintended. Since NetBeans 6.9
- Invoking Thread.run()
- Invoking run on java.lang.Thread should be probably replaced with invocation of method start() Since NetBeans 6.9
- Invoking Thread.stop()/suspend()/resume()
- Methods stop(), suspend() and resume() of java.lang.Thread are dangerous and should not be used. Since NetBeans 6.9
- Invoking Thread.yield()
- Invocation of method yield() on java.lang.Thread is usually used to masquerade synchronization problems and should be avoided. Since NetBeans 6.9
- Lock not unlocked in finally
- Finds occurrences of Lock.lock()-Lock.unlock() not properly wrapped in try-finally. Since NetBeans 6.9
- Nested synchronized blocks
- Nesting synchronized blocks is either useless (if they use the same lock object) or dangerous. Since NetBeans 6.9
- Starting Thread in constructor
- Starting a new Thread in constructor is dangerous and should be prevented. Since NetBeans 6.9
- Synchronization on non-final field
- Synchronization on non-final field In NetBeans 6.8 or earlier
- Synchronizing on Lock
- Synchronizing on java.util.concurrent.locks.Lock is usually unintended and should be replaced with Lock.lock()-Lock.unlock() Since NetBeans 6.9
- Thread.sleep in loop
- Invoking Thread.sleep in loop can cause performance problems Since NetBeans 6.9
- Thread.sleep in synchronized context
- Invoking Thread.sleep in synchronized context can cause performance problems Since NetBeans 6.9
- Volatile array field
- Finds declarations of volatile array fields. Since NetBeans 6.9
suggestion
- Flip operands of the binary operator
- Flip operands of the binary operator In current development version
