lahodaj opened a new pull request, #9450:
URL: https://github.com/apache/netbeans/pull/9450

   There's a `null` checker in `java/java.hints`, `NPECheck`. I am considering 
some updates to it, and, as a preparation for that, I was looking at the 
current `State`s there. There are some weird ones:
   - `NULL_HYPOTHETICAL` and `NOT_NULL_HYPOTHETICAL` - these are meant to cover 
cases like:
   ```
   boolean b = o != null && /*we know o is non-`null` here, marked as 
`NOT_NULL_HYPOTHETICAL`*/ ...;
   //we can't really say much about `o` here, except that we tested it for 
`null`
   ```
   
   the hypothetical states were basically used as "transient state" in 
expressions. I think that with the experience from pattern matching, this is 
overly complex: I think we can simply keep ordinary `NULL`/`NOT_NULL` states, 
but keep them "when true" and "when false", and then use and merge them 
accordingly. This also avoids the need to run conditions twice (once for 
ordinary run, and once for a negated one). Overall, this should make stuff 
simpler.
   
   - `INSTANCE_OF_FALSE` and `INSTANCE_OF_TRUE`. I think the only real thing 
this was doing is code along these lines (or conversely the same with an `if`):
   ```
   class Test {
       public void test(Object o) {
           boolean b = !(o instanceof Integer) && o./*warning here, 
dereferencing possible null*/toString() != null;
        }
   }
   ```
   
   Normally, the NPECheck recognizes several "possible nulls", in particular 
`POSSIBLE_NULL`, which does not produce any warning, and 
`POSSIBLE_NULL_REPORT`, which is used if there's a confirmation the variable 
might be null, like if there's a test for null for the variable, and which 
produces the "possibly dereferencing null` warning. The instanceof states are 
used to make the `instanceof` work as a test for null, but, frankly, it is not: 
we have no firm idea whether `o` can or cannot be `null` if the `instanceof` 
fails. I.e. the behavior of `POSSIBLE_NULL` is more in order here, not the 
`POSSIBLE_NULL_REPORT`. So, this PR is stripping the instanceof states, and 
won't produce a warning in the above case.
   
   ---
   **^Add meaningful description above**
   
   <details open>
   <summary>Click to collapse/expand PR instructions</summary>
   
   By opening a pull request you confirm that, unless explicitly stated 
otherwise, the changes -
   
    - are all your own work, and you have the right to contribute them.
    - are contributed solely under the terms and conditions of the Apache 
License 2.0 (see section 5 of the license for more information).
   
   Please make sure (eg. `git log`) that all commits have a valid name and 
email address for you in the Author field.
   
   If you're a first time contributor, see the Contributing guidelines for more 
information.
   
   If you're a committer, please label the PR before pressing "Create pull 
request" so that the right test jobs can run.
   
   ### PR approval and merge checklist:
   
   1. [ ] Was this PR [correctly 
labeled](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=240884239#PRsandYouAreviewerGuide-PRtriggeredCIJobs(conditionalCIpipeline)),
 did the right tests run? When did they run?
   2. [ ] Is this PR 
[squashed](https://cwiki.apache.org/confluence/display/NETBEANS/git%3A+squash+and+merge)?
   3. [ ] Are author name / email address correct? Are 
[co-authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-the-command-line)
 correctly listed? Do the commit messages need updates?
   3. [ ] Does the PR title and description still fit after the Nth iteration? 
Is the description sufficient to appear in the release notes?
   
   If this PR targets the delivery branch: [don't 
merge](https://cwiki.apache.org/confluence/display/NETBEANS/Pull+requests+for+delivery).
 ([full wiki 
article](https://cwiki.apache.org/confluence/display/NETBEANS/PRs+and+You+-+A+reviewer+Guide))
   
   </details>


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