You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
PrematureDeclaration shouldn't trigger on classes which are specific to time measurement. E.g. it fails when stopwatch is used to measure time to invoke entire method (and I'm interested only in sunny-day scenario when exit points are not triggered).
Code Sample demonstrating the issue:
Stopwatchstopwatch = Stopwatch.createStarted();
// some code with exit pointsreturnstopwatch.elapsed(MILLISECONDS);
It fails on first line with [PrematureDeclaration] Avoid declaring a variable if it is unreferenced before a possible exit point.
The text was updated successfully, but these errors were encountered:
I would even extend this to exclude all calls with side effects
Object o = callWithSideEffects();
// code with exit points
doSomeThing(o);
from this rule. On the one hand, system calls (like reading time) cannot be moved without changing the behavior of the program. On the other hand, callWithSideEffects can do some work/change some state which is needed for the execution of code with exit points.
Affects PMD Version:
6.4.0
Rule:
PrematureDeclaration
Description:
PrematureDeclaration shouldn't trigger on classes which are specific to time measurement. E.g. it fails when stopwatch is used to measure time to invoke entire method (and I'm interested only in sunny-day scenario when exit points are not triggered).
Code Sample demonstrating the issue:
It fails on first line with
[PrematureDeclaration] Avoid declaring a variable if it is unreferenced before a possible exit point.
The text was updated successfully, but these errors were encountered: