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.

Add Null checking where applicable

See original GitHub issue

Methods annotated by @NotNull should produce a NullPointerException if invoked by a null argument. As of now, only intent is indicated.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JerrySheacommented, Nov 21, 2020

If you compile in intellij then it automatically does this instrumentation btw.

My dream is that the compiler can do all this for us i.e. confirm at compile time. There are a few tools I have looked at:

  • the combination of NullAway+ErrorProne seems to be reasonably lightweight
  • the checkers framework has good support this but adds a bit of time to your compile

Unfortunately both of these work the opposite way to IntelliJ: IntelliJ assumes that everything is nullable unless you explicitly annotate with @NotNull whereas both of these tools assume the opposite. I believe that you can configure the checkers framework to work the same way as Intellij but I have not spent the time.

If we were to follow the compile time static analysis approach on all our products then we could that all our null-related contracts are being respected, although our customers would not get the same assurances for their code.

0reactions
minborgcommented, Nov 20, 2020

After some consideration, I agree with you @JerryShea . There are some potentially dangerous corner cases that may be affected by instrumentation. It is better to explicitly use Objects.requireNonNull() where applicable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add null checks for all (parameters) - Visual Studio
Learn how to create and add if statements to your code that check nullity of all the nullable, non-checked parameters.
Read more >
visualstudio-docs/add-null-checks-for-parameters.md at main
Learn how to create and add if statements to your code that check nullity of all the nullable, non-checked parameters. SEO-VS-2020. 09/17/2019.
Read more >
How do I check for null values in JavaScript?
I'm going to do something that is almost never a good idea: change the code in this answer. Specifically, remove the totally unnecessary...
Read more >
Null Checking | ReSharper Documentation
Use this page to customize generating null-checking routines for exceptions and assertions. Null checks for exceptions and assertions.
Read more >
Working with SQL NULL values
For example, in the following query, the ISNULL() function replaces the NULL values in the row with the specified value.
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