DEV Community

Sivaram Rasathurai
Sivaram Rasathurai

Posted on

Remove Java Developers NullPointerException Hell

  1. NullUtil.executeViaNullSafer method will execute the given function on Non-Null Values and, when the value is null It will return Null instead of executing the function.

  2. NullUtil.executeExecutorOrDefault method will execute the given function on Non-Null Values and, If the value is null, It will return the given default value.

  3. NullUtil.executeMutator method mutates the reference type values without returning anything. If the value is null, It will not do anything.

  4. NullUtil.replaceNull method will replace the null value with the given defaultValue. when the value is not null, It will return the value.

  5. NullUtil.hasText method is used to check the String value has any kind of text or not
    .

  6. NullUtil.trimValue method will be used to trim the String without causing the null pointer Exception.

More details about this Util class you can find on my medium article(https://rcvaram.medium.com/remove-dirty-nullchecks-in-java-8aca833dc276) or my stackoverflow answer(https://stackoverflow.com/a/70200959/12894468).

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay