question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Null pointers/nullable

See original GitHub issue

I can see that most of the issues marked as “bugs” in SonarCloud are Null pointers should not be dereferenced which risks throwing a NullReferenceException

Issues: https://sonarcloud.io/project/issues?resolved=false&rules=csharpsquid%3AS2259&types=BUG&id=apache_lucenenet

As an example I looked into this issue: https://sonarcloud.io/project/issues?issues=AYRH0TRT_qq9ReJdi4pi&open=AYRH0TRT_qq9ReJdi4pi&id=apache_lucenenet

Here I tracked the newest version of the code down here: https://github.com/apache/lucene/blob/7c130d2f07e00fd8725cf7e22cc268dd4331fbbe/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ConvTable.java#L59

Which is similar to the version we have which should therefore mean that the same issue is still present in the Java version too? Therefore I’m wondering what’s the best approach for fixing these errors or if they should be fixed at all. It’s very possible that it’s next to impossible to encounter this error in a real world scenario. (I haven’t looked too much into how it’s used).

And related to this, would it make sense to enable the Nullable feature across the project to give a informative public API for the developers using Lucene.NET? Here we could mark variables and parameters that can be null at some point. This should be possible to do step by step by adding the #nullable enable that I can see you’ve used in some files.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
NightOwl888commented, Nov 2, 2022

Well, that is because you know what you are doin’ 😃.

But those mere mortals who allow a null to pass into one of our APIs might be chasing their tail for awhile because the null gets passed down through 5 or so more APIs before it hits the one that throws. A guard clause makes the stack trace much more explicit as to where the problem lies. And who knows how long they will chase their tail if they don’t even have a vague notion that they can turn on asserts.

What has been most enlightening about the scan is that it is pointing us to very specific areas that have a small problem, and in several instances it led to finding a much bigger problem in the same area. Even though the scan didn’t pick it up the bigger problem as an issue.

2reactions
NightOwl888commented, Nov 2, 2022

I don’t think you guys appreciate the power that the scan gave us. It turned ~1500 hours of unspecified work with a vague notion of “let’s fix the main APIs first” into a very targeted few dozen hours of work to hit the most problematic areas first. All while avoiding having to change exception behavior in a breaking way after the release.

Sure, this was near the bottom in terms of priority - and still is - but having a hard target to hit bumps it up a bit in my opinion. Clean up the squeaky wheels that the scan gave us, and then fix the rest at some point after the release (most notably, the APIs that allow null that the scan isn’t showing us).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nullable variable throws NullPointerException on get()
1 Answer 1 ... It's saying you're trying to call getCode() on something that's null, instead of an actual CountryCodeValue object. null doesn't ......
Read more >
Nothing is better than the Optional type. Really. ...
Nullness Checker uses powerful analysis to keep track of whether a reference might be null. By comparison to the use of Optional, this...
Read more >
Protect Your Code from NullPointerExceptions with ...
Null -safety ensures that we have added proper checks in the code to guarantee the object reference cannot be null or possible safety...
Read more >
When do the benefits of nullable value types outweigh ...
Having a null pointer means there is no chance that there will ever be a value to be obtained by using that particular...
Read more >
The Best Article You'll Ever Need to Understand Kotlin Null ...
In this tutorial on Kotlin Null safety, you understand various topics, including Non-nullable types and Nullable types, Causes of Null pointer ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found