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
[jackpot] Attempt to make JackpotTrees more robust. #3283
Conversation
mbien
commented
Oct 28, 2021
•
edited
edited
- JackpotTrees.createInstance() will match constructors directly - no filling up with null objects anymore
- extracted typesafe factory methods to keep the fragile code in one place and make it hopefully easier to update it in future
i am surprised about this requirement given the code styles i have seen so far. The lambda in question is fairly concise and should be easy to read. The indentation makes it difficult to misinterpret what is going there. |
@jlahoda should I remove the logic which fills unknown params with null values? Current impl won't fill primitives but will still fill objects. I was hesitant in doing this because I thought there might be some JDK version compatibility issue this was supposed to solve - so i didn't want to cause a regression. |
My take on this: If I want indention based syntax, I go to python. I had to look at it multiple times to see the right indentions and blocks. I looked through other classes in This is what I had in mind: IMHO lambdas get messy quickly if people put to much code in them and even more if braces are missing. |
I didn't want to change the language just to fix this method :)
I have seen files which looked like they tried intentionally to avoid any kinds of newlines. To achive that they re-assigning method params, inside other assignments or declarations. While loops without bodies, and i just replaced a for loop which used continue labels with this patch. I don't actually mind having braces in that lambda i was just surprised to get that requirement, given the context.
I can see that |
but to bring this back to the more interesting questions:
@jlahoda ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make this formal - please add braces for if
and for
statements.
For the question: Could it happen with NB 12.6? Yes it could - the conflicting constructors are there (disassembled from the referenced binary): protected JCVariableDecl(JCModifiers mods, Name name, JCExpression vartype, JCExpression init, Symbol.VarSymbol sym) {
this(mods, name, vartype, init, sym, false);
}
protected JCVariableDecl(JCModifiers mods, Name name, JCExpression vartype, JCExpression init, Symbol.VarSymbol sym, boolean declaredUsingVar) {
this.mods = mods;
this.name = name;
this.vartype = vartype;
this.init = init;
this.sym = sym;
this.declaredUsingVar = declaredUsingVar;
} I don't see it though, but we don't know what influences the reported order of the constructors. |
i did some archeological digging to check usages and call site compatibility to get a better picture if a direct constructor match would work. Two instances are created using JackpotTrees: // JDK 8+11
JCCase(JCExpression pat, List<JCStatement> stats)
// JDK 12-18
JCCase(CaseKind caseKind, List<JCCaseLabel> labels, List<JCStatement> stats, JCTree body) // JDK 8+11
JCVariableDecl(JCModifiers mods, Name name, JCExpression vartype, JCExpression init, VarSymbol sym)
JCVariableDecl(JCModifiers mods, JCExpression nameexpr, JCExpression vartype)
// JDK ?-18
JCVariableDecl(JCModifiers mods, Name name, JCExpression vartype, JCExpression init, VarSymbol sym)
JCVariableDecl(JCModifiers mods, Name name, JCExpression vartype, JCExpression init, VarSymbol sym, boolean declaredUsingVar)
JCVariableDecl(JCModifiers mods, JCExpression nameexpr, JCExpression vartype) Given the new knowledge i don't think the filling-params-with-null logic was of any help so far. There is also a bytebuddy code path selectively calling the I did the following:
lets see if the tests are ok with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me, thanks! (Seems the braces have been added.) Overall, I hope at some point we will only need to support ~1 version of the APIs/internal APIs, at which point we should be able to avoid all this reflection and class construction.
@mbien thanks for working through this and @jlahoda thank you for the review. As the analysis showed, that the problem could happen with the nbjavac version currently targetted for 12.6, I think we should retarget this to delivery. As delivery and master did not diverge that much, I suggest this approach (if you don't need the instructions, just ignore them):
After this you should only have a single commit in it. |
java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/JackpotTrees.java
Outdated
Show resolved
Hide resolved
- JackpotTrees.createInstance() will match constructors directly (no unknown parameter filling with null anymore) - extracted typesafe factory methods to keep the fragile code in one place and make it hopefully easier to update it in future
- removed ByteBuddy interceptor and dead code path
- removed ByteBuddy interceptor and dead code path - less reflection
- removed ByteBuddy interceptors and dead code path - less reflection