Skip to content

SF_SWITCH_FALLTHROUGH false positive since SpotBugs-4.9.4 #3645

@rovarga

Description

@rovarga

The following code causes a false positive report:

[ERROR] Medium: Switch statement found in org.opendaylight.yangtools.yang.parser.stmt.reactor.BuildGlobalContext.completePhaseActions() where one case falls through to the next case [org.opendaylight.yangtools.yang.parser.stmt.reactor.BuildGlobalContext] At BuildGlobalContext.java:[lines 320-327] SF_SWITCH_FALLTHROUGH

Version 4.9.3 is fine, so I suspect this has to do with #3574 and the bytecode which is being generated by javac-21 here:

       131: invokedynamic #443,  0            // InvokeDynamic #1:enumSwitch:(Lorg/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext$PhaseCompletionProgress;I)I
       136: tableswitch   { // -1 to 2
                      -1: 178
                       0: 186
                       1: 197
                       2: 202
                 default: 168
            }
       168: new           #447                // class java/lang/MatchException
       171: dup
       172: aconst_null
       173: aconst_null
       174: invokespecial #449                // Method java/lang/MatchException."<init>":(Ljava/lang/String;Ljava/lang/Throwable;)V
       177: athrow
       178: new           #452                // class java/lang/NullPointerException
       181: dup
       182: invokespecial #454                // Method java/lang/NullPointerException."<init>":()V
       185: athrow
       186: aload_3
       187: invokeinterface #455,  1          // InterfaceMethod java/util/Iterator.remove:()V
       192: iconst_1
       193: istore_2
       194: goto          202
       197: iconst_1
       198: istore_2
       199: goto          202
       202: goto          216
       205: astore        5
       207: aload_0
       208: aload         4
       210: aload         5
       212: invokevirtual #324                // Method propagateException:(Lorg/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext;Ljava/lang/RuntimeException;)Lorg/opendaylight/yangtools/yang/parser/spi/meta/SomeModifiersUnresolvedException;
       215: athrow
       216: goto          86

and following entries in the line number table:

        line 313: 120
        line 314: 178
        line 316: 186
        line 318: 192
        line 319: 194
        line 320: 197
        line 327: 202
        line 325: 205
        line 326: 207
        line 328: 216
        line 329: 219

The source code is using arrow cases, hence there is no way this is a fall-through. The bytecode clearly shows that the progress = true is part is duplicated (at 192 and 197), from whence the both cases take a jump to 202 and then jump to 86 (to continue the while() loop).

I suspect it is the NO_PROGRESS case being a no-op which is causing the confusion here.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions