GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] UnusedAssignment FP in try/catch · Issue #2684 · pmd/pmd

[java] UnusedAssignment FP in try/catch #2684

New issue
Copy link
New issue
Copy link
Closed
#2703
Closed
[java] UnusedAssignment FP in try/catch#2684
#2703
Copy link
Assignees
oowekyala
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.27.0

Description

@kris-scheibe
kris-scheibe
opened on Jul 31, 2020
Issue body actions

Affects PMD Version: 6.26.0 (and 6.27.0-SNAPSHOT)

Rule: UnusedAssignment

Description:
A method-call within a try-block might fail and its result shouldn't be treated as a guaranteed assignment.

Code Sample demonstrating the issue:

public class Foo {

    public int foo() {
        int a = 0; // <--- false-positive UnusedAssignment
        try (Reader r = new StringReader("")) {
            a = r.read(); // might assign or fail
            a = r.read(); // might assign or fail
        } catch (IOException e) {
        }
        return a;
    }

}

Expected outcome:

  • Both the first and second read might fail. All assignments to the variable a are useful, depending on whether one of the read()'s fails -> false-positive

Running PMD through: Other

Activity

  1. kris-scheibe
    added
    a:bugPMD crashes or fails to analyse a file.
    on Jul 31, 2020
  2. oowekyala
    added
    a:false-positivePMD flags a piece of code that is not problematic
    and removed
    a:bugPMD crashes or fails to analyse a file.
    on Jul 31, 2020
  3. oowekyala
    self-assigned this
    on Aug 6, 2020
  4. oowekyala
    added
    has:pr
    on Aug 6, 2020
  5. oowekyala
    added this to the 6.27.0 milestone on Aug 6, 2020
  6. adangel
    closed this as completedin #2703on Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @oowekyala
    oowekyala

Labels

a:false-positivePMD flags a piece of code that is not problematic

Type

No type

Projects

No projects

    Milestone

    • 6.27.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.