Bug 136512 - `(String) + (null)` gives "may be null" warning
Summary: `(String) + (null)` gives "may be null" warning
Status: RESOLVED DUPLICATE of bug 127919
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-12 21:46 EDT by Sarah Gerweck CLA
Modified: 2006-04-13 07:22 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sarah Gerweck CLA 2006-04-12 21:46:54 EDT
When concatenating a string with a possibly null variable using the `+` operator, Eclipse 3.2M5a gives a warning if _Null reference_ is set in Compiler->Errors/Warnings.

Actually, the Java compiler allows nulls in this context and deliberately inserts the string "null". See the Java Language Specification, ยง15.18.1 [http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#39990].

While some might argue that a warning here is still meritable, I'd suggest a special case in the JLS wins the argument. I would think a checkbox to allow personal preference reasonable; absent a toggle there should be no warning.

The JLS has this special case for a reason. For example, lots of code traps nulls and logs and/or throws an exception indicating the problem:

  if (folderName == null || !FOLDER_PATTERN.matches(folderName))
      throw new BadFolderException("Folder " + folderName + " is invalid");

The whole purpose of the JLS's explicit null handling here is to avoid silly code like this:
          folderName == null ? "null" : folderName
Comment 1 Maxime Daniel CLA 2006-04-13 07:22:22 EDT
This has been fixed with M6.

*** This bug has been marked as a duplicate of 127919 ***