All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S1695.html Maven / Gradle / Ivy

The newest version!
A NullPointerException should indicate that a null value was unexpectedly encountered. Good programming practice dictates that code is structured to avoid NPE's. 

Explicitly throwing NullPointerException forces a method's callers to explicitly catch it, rather than coding to avoid it. Further, it makes it difficult to distinguish between the unexpectedly-encountered null value and the condition which causes the method to purposely throw an NPE.

If an NPE is being thrown to indicate that a parameter to the method should not have been null, use the @NotNull annotation instead.

Noncompliant Code Sample

public void doSomething (String aString) throws NullPointerException 
{}

Compliant Solution

public void doSomething (@NotNull String aString)
{}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy