Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] InefficientEmptyStringCheck false negative in anonymous class #1224

Closed
maikelsteneker opened this issue Jul 3, 2018 · 1 comment
Closed
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Milestone

Comments

@maikelsteneker
Copy link
Contributor

Affects PMD Version:
6.5.0 and 6.4.0, but not 5.3.0

Rule:
InefficientEmptyStringCheck

Description:
When using an inefficient empty string check inside of an anonymous class, PMD doesn't produce a violation. Moving the code outside of the anonymous class (directly inside of the main method) does produce a violation.

Code Sample demonstrating the issue:

import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class Main {
    public static void main(String[] args) {
        final JPanel jPanel = new JPanel();
        jPanel.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
                final String val = "";
                if (val.trim().length() > 0) {
                    System.out.println("Non-empty string.");
                }
            }

            @Override
            public void keyPressed(KeyEvent e) {
            }

            @Override
            public void keyReleased(KeyEvent e) {
            }
        });
    }
}

Running PMD through: CLI

@adangel adangel added the a:false-negative PMD doesn't flag a problematic piece of code label Jul 3, 2018
@oowekyala oowekyala changed the title [java] InefficientEmptyStringCheck false negative [java] InefficientEmptyStringCheck false negative in anonymous class Nov 5, 2020
oowekyala added a commit to oowekyala/pmd that referenced this issue Nov 5, 2020
@oowekyala oowekyala added this to the 7.0.0 milestone Nov 10, 2020
@adangel
Copy link
Member

adangel commented Dec 11, 2020

Fixed via #2899 for PMD 7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Projects
None yet
Development

No branches or pull requests

3 participants