Showing 1,951 of 1,951 total issues
Avoid variables with short names like g Open
Graphics g = stitchedImage.getGraphics();
- Read upRead up
- Exclude checks
ShortVariable
Since: PMD 0.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Fields, local variables, or parameter names that are very short are not helpful to the reader.
Example:
public class Something {
private int q = 15; // field - too short
public static void main( String as[] ) { // formal arg - too short
int r = 20 + q; // local var - too short
for (int i = 0; i < 10; i++) { // not a violation (inside 'for' loop)
r += q;
}
for (Integer i : numbers) { // not a violation (inside 'for-each' loop)
r += q;
}
}
}
Avoid if (x != y) ..; else ..; Open
if (baseUri != null) {
return uri == null ? baseUri.toString() : baseUri.resolve(uri).toString();
} else if (uri != null) {
return uri.toString();
} else {
- Read upRead up
- Exclude checks
ConfusingTernary
Since: PMD 1.9
Priority: Medium
Categories: Style
Remediation Points: 50000
Avoid negation within an 'if' expression with an 'else' clause. For example, rephrase: if (x != y) diff(); else same();
as: if (x == y) same(); else diff();
. Most 'if (x != y)' cases without an 'else' are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, such as 'does the error case go first?' or 'does the common case go first?'.
Example:
boolean bar(int x, int y) {
return (x != y) ? diff : same;
}
The user-supplied array 'args' is stored directly. Open
public ReflectiveWebDriverFactory(String name, Class<? extends WebDriver> webDriverClass, Object... args) {
- Read upRead up
- Exclude checks
ArrayIsStoredDirectly
Since: PMD 2.2
Priority: Medium
Categories: Style
Remediation Points: 50000
Constructors and methods receiving arrays should clone objects and store the copy. This prevents future changes from the user from affecting the original array.
Example:
public class Foo {
private String [] x;
public void foo (String [] param) {
// Don't do this, make a copy of the array at least
this.x=param;
}
}
Consider simply returning the value vs storing it in local variable 'untilPredicate' Open
return untilPredicate;
- Read upRead up
- Exclude checks
UnnecessaryLocalBeforeReturn
Since: PMD 3.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Avoid the creation of unnecessary local variables
Example:
public class Foo {
public int foo() {
int x = doSomething();
return x; // instead, just 'return doSomething();'
}
}
Avoid variables with short names like s Open
public void afterGetText(WebElement webElement, WebDriver webDriver, String s) {
- Read upRead up
- Exclude checks
ShortVariable
Since: PMD 0.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Fields, local variables, or parameter names that are very short are not helpful to the reader.
Example:
public class Something {
private int q = 15; // field - too short
public static void main( String as[] ) { // formal arg - too short
int r = 20 + q; // local var - too short
for (int i = 0; i < 10; i++) { // not a violation (inside 'for' loop)
r += q;
}
for (Integer i : numbers) { // not a violation (inside 'for-each' loop)
r += q;
}
}
}
Avoid if (x != y) ..; else ..; Open
return (page != null) ? page : fluentWebElement;
- Read upRead up
- Exclude checks
ConfusingTernary
Since: PMD 1.9
Priority: Medium
Categories: Style
Remediation Points: 50000
Avoid negation within an 'if' expression with an 'else' clause. For example, rephrase: if (x != y) diff(); else same();
as: if (x == y) same(); else diff();
. Most 'if (x != y)' cases without an 'else' are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, such as 'does the error case go first?' or 'does the common case go first?'.
Example:
boolean bar(int x, int y) {
return (x != y) ? diff : same;
}
Avoid variables with short names like is Open
InputStream is = Files.newInputStream(Paths.get(fileName));
- Read upRead up
- Exclude checks
ShortVariable
Since: PMD 0.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Fields, local variables, or parameter names that are very short are not helpful to the reader.
Example:
public class Something {
private int q = 15; // field - too short
public static void main( String as[] ) { // formal arg - too short
int r = 20 + q; // local var - too short
for (int i = 0; i < 10; i++) { // not a violation (inside 'for' loop)
r += q;
}
for (Integer i : numbers) { // not a violation (inside 'for-each' loop)
r += q;
}
}
}
Avoid variables with short names like g Open
private void drawStringMultiLine(Graphics g, String text, int lineWidth) {
- Read upRead up
- Exclude checks
ShortVariable
Since: PMD 0.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Fields, local variables, or parameter names that are very short are not helpful to the reader.
Example:
public class Something {
private int q = 15; // field - too short
public static void main( String as[] ) { // formal arg - too short
int r = 20 + q; // local var - too short
for (int i = 0; i < 10; i++) { // not a violation (inside 'for' loop)
r += q;
}
for (Integer i : numbers) { // not a violation (inside 'for-each' loop)
r += q;
}
}
}
Avoid if (x != y) ..; else ..; Open
} else if (uri != null) {
return uri.toString();
} else {
return null;
}
- Read upRead up
- Exclude checks
ConfusingTernary
Since: PMD 1.9
Priority: Medium
Categories: Style
Remediation Points: 50000
Avoid negation within an 'if' expression with an 'else' clause. For example, rephrase: if (x != y) diff(); else same();
as: if (x == y) same(); else diff();
. Most 'if (x != y)' cases without an 'else' are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, such as 'does the error case go first?' or 'does the common case go first?'.
Example:
boolean bar(int x, int y) {
return (x != y) ? diff : same;
}
Avoid if (x != y) ..; else ..; Open
if (mockName != null) {
return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName));
} else {
return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType));
}
- Read upRead up
- Exclude checks
ConfusingTernary
Since: PMD 1.9
Priority: Medium
Categories: Style
Remediation Points: 50000
Avoid negation within an 'if' expression with an 'else' clause. For example, rephrase: if (x != y) diff(); else same();
as: if (x == y) same(); else diff();
. Most 'if (x != y)' cases without an 'else' are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, such as 'does the error case go first?' or 'does the common case go first?'.
Example:
boolean bar(int x, int y) {
return (x != y) ? diff : same;
}
The user-supplied array 'args' is stored directly. Open
public MethodInvocationReflectionFactory(Method method, Object instance, Object... args) {
- Read upRead up
- Exclude checks
ArrayIsStoredDirectly
Since: PMD 2.2
Priority: Medium
Categories: Style
Remediation Points: 50000
Constructors and methods receiving arrays should clone objects and store the copy. This prevents future changes from the user from affecting the original array.
Example:
public class Foo {
private String [] x;
public void foo (String [] param) {
// Don't do this, make a copy of the array at least
this.x=param;
}
}
Document empty method body Open
public void verifyIsLoaded() {
}
- Read upRead up
- Exclude checks
UncommentedEmptyMethodBody
Since: PMD 3.4
Priority: Medium
Categories: Style
Remediation Points: 50000
Uncommented Empty Method Body finds instances where a method body does not contain statements, but there is no comment. By explicitly commenting empty method bodies it is easier to distinguish between intentional (commented) and unintentional empty methods.
Example:
public void doSomething() {
}
Avoid unused local variables such as 'converted'. Open
long converted = (Long) value;
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: PMD 0.1
Priority: Medium
Categories: Style
Remediation Points: 50000
Detects when a local variable is declared and/or assigned, but not used.
Example:
public class Foo {
public void doSomething() {
int i = 5; // Unused
}
}
A class which only has private constructors should be final Open
public class PredefinedDesiredCapabilities {
private PredefinedDesiredCapabilities() {
// intentionally blank
}
- Read upRead up
- Exclude checks
ClassWithOnlyPrivateConstructorsShouldBeFinal
Since: PMD 4.1
Priority: High
Categories: Style
Remediation Points: 50000
A class with only private constructors should be final, unless the private constructor is invoked by a inner class.
Example:
public class Foo { //Should be final
private Foo() { }
}
The user-supplied array 'args' is stored directly. Open
public ReflectiveCapabilitiesFactory(String name, Class<? extends Capabilities> capabilitiesClass, Object... args) {
- Read upRead up
- Exclude checks
ArrayIsStoredDirectly
Since: PMD 2.2
Priority: Medium
Categories: Style
Remediation Points: 50000
Constructors and methods receiving arrays should clone objects and store the copy. This prevents future changes from the user from affecting the original array.
Example:
public class Foo {
private String [] x;
public void foo (String [] param) {
// Don't do this, make a copy of the array at least
this.x=param;
}
}
Avoid variables with short names like s Open
public void on(String s, WebDriver driver) {
- Read upRead up
- Exclude checks
ShortVariable
Since: PMD 0.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Fields, local variables, or parameter names that are very short are not helpful to the reader.
Example:
public class Something {
private int q = 15; // field - too short
public static void main( String as[] ) { // formal arg - too short
int r = 20 + q; // local var - too short
for (int i = 0; i < 10; i++) { // not a violation (inside 'for' loop)
r += q;
}
for (Integer i : numbers) { // not a violation (inside 'for-each' loop)
r += q;
}
}
}
Avoid variables with short names like m Open
FontMetrics m = g.getFontMetrics();
- Read upRead up
- Exclude checks
ShortVariable
Since: PMD 0.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Fields, local variables, or parameter names that are very short are not helpful to the reader.
Example:
public class Something {
private int q = 15; // field - too short
public static void main( String as[] ) { // formal arg - too short
int r = 20 + q; // local var - too short
for (int i = 0; i < 10; i++) { // not a violation (inside 'for' loop)
r += q;
}
for (Integer i : numbers) { // not a violation (inside 'for-each' loop)
r += q;
}
}
}
New exception is thrown in catch block, original stack trace may be lost Open
throw new ChromiumApiNotSupportedException("API supported only by Chrome and Edge", ex.getCause());
- Read upRead up
- Exclude checks
PreserveStackTrace
Since: PMD 3.7
Priority: Medium
Categories: Style
Remediation Points: 50000
Throwing a new exception from a catch block without passing the original exception into the new exception will cause the original stack trace to be lost making it difficult to debug effectively.
Example:
public class Foo {
void good() {
try{
Integer.parseInt('a');
} catch (Exception e) {
throw new Exception(e); // first possibility to create exception chain
}
try {
Integer.parseInt('a');
} catch (Exception e) {
throw (IllegalStateException)new IllegalStateException().initCause(e); // second possibility to create exception chain.
}
}
void bad() {
try{
Integer.parseInt('a');
} catch (Exception e) {
throw new Exception(e.getMessage());
}
}
}
The user-supplied array 'args' is stored directly. Open
public void setArgs(Object[] args) {
- Read upRead up
- Exclude checks
ArrayIsStoredDirectly
Since: PMD 2.2
Priority: Medium
Categories: Style
Remediation Points: 50000
Constructors and methods receiving arrays should clone objects and store the copy. This prevents future changes from the user from affecting the original array.
Example:
public class Foo {
private String [] x;
public void foo (String [] param) {
// Don't do this, make a copy of the array at least
this.x=param;
}
}
Avoid variables with short names like s Open
public void afterSwitchToWindow(String s, WebDriver webDriver) {
- Read upRead up
- Exclude checks
ShortVariable
Since: PMD 0.3
Priority: Medium
Categories: Style
Remediation Points: 50000
Fields, local variables, or parameter names that are very short are not helpful to the reader.
Example:
public class Something {
private int q = 15; // field - too short
public static void main( String as[] ) { // formal arg - too short
int r = 20 + q; // local var - too short
for (int i = 0; i < 10; i++) { // not a violation (inside 'for' loop)
r += q;
}
for (Integer i : numbers) { // not a violation (inside 'for-each' loop)
r += q;
}
}
}