Skip to content

[java] UnnecessaryLocalBeforeReturn: ClassCastException in switch case with local variable returned #219

Closed

Description

@davidburstromspotify

Please, prefix the report title with the language it applies to within brackets, such as [java] or [apex]. If not specific to a language, you can use [core]

Rule Set:
UnnecessaryLocalBeforeReturn

Description:

java.lang.ClassCastException: net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement cannot be cast to net.sourceforge.pmd.lang.java.ast.ASTBlock
        at net.sourceforge.pmd.lang.java.rule.design.UnnecessaryLocalBeforeReturnRule.hasAssertStatement(UnnecessaryLocalBeforeReturnRule.java:101)
        at net.sourceforge.pmd.lang.java.rule.design.UnnecessaryLocalBeforeReturnRule.visit(UnnecessaryLocalBeforeReturnRule.java:52)

Code Sample demonstrating the issue:

    public static int m() {
        switch (0) {
            default:
                int i = 0;
                return i;
        }
    }

Running PMD through: Gradle

Activity

  1. self-assigned this
    on Jan 30, 2017
  2. added
    a:bug
    on Jan 30, 2017
  3. added this to the 5.4.5 milestone on Jan 30, 2017
  4. jsotuyod commented on Jan 30, 2017

    @jsotuyod
    Member

    I confirm this is a regression, I just submitted a PR to fix it.

    Thanks for the report!

  5. adangel commented on Jan 30, 2017

    @adangel
    Member

    Thanks for reporting, and @jsotuyod thanks for fixing. Was probably my bad in fixing https://sourceforge.net/p/pmd/bugs/1495/...

  6. changed the title [-][java] 5.5.3, ClassCastException in switch case with local variable returned[/-] [+][java] UnnecessaryLocalBeforeReturn: ClassCastException in switch case with local variable returned[/+] on Jan 30, 2017
  7. added 2 commits that reference this issue on Feb 6, 2017
    1950aeb
    6c75c91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a:bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions