You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
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:
Running PMD through: CLI
The text was updated successfully, but these errors were encountered: