• Post Reply Bookmark Topic Watch Topic
  • New Topic

Null pointer access. The variable can be null  RSS feed

 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Good Day!

I am trying to understand the message in my eclipse. It says Null Pointer Access. The variable....

As I know, the value at the database can be null or an empty string. I am just adding code to guard the
other data so I created but eclipse is telling me that there is a null pointer access.



I am not sure but is there something wrong in my code? Thanks for the reply.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OR condition is "If both are false then its false" and its gets evaluated in Left to Right.
So where is the error then ?
 
Uli Hofstoetter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


does not make your code null-safe, as the second test will be conducted only if wireSize is null.

Lets play it step by step:

wireSize is not null => "wireSize!= null" resolves to true => whole condition resolves to true => if branch is executed.

wireSize is null => "wireSize!= null" resolves to false => next condition is evaluated => NullPointerException


I guess you wanted to use and (&&):



 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So where is the error then ?


Hi Sagar, thanks for your reply. There's actually no error. It's just my eclipse displaying a warning sign and I wanted to know what is meant by the message.

I guess you wanted to use and (&&):


Hi Uli, Thanks for your explanation, I got your point but I think I dont need the && either.
I change my code into this.


I forgot that an empty string("") in the database is not equal to a null value.

I understand now why eclipse is displaying a message.. Thanks to both of you.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mark reyes wrote:
So where is the error then ?


Hi Sagar, thanks for your reply. There's actually no error. It's just my eclipse displaying a warning sign and I wanted to know what is meant by the message.

Ok, the way I putted it was wrong, I just wanted you to find out where would be the problem lies ?(and not an error !)

And one more thing, you should look out for what Uli suggested, it ll definitely save one line of code ?
 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And one more thing, you should look out for what Uli suggested, it ll definitely save one line of code ?


yes you're right.. Its almost the same. I was caught about the null and empty string thing. Thank you again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!