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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4