A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2580 below:

[java] AvoidThrowingNullPointerException marks all NullPointerException objects as wrong, whether or not thrown · Issue #2580 · pmd/pmd · GitHub

Affects PMD Version:
6.22.0

Rule:
AvoidThrowingNullPointerException

Description:
AvoidThrowingNullPointerException marks all NullPointerException objects as wrong, whether or not thrown.
This rule is implemented through xpath search:

<![CDATA[
//AllocationExpression/ClassOrInterfaceType[@Image='NullPointerException']
]]>

This marks all new NullPointerException(), although these errors are not thrown.
It is recommended to adjust the detection content of the rule to reduce unimportant error warnings.

Code Sample demonstrating the issue:
Example 1

@Override
public LogEntry next() {
	long delay = (long) ((Math.random()*1800)/**(Math.random()*10)*/);
	try {
		Thread.sleep(delay);
	} catch (InterruptedException e) {/**/}
		
	Severity severity = Severity.Trace;
	StackTraceElement[] trace = null;
	if ( delay%2==0 ) {
		severity = Severity.Info;
	} else if ( delay%3==0 ) {
		severity = Severity.Error;
		trace = new NullPointerException("Sample").getStackTrace();
	}
		
	return new LogEntry(new Date(), severity, "Random entry with a delay of "+delay+"ms.", trace);
}

Example 2

public Config init() throws InvalidConfigurationException {
	if(CONFIG_FILE==null) throw new InvalidConfigurationException(new NullPointerException());
	if(CONFIG_FILE.exists()) return reload();
	else return save();
}

Expected outcome:
false-positive

Running PMD through:
CLI


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4