0

we are migrating code from JDK6/JBoss 5.1 to JDK8/JBoss 7.

In existing codebase, empty string validation was incorrectly written as str!="". However this code is working fine in JBoss 5.1/JDK6. But when trying to run the same code base in JDK8/JBoss 7, the empty string validation is breaking. I fixed this by using str.isEmpty() method. But why it is working differently in JBoss 5.1/JDK6 and JDK8/JBoss 7. The value for string object is retrieved from request.getParameter("<>") statement.

Code Snippet:

String tmpFlag= request.getParameter("Flag");
if( tmpFlag != null && tmpFlag !="" ){
//some logic
}

request.getParameter("Flag"); --> returns "" String in both cases.

Srinivasan
  • 11,718
  • 30
  • 64
  • 92
  • Possibly because of different parameter handling, with `intern()` being used in the earlier version. Lesson to be learned; don't compare Strings incorrectly. – Kayaman Oct 25 '17 at 12:56
  • @Kayaman: I’d rather guess that there was an `if(condition) return "";` somewhere, rather than constructing an empty string and call `intern()`. But the conclusion is the same. – Holger Oct 26 '17 at 08:12

0 Answers0