0

Masking NullPointerException will give another delirium to developers as they are bombarded with logic that we are letting Object in memory pointing to null value. If we catch NullPointerException , we are again catching buggy code that takes null value. Ideally, we must stop object taking null input value in code, and being a valid code. I have seen null being passed as parameters in one of object created in code, and code successfully leads user go through activities. How is that possible. Is it risky to implement such implementation which is against NullPointerException norms? As a fallback, we can't even use RuntimeException as it will mask NullPointerException from happening and we won't know buggy code was buggy at first place?

surendrapanday
  • 530
  • 3
  • 13
  • This is way too broad to answer in general. But as a guideline, they are generally the result of missing user input validation or coding errors. – Thilo Feb 24 '19 at 07:29
  • Catching null dereferencing exception is usually a bad idea regardless of the platform/language. If your code allows null for some parameter then handle it explicitly. Otherwise, barring some buggy libraries or etc., just don't do it. Can't find a definitive reference for Java (https://www.quora.com/Is-it-bad-practice-to-catch-null-pointer-exceptions-in-Java), though. – Eugene Podskal Feb 24 '19 at 16:13

1 Answers1

-1

Since you have a tag for Spring, I will share an example. It uses Springboot and Hibernate Validator though but just for information of one way of handling this case ..

http://www.springboottutorial.com/spring-boot-validation-for-rest-services

Ben G
  • 55
  • 8
  • Hi. I’m new to this website. May I please know why this is downvoted. As explained in my answer this was posted only for information as one example as to at what point null was handled not an actual answer. – Ben G Feb 24 '19 at 11:23