Bug 444969 - [xtend][validation] Validation ‘Missing default branch for switch expression with primitive type‘ is bogus
Summary: [xtend][validation] Validation ‘Missing default branch for switch expression ...
Status: NEW
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-24 10:21 EDT by Anton Kosyakov CLA
Modified: 2016-06-10 05:56 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Kosyakov CLA 2014-09-24 10:21:45 EDT
The following method produces a warning and it is fine:
def boolean foo(Object value) {
	switch value {
		String: true
	}
}

But a similar method with inferred boolean type does not produce a warning:
def foo(Object value) {
	switch value {
		String: true
	}
}

A method with explicit declared boolean type, but with Boolean inferred type for switch expression does not produce a warning also:
def boolean foo(Object value) {
	switch value {
		case String: Boolean.TRUE
	}
}

though the generated Java code can throw a NPE:
public boolean foo(final Object value) {
    Boolean _switchResult = null;
    boolean _matched = false;
    if (!_matched) {
      if (value instanceof String) {
        _matched=true;
        _switchResult = Boolean.TRUE;
      }
    }
    return (_switchResult).booleanValue(); // NullPointerException if a value is not of String type
}