New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[java] Report unannotated receiver parameter #2030
Comments
Your link is dead, but I found the thread. The receiver parameter is not necessarily useless, as Brian Goetz himself argues in that thread. It's only useless if it is not annotated (or just annotated Feel free to submit a PR |
Yes, I updated the documentation. The tweet content is now embedded. |
Added code sample to description. |
There's also a code sample in here. |
https://bugs.openjdk.java.net/browse/JDK-8195646 Modified code in bug to have another code sample that compiles. That also illustrates why an anonymous class' this must refer to its parent instead since there's no way of referring the anonymous class itself. |
https://coderanch.com/t/708483/java/understanding-implicit-parameter This thread has a great explanation of this keyword right upto receive parameter. |
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8175198 How relevant is this? |
https://github.com/Fernal73/LearnJava/blob/master/Reflection/reflection/SyntheticSample.java A synthetic method in an inner class displays it's signature as consisting of a call to a receiver parameter. |
FYI - I've updated to description to have two examples: one the new rule should detect (e.g. "invalid code") and another one, that should produce no violation (e.g. "valid code") |
Nice. The link that accompanies the valid code example is pretty useful as
well.
|
Is this going to be in PMD 7? |
Affects PMD Version:
All.
Rule:
Suggested Name:
AnnotateReceiverParameter
Non-static methods and constructors should not use "this" as a parameter unless it's annotated. New rule needed.
Description:
Example of code with violation:
A valid code sample:
(from https://www.logicbig.com/tutorials/core-java-tutorial/java-8-enhancements/explicit_receiver_parameters.html)
Best described here:
It can become confusing.
The text was updated successfully, but these errors were encountered: