matthiasblaesing commented on pull request #3206:
URL: https://github.com/apache/netbeans/pull/3206#issuecomment-954103511


   I think I found the issue and I think it is a bug in Jackpot. The exception 
is raised when the fake class for `JCVariableDecl` is being created. The 
constructor is looked up with 
   
   ```java
   new Class<?>[] {JCModifiers.class, Name.class, JCExpression.class, 
JCExpression.class, VarSymbol.class}
   ```
   
   or
   
   ```java
   new Class<?>[] {JCModifiers.class, Name.class, JCExpression.class, 
JCExpression.class, VarSymbol.class, List.class}
   ```
   
   The code, that does the lookup is found here
   
   
https://github.com/apache/netbeans/blob/76448e5011d37650a804a9a1c4fdf36f676807f3/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/JackpotTrees.java#L88-L100
   
   JDK 17 declares 3 constructors for `JCVariableDecl` (see: 
https://github.com/openjdk/jdk/blob/jdk-17+35/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java#L983-L1016)
   
   1. `JCModifiers, Name, JCExpression, JCExpression, VarSymbol`
   2. `JCModifiers, Name, JCExpression, JCExpression, VarSymbol, boolean`
   3. `JCModifiers, JCExpression, JCExpression`
   
   Only the first constuctor lookup described at the start of this article is 
relevant, as the second lookup does not match none of the constructors. The 
issue is, that the first lookup has to matching constructors: 1 + 2.
   
   And indeed debugging I see this:
   
   **Working case (Zulu, Adoptium)**
   
   
![image](https://user-images.githubusercontent.com/2179736/139313875-ad7235b6-b6a9-4480-94ba-9e866fc2eb4e.png)
   
   **Failing case (Ubuntu JDK 11)**
   
   
![image](https://user-images.githubusercontent.com/2179736/139313949-ea7bce06-ddde-45ca-ab40-5f2a8c67502f.png)
   
   In the failing case, the constructor has the required minimum number of 
parameters (check in line 89) and starts with the right parameter types (check 
in lines 91-95), but the final primitive boolean parameter is most probably the 
problem. In line 99 missing parameters are replaced with `null`. Now the VM 
either throws because it can't unbox `null` to a `boolean` or because a 
primitive can't be set from a reference.
   
   The problem is present on both JDKs, it only materializes on the Ubuntu JDK, 
because there the constructors are returned in a different order, than on the 
Zulu and Adoptium builds. But this is _not_ a bug in Ubuntu, as there is no 
guaranteed order (at least it is missing from the method documentation: 
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html#getConstructors())
   
   I think `JackpotTrees#createInstance` could be stabilized by
   - preferring exactly matching constructors
   - ignoring constructors, that can't be satisfied by extending parameter list 
with null (i.e. which have primitive arguments beyond the supplied arguments)
   
   @jlahoda what do you think?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to