mbien commented on PR #8930:
URL: https://github.com/apache/netbeans/pull/8930#issuecomment-3419435065

   @jlahoda added tests for the hint.
   
   There is one curiosity though: initially I wanted to add test cases to the 
`UnusedDetectorTest`, since it would be the most direct way to validate the 
functionality.
   
   e.g:
   
   ```java
       @Test
       public void testNoUnusedPackagePrivateClass() throws Exception {
           performTest(
                   "test/Test.java",
                   """
                   package test;
                   class Test {
                        Test() {}
                   }
                   """
           );
       }
   ```
   
   However, it would fail since returns package private top level 
classes/interfaces/records.. etc as unused. 
   ```
   Testcase: 
testUnusedPackagePrivateClass(org.netbeans.modules.java.editor.base.semantic.UnusedDetectorTest):
  FAILED
   expected:<[]> but was:<[3:<init>:NOT_USED]>
   ```
   I debugged through it and it correctly marks the class declaration as used, 
but later sees an synthetic constructor and marks that as unused. I believe 
what is happening afterwards is that since synthetic items have no line 
numbers, it maps the unused line to the class declaration so that it looks as 
if it would think that the class should be marked as unused. (constructor name 
== class name too so the error line becomes indistinguishable)
   
   So why does the hint work?
   the hint then drops the item at 
https://github.com/apache/netbeans/blob/8e2bc77e581e04ab1b52575b16d61fc3ff95bcfe/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Unused.java#L70
   
   That is why the junit test works as expected for the hint, while the 
`UnusedDetector` produces technically wrong output in that case.
   
   However, changing this is not required to resolve this issue and it would be 
unnecessarily risky for the release. We should probably fix this at some point 
though.
   
   I think this can get in as is (+ the added hint tests)


-- 
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