Affects PMD Version:
6.11.0
Rule:
Description:
I argue that, since Java 8, Runnables are the de-facto standard way to model ()->void
functions. I am aware that the Javadoc says
The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread
yet, there is no substitute in java.util.function
, and until something else is in place, in several cases a delayed computation is modelled through Runnable
, generating a number of false positives.
I'd like to open a discussion on whether the rule should be changed to take into account only Thread
(and, possibily, Executors
and ExecutorService
).
Code Sample demonstrating the issue:
Snippet from Protelis/Protelis
@Override public void eval(final ExecutionContext context) { final AnnotatedTree<?> initBranch = getBranch(INIT); initBranch.evalInNewStackFrame(context, INIT); final S localValue = ensureType(isErased() ? initBranch.getAnnotation() : getSuperscript()); final AnnotatedTree<?> body = getBranch(BODY); ifPresent(localName, it -> context.putVariable(it, localValue, true)); ifPresent(fieldName, it -> context.putVariable(it, context.buildFieldDeferred(i -> i, localValue, body::getAnnotation), true)); context.newCallStackFrame(BODY); final Runnable yieldEvaluation = () -> ifPresent(yield, it -> it.evalInNewStackFrame(context, YIELD)); // Warning, but this is just a delayed computation, no threads involved... if (body instanceof All) { final All multilineBody = (All) body; multilineBody.forEachWithIndex((i, b) -> { context.newCallStackFrame(i.byteValue()); b.eval(context); multilineBody.setAnnotation(b.getAnnotation()); }); yieldEvaluation.run(); multilineBody.forEach(it -> context.returnFromCallFrame()); } else { body.eval(context); yieldEvaluation.run(); } context.returnFromCallFrame(); final S result = ensureType(body.getAnnotation()); setSuperscript(result); setAnnotation(yield.isPresent() ? yield.get().getAnnotation() : (T) result); }
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Vampire and KrzysztofZabolotny
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