Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 563200

Summary: Missing warning "Statement unnecessarily nested within else clause"
Product: [Eclipse Project] JDT Reporter: Clovis Seragiotto <clovis.seragiotto>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: stephan.herrmann
Version: 4.15   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard: stalebug

Description Clovis Seragiotto CLA 2020-05-15 03:45:10 EDT
In this case, a warning "Statement unnecessarily nested within else clause" is issued, as expected:

static void foo(int n) {
    if (n <= 0) return;
    else System.out.println();
}

Also in this case (again as expected):

static void foo(int n) {
    if (n <= 0) return;
    else for(int i = 0; i < 1; i++) System.out.println();
}

But unexpectedly not in this case:

static void foo(int n) {
   if (n <= 0) return;
   else if (n > 0) System.out.println();
}
Comment 1 Stephan Herrmann CLA 2020-05-15 06:32:47 EDT
Without looking at the implementation I guess that "else if" is treated as one thing, differently from plain "else". Would make sense to me.
Comment 2 Eclipse Genie CLA 2022-05-06 13:33:30 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.