Bug 575869 - [17][switch pattern] case null with type pattern in that order does not compile
Summary: [17][switch pattern] case null with type pattern in that order does not compile
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.21   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.22 M3   Edit
Assignee: Manoj N Palat CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-08 04:57 EDT by Manoj N Palat CLA
Modified: 2021-11-11 02:31 EST (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 Manoj N Palat CLA 2021-09-08 04:57:40 EDT
Created the test case on the basis of a note from Remi (Thanks)!

Given:
public class X {	
	private int foo(Integer o) {		
		switch(o) {
		  case null, Integer i -> System.out.println("hh");
		}
		return 0;
	}
}

This gives an "Illegal fall-through error". 
As per the JEP. 406 Section 14.11.1, this is allowed:

"If a switch label has a null case label element then if the switch label also has any pattern case element labels, they must be type patterns (14.30.1)."

On a side-note, "case Integer i, null -> " works.

This fell through the cracks although we had a test case (testBug574563_002) covering this scenario but had additional errors which did not cause this error.
Comment 1 Eclipse Genie CLA 2021-09-08 05:42:08 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/185138
Comment 2 Eclipse Genie CLA 2021-09-27 06:00:55 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/185850
Comment 4 Stephan Herrmann CLA 2021-10-24 17:08:29 EDT
This change makes NullAnnotationTests17.test_switchNullInSameCase() fail.

While it's easy to adjust the test expectation I wonder if gerrit jobs actually test against JRE 17 / with -Dcompliance=17?
Comment 5 Stephan Herrmann CLA 2021-10-26 09:24:51 EDT
(In reply to Stephan Herrmann from comment #4)
> This change makes NullAnnotationTests17.test_switchNullInSameCase() fail.
> 
> While it's easy to adjust the test expectation I wonder if gerrit jobs
> actually test against JRE 17 / with -Dcompliance=17?

After updating the gerrit jenkins job to JRE 17 & compliance 17, those builds consistently fail for this bug and bug 576026. To unblock that deadlock, I'm fixing both issues in one gerrit: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/186875
Comment 6 Stephan Herrmann CLA 2021-10-26 09:29:53 EDT
I should add, that adjusting the expectation wasn't exactly a good idea: previously, null analysis didn't have to care about "case null, Integer i -> " because originally that was illegal to begin with. The gerrit enhances analysis to detect that 'i' is potentially null in this situation.
Comment 7 Stephan Herrmann CLA 2021-10-26 12:04:33 EDT
(In reply to Stephan Herrmann from comment #5)
> (In reply to Stephan Herrmann from comment #4)
> > This change makes NullAnnotationTests17.test_switchNullInSameCase() fail.
> > 
> > While it's easy to adjust the test expectation I wonder if gerrit jobs
> > actually test against JRE 17 / with -Dcompliance=17?
> 
> After updating the gerrit jenkins job to JRE 17 & compliance 17, those
> builds consistently fail for this bug and bug 576026. To unblock that
> deadlock, I'm fixing both issues in one gerrit:
> https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/186875

This regression fix has been released to master.
Comment 8 Manoj N Palat CLA 2021-10-27 03:22:14 EDT
(In reply to Stephan Herrmann from comment #7)
> 
> This regression fix has been released to master.

@Stephan: Thanks a lot for taking care of the regression - got busy with the sessions in EclipseCon in the last two days - catching up on the bugs now. Since JEP 420 draft is out for second preview, I have added Bug 576910 as a separate bug for null analysis there to check for any changes due to the delta in the new jep.
Comment 9 Jay Arthanareeswaran CLA 2021-11-11 02:31:44 EST
Verified for 4.22 M3 using build I20211110-1800