forked from mifmif/Generex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pmdruleset.xml
845 lines (725 loc) · 33.3 KB
/
.pmdruleset.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="M2Eclipse PMD RuleSet" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0">
<description/>
<exclude-pattern>.*C:/Users/Pro/git/GenerexMvn/src/main/java.*/HelpMojo.java</exclude-pattern>
<exclude-pattern>.*C:/Users/Pro/git/GenerexMvn/src/test/java.*</exclude-pattern>
<exclude-pattern>.*C:/Users/Pro/git/GenerexMvn/target.*</exclude-pattern>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#JumbledIncrementer" language="java" message="Avoid modifying an outer loop incrementer in an inner loop for update expression" name="JumbledIncrementer" since="1.0" typeResolution="false">
<description>
Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//ForStatement
[
ForUpdate/StatementExpressionList/StatementExpression/PostfixExpression/PrimaryExpression/PrimaryPrefix/Name/@Image
=
ancestor::ForStatement/ForInit//VariableDeclaratorId/@Image
]
]]></value>
</property>
</properties>
<example><![CDATA[
public class JumbledIncrementerRule1 {
public void foo() {
for (int i = 0; i < 10; i++) { // only references 'i'
for (int k = 0; k < 20; i++) { // references both 'i' and 'k'
System.out.println("Hello");
}
}
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#ForLoopShouldBeWhileLoop" language="java" message="This for loop could be simplified to a while loop" name="ForLoopShouldBeWhileLoop" since="1.02" typeResolution="false">
<description>
Some for loops can be simplified to while loops, this makes them more concise.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//ForStatement
[count(*) > 1]
[not(LocalVariableDeclaration)]
[not(ForInit)]
[not(ForUpdate)]
[not(Type and Expression and Statement)]
]]></value>
</property>
</properties>
<example><![CDATA[
public class Foo {
void bar() {
for (;true;) true; // No Init or Update part, may as well be: while (true)
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.OverrideBothEqualsAndHashcodeRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#OverrideBothEqualsAndHashcode" message="Ensure you override both equals() and hashCode()" name="OverrideBothEqualsAndHashcode" since="0.4" typeResolution="true">
<description>
Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass.
</description>
<priority>3</priority>
<example><![CDATA[
public class Bar { // poor, missing a hashcode() method
public boolean equals(Object o) {
// do some comparison
}
}
public class Baz { // poor, missing an equals() method
public int hashCode() {
// return some hash value
}
}
public class Foo { // perfect, both methods provided
public boolean equals(Object other) {
// do some comparison
}
public int hashCode() {
// return some hash value
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.DoubleCheckedLockingRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#DoubleCheckedLocking" message="Double checked locking is not thread safe in Java." name="DoubleCheckedLocking" since="1.04" typeResolution="true">
<description>
Partially created objects can be returned by the Double Checked Locking pattern when used in Java.
An optimizing JRE may assign a reference to the baz variable before it creates the object the
reference is intended to point to.
For more details refer to: http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html
</description>
<priority>1</priority>
<example><![CDATA[
public class Foo {
Object baz;
Object bar() {
if (baz == null) { // baz may be non-null yet not fully created
synchronized(this) {
if (baz == null) {
baz = new Object();
}
}
}
return baz;
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#ReturnFromFinallyBlock" language="java" message="Avoid returning from a finally block" name="ReturnFromFinallyBlock" since="1.05" typeResolution="false">
<description>
Avoid returning from a finally block, this can discard exceptions.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//FinallyStatement//ReturnStatement
]]></value>
</property>
</properties>
<example><![CDATA[
public class Bar {
public String foo() {
try {
throw new Exception( "My Exception" );
} catch (Exception e) {
throw e;
} finally {
return "A. O. K."; // return not recommended here
}
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#UnconditionalIfStatement" language="java" message="Do not use 'if' statements that are always true or always false" name="UnconditionalIfStatement" since="1.5" typeResolution="false">
<description>
Do not use "if" statements whose conditionals are always true or always false.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//IfStatement/Expression
[count(PrimaryExpression)=1]
/PrimaryExpression/PrimaryPrefix/Literal/BooleanLiteral
]]></value>
</property>
</properties>
<example><![CDATA[
public class Foo {
public void close() {
if (true) { // fixed conditional, not recommended
// ...
}
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.BooleanInstantiationRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#BooleanInstantiation" message="Avoid instantiating Boolean objects; reference Boolean.TRUE or Boolean.FALSE or call Boolean.valueOf() instead." name="BooleanInstantiation" since="1.2" typeResolution="true">
<description>
Avoid instantiating Boolean objects; you can reference Boolean.TRUE, Boolean.FALSE, or call Boolean.valueOf() instead.
</description>
<priority>2</priority>
<example><![CDATA[
Boolean bar = new Boolean("true"); // unnecessary creation, just reference Boolean.TRUE;
Boolean buz = Boolean.valueOf(false); // ...., just reference Boolean.FALSE;
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#CollapsibleIfStatements" language="java" message="These nested if statements could be combined" name="CollapsibleIfStatements" since="3.1" typeResolution="false">
<description>
Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//IfStatement[@Else='false']/Statement
/IfStatement[@Else='false']
|
//IfStatement[@Else='false']/Statement
/Block[count(BlockStatement)=1]/BlockStatement
/Statement/IfStatement[@Else='false']
]]></value>
</property>
</properties>
<example><![CDATA[
void bar() {
if (x) { // original implementation
if (y) {
// do stuff
}
}
}
void bar() {
if (x && y) { // optimized implementation
// do stuff
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#ClassCastExceptionWithToArray" language="java" message="This usage of the Collection.toArray() method will throw a ClassCastException." name="ClassCastExceptionWithToArray" since="3.4" typeResolution="false">
<description>
When deriving an array of a specific class from your Collection, one should provide an array of
the same class as the parameter of the toArray() method. Doing otherwise you will will result
in a ClassCastException.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//CastExpression[Type/ReferenceType/ClassOrInterfaceType[@Image !=
"Object"]]/PrimaryExpression
[
PrimaryPrefix/Name[ends-with(@Image, '.toArray')]
and
PrimarySuffix/Arguments[count(*) = 0]
and
count(PrimarySuffix) = 1
]
]]></value>
</property>
</properties>
<example><![CDATA[
Collection c = new ArrayList();
Integer obj = new Integer(1);
c.add(obj);
// this would trigger the rule (and throw a ClassCastException if executed)
Integer[] a = (Integer [])c.toArray();
// this is fine and will not trigger the rule
Integer[] b = (Integer [])c.toArray(new Integer[c.size()]);
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#AvoidDecimalLiteralsInBigDecimalConstructor" language="java" message="Avoid creating BigDecimal with a decimal (float/double) literal. Use a String literal" name="AvoidDecimalLiteralsInBigDecimalConstructor" since="3.4" typeResolution="false">
<description>
One might assume that the result of "new BigDecimal(0.1)" is exactly equal to 0.1, but it is actually
equal to .1000000000000000055511151231257827021181583404541015625.
This is because 0.1 cannot be represented exactly as a double (or as a binary fraction of any finite
length). Thus, the long value that is being passed in to the constructor is not exactly equal to 0.1,
appearances notwithstanding.
The (String) constructor, on the other hand, is perfectly predictable: 'new BigDecimal("0.1")' is
exactly equal to 0.1, as one would expect. Therefore, it is generally recommended that the
(String) constructor be used in preference to this one.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//AllocationExpression[ClassOrInterfaceType[@Image="BigDecimal"]
and
./Arguments/ArgumentList
/Expression/PrimaryExpression/PrimaryPrefix/Literal[(not
(ends-with
(@Image,'"'))) and contains(@Image,".")]]
]]></value>
</property>
</properties>
<example><![CDATA[
BigDecimal bd = new BigDecimal(1.123); // loss of precision, this would trigger the rule
BigDecimal bd = new BigDecimal("1.123"); // preferred approach
BigDecimal bd = new BigDecimal(12); // preferred approach, ok for integer values
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#MisplacedNullCheck" language="java" message="The null check here is misplaced; if the variable is null there'll be a NullPointerException" name="MisplacedNullCheck" since="3.5" typeResolution="false">
<description>
The null check here is misplaced. If the variable is null a NullPointerException will be thrown.
Either the check is useless (the variable will never be "null") or it is incorrect.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//Expression
/*[self::ConditionalOrExpression or self::ConditionalAndExpression]
/descendant::PrimaryExpression/PrimaryPrefix
/Name[starts-with(@Image,
concat(ancestor::PrimaryExpression/following-sibling::EqualityExpression
[./PrimaryExpression/PrimaryPrefix/Literal/NullLiteral]
/PrimaryExpression/PrimaryPrefix
/Name[count(../../PrimarySuffix)=0]/@Image,".")
)
]
[count(ancestor::ConditionalAndExpression/EqualityExpression
[@Image='!=']
[./PrimaryExpression/PrimaryPrefix/Literal/NullLiteral]
[starts-with(following-sibling::*/PrimaryExpression/PrimaryPrefix/Name/@Image,
concat(./PrimaryExpression/PrimaryPrefix/Name/@Image, '.'))]
) = 0
]
]]></value>
</property>
</properties>
<example><![CDATA[
public class Foo {
void bar() {
if (a.equals(baz) && a != null) {}
}
}
]]></example>
<example><![CDATA[
public class Foo {
void bar() {
if (a.equals(baz) || a == null) {}
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#AvoidThreadGroup" language="java" message="Avoid using java.lang.ThreadGroup; it is not thread safe" name="AvoidThreadGroup" since="3.6" typeResolution="true">
<description>
Avoid using java.lang.ThreadGroup; although it is intended to be used in a threaded environment
it contains methods that are not thread-safe.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//AllocationExpression/ClassOrInterfaceType[pmd-java:typeof(@Image, 'java.lang.ThreadGroup')]|
//PrimarySuffix[contains(@Image, 'getThreadGroup')]
]]></value>
</property>
</properties>
<example><![CDATA[
public class Bar {
void buz() {
ThreadGroup tg = new ThreadGroup("My threadgroup") ;
tg = new ThreadGroup(tg, "my thread group");
tg = Thread.currentThread().getThreadGroup();
tg = System.getSecurityManager().getThreadGroup();
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.BrokenNullCheckRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#BrokenNullCheck" message="Method call on object which may be null" name="BrokenNullCheck" since="3.8" typeResolution="true">
<description>
The null check is broken since it will throw a NullPointerException itself.
It is likely that you used || instead of && or vice versa.
</description>
<priority>2</priority>
<example><![CDATA[
public String bar(String string) {
// should be &&
if (string!=null || !string.equals(""))
return string;
// should be ||
if (string==null && string.equals(""))
return string;
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.BigIntegerInstantiationRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#BigIntegerInstantiation" message="Don't create instances of already existing BigInteger and BigDecimal (ZERO, ONE, TEN)" name="BigIntegerInstantiation" since="3.9" typeResolution="true">
<description>
Don't create instances of already existing BigInteger (BigInteger.ZERO, BigInteger.ONE) and
for Java 1.5 onwards, BigInteger.TEN and BigDecimal (BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN)
</description>
<priority>3</priority>
<example><![CDATA[
BigInteger bi = new BigInteger(1); // reference BigInteger.ONE instead
BigInteger bi2 = new BigInteger("0"); // reference BigInteger.ZERO instead
BigInteger bi3 = new BigInteger(0.0); // reference BigInteger.ZERO instead
BigInteger bi4;
bi4 = new BigInteger(0); // reference BigInteger.ZERO instead
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.AvoidUsingOctalValuesRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#AvoidUsingOctalValues" message="Do not start a literal by 0 unless it's an octal value" name="AvoidUsingOctalValues" since="3.9" typeResolution="true">
<description>
Integer literals should not start with zero since this denotes that the rest of literal will be
interpreted as an octal value.
</description>
<priority>3</priority>
<example><![CDATA[
int i = 012; // set i with 10 not 12
int j = 010; // set j with 8 not 10
k = i * j; // set k with 80 not 120
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.AvoidUsingHardCodedIPRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#AvoidUsingHardCodedIP" message="Do not hard code the IP address ${variableName}" name="AvoidUsingHardCodedIP" since="4.1" typeResolution="true">
<description>
Application with hard-coded IP addresses can become impossible to deploy in some cases.
Externalizing IP adresses is preferable.
</description>
<priority>3</priority>
<properties>
<property description="Regular Expression" name="pattern" type="String" value="^"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"$"/>
</properties>
<example><![CDATA[
public class Foo {
private String ip = "127.0.0.1"; // not recommended
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.CheckResultSetRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#CheckResultSet" message="Always check the return of one of the navigation method (next,previous,first,last) of a ResultSet." name="CheckResultSet" since="4.1" typeResolution="true">
<description>
Always check the return values of navigation methods (next, previous, first, last) of a ResultSet.
If the value return is 'false', it should be handled properly.
</description>
<priority>3</priority>
<example><![CDATA[
Statement stat = conn.createStatement();
ResultSet rst = stat.executeQuery("SELECT name FROM person");
rst.next(); // what if it returns false? bad form
String firstName = rst.getString(1);
Statement stat = conn.createStatement();
ResultSet rst = stat.executeQuery("SELECT name FROM person");
if (rst.next()) { // result is properly examined and used
String firstName = rst.getString(1);
} else {
// handle missing data
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.AvoidMultipleUnaryOperatorsRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#AvoidMultipleUnaryOperators" message="Using multiple unary operators may be a bug, and/or is confusing." name="AvoidMultipleUnaryOperators" since="4.2" typeResolution="true">
<description>
The use of multiple unary operators may be problematic, and/or confusing.
Ensure that the intended usage is not a bug, or consider simplifying the expression.
</description>
<priority>2</priority>
<example><![CDATA[
// These are typo bugs, or at best needlessly complex and confusing:
int i = - -1;
int j = + - +1;
int z = ~~2;
boolean b = !!true;
boolean c = !!!true;
// These are better:
int i = 1;
int j = -1;
int z = 2;
boolean b = true;
boolean c = false;
// And these just make your brain hurt:
int i = ~-2;
int j = -~7;
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#ExtendsObject" language="java" message="No need to explicitly extend Object." name="ExtendsObject" since="5.0" typeResolution="false">
<description>No need to explicitly extend Object.</description>
<priority>4</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//ExtendsList/ClassOrInterfaceType[@Image='Object' or @Image='java.lang.Object']
]]></value>
</property>
</properties>
<example><![CDATA[
public class Foo extends Object { // not required
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.CheckSkipResultRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#CheckSkipResult" message="Check the value returned by the skip() method of an InputStream to see if the requested number of bytes has been skipped." name="CheckSkipResult" since="5.0" typeResolution="true">
<description>The skip() method may skip a smaller number of bytes than requested. Check the returned value to find out if it was the case or not.</description>
<priority>3</priority>
<example><![CDATA[
public class Foo {
private FileInputStream _s = new FileInputStream("file");
public void skip(int n) throws IOException {
_s.skip(n); // You are not sure that exactly n bytes are skipped
}
public void skipExactly(int n) throws IOException {
while (n != 0) {
long skipped = _s.skip(n);
if (skipped == 0)
throw new EOFException();
n -= skipped;
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.basic.AvoidBranchingStatementAsLastInLoopRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#AvoidBranchingStatementAsLastInLoop" message="Avoid using a branching statement as the last in a loop." name="AvoidBranchingStatementAsLastInLoop" since="5.0" typeResolution="true">
<description>
Using a branching statement as the last part of a loop may be a bug, and/or is confusing.
Ensure that the usage is not a bug, or consider using another approach.
</description>
<priority>2</priority>
<example><![CDATA[
// unusual use of branching statement in a loop
for (int i = 0; i < 10; i++) {
if (i*i <= 25) {
continue;
}
break;
}
// this makes more sense...
for (int i = 0; i < 10; i++) {
if (i*i > 25) {
break;
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#DontCallThreadRun" language="java" message="Don't call Thread.run() explicitly, use Thread.start()" name="DontCallThreadRun" since="4.3" typeResolution="false">
<description>
Explicitly calling Thread.run() method will execute in the caller's thread of control. Instead, call Thread.start() for the intended behavior.
</description>
<priority>4</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//StatementExpression/PrimaryExpression
[
PrimaryPrefix
[
./Name[ends-with(@Image, '.run') or @Image = 'run']
and substring-before(Name/@Image, '.') =//VariableDeclarator/VariableDeclaratorId/@Image
[../../../Type/ReferenceType[ClassOrInterfaceType/@Image = 'Thread']]
or (
./AllocationExpression/ClassOrInterfaceType[@Image = 'Thread']
and ../PrimarySuffix[@Image = 'run'])
]
]
]]></value>
</property>
</properties>
<example><![CDATA[
Thread t = new Thread();
t.run(); // use t.start() instead
new Thread().run(); // same violation
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/basic.html#DontUseFloatTypeForLoopIndices" language="java" message="Don't use floating point for loop indices. If you must use floating point, use double." name="DontUseFloatTypeForLoopIndices" since="4.3" typeResolution="false">
<description>
Don't use floating point for loop indices. If you must use floating point, use double
unless you're certain that float provides enough precision and you have a compelling
performance need (space or time).
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//ForStatement/ForInit/LocalVariableDeclaration
/Type/PrimitiveType[@Image="float"]
]]></value>
</property>
</properties>
<example><![CDATA[
public class Count {
public static void main(String[] args) {
final int START = 2000000000;
int count = 0;
for (float f = START; f < START + 50; f++)
count++;
//Prints 0 because (float) START == (float) (START + 50).
System.out.println(count);
//The termination test misbehaves due to floating point granularity.
}
}
]]></example>
</rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyCatchBlock"/>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyIfStmt"/>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyWhileStmt"/>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyTryBlock"/>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyFinallyBlock"/>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptySwitchStatements"/>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptySynchronizedBlock"/>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyStatementNotInLoop"/>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyInitializer"/>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyStatementBlock"/>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyStaticInitializer"/>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UnnecessaryConversionTemporary"/>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UnnecessaryReturn"/>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UnnecessaryFinalModifier"/>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UselessOverridingMethod"/>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UselessOperationOnImmutable"/>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UnusedNullCheckInEquals"/>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UselessParentheses"/>
<rule class="net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedPrivateFieldRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/unusedcode.html#UnusedPrivateField" message="Avoid unused private fields such as ''{0}''." name="UnusedPrivateField" since="0.1" typeResolution="true">
<description>
Detects when a private field is declared and/or assigned a value, but not used.
</description>
<priority>3</priority>
<example><![CDATA[
public class Something {
private static int FOO = 2; // Unused
private int i = 5; // Unused
private int j = 6;
public int addOne() {
return j++;
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedLocalVariableRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/unusedcode.html#UnusedLocalVariable" message="Avoid unused local variables such as ''{0}''." name="UnusedLocalVariable" since="0.1" typeResolution="true">
<description>
Detects when a local variable is declared and/or assigned, but not used.
</description>
<priority>3</priority>
<example><![CDATA[
public class Foo {
public void doSomething() {
int i = 5; // Unused
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedPrivateMethodRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/unusedcode.html#UnusedPrivateMethod" message="Avoid unused private methods such as ''{0}''." name="UnusedPrivateMethod" since="0.7" typeResolution="true">
<description>
Unused Private Method detects when a private method is declared but is unused.
</description>
<priority>3</priority>
<example><![CDATA[
public class Something {
private void foo() {} // unused
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedFormalParameterRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/unusedcode.html#UnusedFormalParameter" message="Avoid unused {0} parameters such as ''{1}''." name="UnusedFormalParameter" since="0.8" typeResolution="true">
<description>
Avoid passing parameters to methods or constructors without actually referencing them in the method body.
</description>
<priority>3</priority>
<example><![CDATA[
public class Foo {
private void bar(String howdy) {
// howdy is not used
}
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedModifierRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/unusedcode.html#UnusedModifier" message="Avoid modifiers which are implied by the context" name="UnusedModifier" since="1.02" typeResolution="true">
<description>
Fields in interfaces are automatically public static final, and methods are public abstract.
Classes or interfaces nested in an interface are automatically public and static (all nested interfaces are automatically static).
For historical reasons, modifiers which are implied by the context are accepted by the compiler, but are superfluous.
</description>
<priority>3</priority>
<example><![CDATA[
public interface Foo {
public abstract void bar(); // both abstract and public are ignored by the compiler
public static final int X = 0; // public, static, and final all ignored
public static class Bar {} // public, static ignored
public static interface Baz {} // ditto
}
public class Bar {
public static interface Baz {} // static ignored
}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.imports.DuplicateImportsRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/imports.html#DuplicateImports" message="Avoid duplicate imports such as ''{0}''" name="DuplicateImports" since="0.5" typeResolution="true">
<description>
Duplicate or overlapping import statements should be avoided.
</description>
<priority>4</priority>
<example><![CDATA[
import java.lang.String;
import java.lang.*;
public class Foo {}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.imports.DontImportJavaLangRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/imports.html#DontImportJavaLang" message="Avoid importing anything from the package 'java.lang'" name="DontImportJavaLang" since="0.5" typeResolution="true">
<description>
Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).
</description>
<priority>4</priority>
<example><![CDATA[
import java.lang.String; // this is unnecessary
public class Foo {}
// --- in another source code file...
import java.lang.*; // this is bad
public class Foo {}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.imports.UnusedImportsRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/imports.html#UnusedImports" message="Avoid unused imports such as ''{0}''" name="UnusedImports" since="1.0" typeResolution="true">
<description>
Avoid the use of unused import statements to prevent unwanted dependencies.
</description>
<priority>4</priority>
<example><![CDATA[
// this is bad
import java.io.File;
public class Foo {}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.imports.ImportFromSamePackageRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/imports.html#ImportFromSamePackage" message="No need to import a type that lives in the same package" name="ImportFromSamePackage" since="1.02" typeResolution="true">
<description>
There is no need to import a type that lives in the same package.
</description>
<priority>3</priority>
<example><![CDATA[
package foo;
import foo.Buz; // no need for this
import foo.*; // or this
public class Bar{}
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.rule.XPathRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/imports.html#TooManyStaticImports" language="java" message="Too many static imports may lead to messy code" name="TooManyStaticImports" since="4.1" typeResolution="false">
<description>
If you overuse the static import feature, it can make your program unreadable and
unmaintainable, polluting its namespace with all the static members you import.
Readers of your code (including you, a few months after you wrote it) will not know
which class a static member comes from (Sun 1.5 Language Guide).
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
.[count(ImportDeclaration[@Static = 'true']) > $maximumStaticImports]
]]></value>
</property>
<property description="All static imports can be disallowed by setting this to 0" max="100" min="0" name="maximumStaticImports" type="Integer" value="4"/>
</properties>
<example><![CDATA[
import static Lennon;
import static Ringo;
import static George;
import static Paul;
import static Yoko; // Too much !
]]></example>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.imports.UnnecessaryFullyQualifiedNameRule" deprecated="false" dfa="false" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.5/rules/java/imports.html#UnnecessaryFullyQualifiedName" message="Unnecessary use of fully qualified name ''{0}'' due to existing import ''{1}''" name="UnnecessaryFullyQualifiedName" since="5.0" typeResolution="true">
<description>
Import statements allow the use of non-fully qualified names. The use of a fully qualified name
which is covered by an import statement is redundant. Consider using the non-fully qualified name.
</description>
<priority>4</priority>
<example><![CDATA[
import java.util.List;
public class Foo {
private java.util.List list1; // Unnecessary FQN
private List list2; // More appropriate given import of 'java.util.List'
}
]]></example>
</rule>
</ruleset>