0

Do System.getProperty("line.separator") and System.getProperty("os.name") always have values?

Or do I need to check the return value in the code for null?

4J41
  • 5,005
  • 1
  • 29
  • 41
Mahsa
  • 85
  • 1
  • 11

2 Answers2

1

Yes, they are inserted automatically by the JVM

David Rabinowitz
  • 29,904
  • 14
  • 93
  • 125
0

The question is: can your code handle a null? If yes check for it, even if it is extremely unrealistic that this part of the code will ever be called, if not add a if null -> terminate concept, if that might cause trouble otherwise.

While the JVM will insert this for you, there are still two cases left where you can get null:

  • The JVM has a bug
  • Someone in the background deletes these properties.

None of these cases is likely enough to require to handle them by default.

TwoThe
  • 13,879
  • 6
  • 30
  • 54