Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report.samples

org.jcoderz.phoenix.report.samples.SimplePmdFindings

LineHitsNoteSource
1  /*
2   * $Id: SimplePmdFindings.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.phoenix.report.samples;
34  
35  import java.math.BigDecimal;
36  import java.util.ArrayList;
37  import java.util.Collection;
38  
39  /**
40   * This class is used to trigger PMD finders.
41   * @author Andreas Mandel
42   */
43  public final class SimplePmdFindings
44  {
45     /** Used to test the finder. */
46 (1)   public static int sNoneFinalStatic;
47  
48     /**
49      * Trigger PMD basic/AvoidDecimalLiteralsInBigDecimalConstructor.
50      */
510(2)(3)   public static final BigDecimal TEST = new BigDecimal(1.123);
52  
530    private static Object sSingleton = null;
54  
55     /**
56      * Trigger PMD design/UncommentedEmptyConstructor
57      */
58     private SimplePmdFindings ()
590    {
600    }
61  
62  
63     /**
64      * Trigger method for findings.
65      */
66     public void sampleMethod ()
67     {
68        // Trigger PMD basic/ClassCastExceptionWithToArray.
690       final Collection c = new ArrayList();
700(4)(5)      final Integer[] a = (Integer []) c.toArray();
71  
72        // Trigger PMD basic/MisplacedNullCheck
730(6)(7)(8)(9)      if (a.toString().equals("hi") && a != null)
74        {
750          a.getClass();
76        }
77  
78        // Trigger PMD basic/UnusedNullCheckInEquals
790(10)      if (a != null && c.equals(a))
80        {
810          a.getClass();
82        }
83  
840       final BigDecimal bd = new BigDecimal("1");
85  
86        // Trigger PMD basic/UselessOperationOnImmutable
870(11)(12)      bd.add(new BigDecimal("10"));
88  
890       final String s = "TEST";
90        // Trigger PMD design/PositionLiteralsFirstInComparisons
910(13)(14)      if (s.equals("2"))
92        {
930          s.getClass();
94        }
950    }
96  
97     /** Trigger PMD design/UncommentedEmptyMethod. */
98     public void doSomething ()
99 (15)   {
1000    }
101  
102     /** Trigger method for findings. */
103     public void bool ()
104     {
1050       boolean b = true;
106  
107        // Trigger PMD controversial/BooleanInversion
1080(16)      b = !b; // slow
1090(17)      b ^= true; // fast
1100    }
111  
112     /** Trigger method for findings. */
113     public void design ()
114     {
115        // Trigger PMD design/AssignmentToNonFinalStatic
1160(18)      sNoneFinalStatic = 1;
1170    }
118  
119     /**
120      * Trigger method for findings.
121      * @return a singleton object.
122      */
123     public Object getSingleton ()
124     {
125        // Trigger PMD design/NonThreadSafeSingleton
1260(19)      if (sSingleton == null)
127        {
1280          sSingleton = new Object();
129        }
1300       return sSingleton;
131     }
132  
133     /**
134      * Trigger PMD basic/UselessOverridingMethod.
135      * @return a String.
136      */
137 (20)   public String toString ()
138     {
1390       return super.toString();
140     }
141  
142     /**
143      * Trigger PMD design.xml/UnnecessaryLocalBeforeReturn.
144      * @return 97
145      */
146     public int foo ()
147     {
1480       final int x = 97;
1490(21)      return x;
150     }
151  }

Findings in this File

i (22) org.jcoderz.phoenix.report.samples.SimplePmdFindings.sNoneFinalStatic should be package protected (sample)
c (1) 46 : 22 Variable 'sNoneFinalStatic' must be private and have accessor methods. (sample)
w (2) 51 : 0 Method org.jcoderz.phoenix.report.samples.SimplePmdFindings.<static initializer>() passes double value to BigDecimal Constructor (sample)
c (3) 51 : 42 Avoid creating BigDecimal with a decimal (float/double) literal. Use a String literal (sample)
e (4) 70 : 0 Impossible cast from Object[] to Integer[] in org.jcoderz.phoenix.report.samples.SimplePmdFindings.sampleMethod() (sample)
e (5) 70 : 40 This usage of the Collection.toArray() method will throw a ClassCastException. (sample)
e (6) 73 : 0 Invocation of toString on a in org.jcoderz.phoenix.report.samples.SimplePmdFindings.sampleMethod() (sample)
i (7) 73 : 0 method org.jcoderz.phoenix.report.samples.SimplePmdFindings.sampleMethod() makes literal string comparisons passing the literal as an argument (sample)
w (8) 73 : 0 Nullcheck of a at line 73 of value previously dereferenced in org.jcoderz.phoenix.report.samples.SimplePmdFindings.sampleMethod() (sample)
w (9) 73 : 11 The null check here is misplaced; if the variable is null therell be a NullPointerException (sample)
e (10) 79 : 0 org.jcoderz.phoenix.report.samples.SimplePmdFindings.sampleMethod() uses equals to compare an array and nonarray (sample)
e (11) 87 : 0 org.jcoderz.phoenix.report.samples.SimplePmdFindings.sampleMethod() ignores return value of java.math.BigDecimal.add(BigDecimal) (sample)
w (12) 87 : 7 An operation on an Immutable object (String, BigDecimal or BigInteger) won't change the object itself (sample)
i (13) 91 : 0 method org.jcoderz.phoenix.report.samples.SimplePmdFindings.sampleMethod() makes literal string comparisons passing the literal as an argument (sample)
c (14) 91 : 11 Position literals first in String comparisons (sample)
c (15) 99 : 4 Document empty method (sample)
c (16) 108 : 11 Use bitwise inversion to invert boolean values (sample)
w (17) 109 : 0 Dead store to b in org.jcoderz.phoenix.report.samples.SimplePmdFindings.bool() (sample)
e (18) 116 : 0 Write to static field org.jcoderz.phoenix.report.samples.SimplePmdFindings.sNoneFinalStatic from instance method org.jcoderz.phoenix.report.samples.SimplePmdFindings.design() (sample)
i (19) 126 : 0 Incorrect lazy initialization of static field org.jcoderz.phoenix.report.samples.SimplePmdFindings.sSingleton in org.jcoderz.phoenix.report.samples.SimplePmdFindings.getSingleton() (sample)
d (20) 137 : 11 Overriding method merely calls super (sample)
c (21) 149 : 7 Consider simply returning the value vs storing it in local variable 'x' (sample)