Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

potential null access?

 
author & internet detective
Posts: 41263
849
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Eclipse 3.4 and 3.5, I get a warning on the one.length access "The variable one may be null at this location". I've simplified the code as much as possible where I still get the error - the first code block in this post. If I simplify it further - the second block - I do not get the warning.

I'm tempted to turn off this warning since it seems like a false positive. Am I missing something? Bug in Eclipse? Two complex to automate because it is two blocks? As a human, they look like they cover both cases.

Example 1:


Example 2:
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using Eclipse 2.2 and don't get any warnings. So you might just ignore them.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to guess it's simply a matter of how it determines possible null access and it doesn't check if the previous blocks *have* to return because of the additional conditions.

I tried a few re-orderings, grouping with parens, etc. and the only way I got the error to go away was to put in a check for "one".
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Two complex to automate because it is two blocks? As a human, they look like they cover both cases.



Thats true. It covers both the cases. Certainly it cant predict the && expressions as the chances are numerous.

In both && statements , i guess it assumes any statement after "one == null &&" as false , so

one == null && false --> which evaluates to false always , hence chances are both && statements may not get executed and hence restricts for null access.

Ironically i dint see this warning in Eclipse 3.4 SDK. If my previous assumptions are right ,

what happens when

if (one == null && true)
or use single ampersand (&) , just to avoid evaluate both expressions.



 
To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic