| Line | Hits | Note | Source |
|---|---|---|---|
| 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 | */ | ||
| 51 | 0 | (2)(3) | public static final BigDecimal TEST = new BigDecimal(1.123); |
| 52 | |||
| 53 | 0 | private static Object sSingleton = null; | |
| 54 | |||
| 55 | /** | ||
| 56 | * Trigger PMD design/UncommentedEmptyConstructor | ||
| 57 | */ | ||
| 58 | private SimplePmdFindings () | ||
| 59 | 0 | { | |
| 60 | 0 | } | |
| 61 | |||
| 62 | |||
| 63 | /** | ||
| 64 | * Trigger method for findings. | ||
| 65 | */ | ||
| 66 | public void sampleMethod () | ||
| 67 | { | ||
| 68 | // Trigger PMD basic/ClassCastExceptionWithToArray. | ||
| 69 | 0 | final Collection c = new ArrayList(); | |
| 70 | 0 | (4)(5) | final Integer[] a = (Integer []) c.toArray(); |
| 71 | |||
| 72 | // Trigger PMD basic/MisplacedNullCheck | ||
| 73 | 0 | (6)(7)(8)(9) | if (a.toString().equals("hi") && a != null) |
| 74 | { | ||
| 75 | 0 | a.getClass(); | |
| 76 | } | ||
| 77 | |||
| 78 | // Trigger PMD basic/UnusedNullCheckInEquals | ||
| 79 | 0 | (10) | if (a != null && c.equals(a)) |
| 80 | { | ||
| 81 | 0 | a.getClass(); | |
| 82 | } | ||
| 83 | |||
| 84 | 0 | final BigDecimal bd = new BigDecimal("1"); | |
| 85 | |||
| 86 | // Trigger PMD basic/UselessOperationOnImmutable | ||
| 87 | 0 | (11)(12) | bd.add(new BigDecimal("10")); |
| 88 | |||
| 89 | 0 | final String s = "TEST"; | |
| 90 | // Trigger PMD design/PositionLiteralsFirstInComparisons | ||
| 91 | 0 | (13)(14) | if (s.equals("2")) |
| 92 | { | ||
| 93 | 0 | s.getClass(); | |
| 94 | } | ||
| 95 | 0 | } | |
| 96 | |||
| 97 | /** Trigger PMD design/UncommentedEmptyMethod. */ | ||
| 98 | public void doSomething () | ||
| 99 | (15) | { | |
| 100 | 0 | } | |
| 101 | |||
| 102 | /** Trigger method for findings. */ | ||
| 103 | public void bool () | ||
| 104 | { | ||
| 105 | 0 | boolean b = true; | |
| 106 | |||
| 107 | // Trigger PMD controversial/BooleanInversion | ||
| 108 | 0 | (16) | b = !b; // slow |
| 109 | 0 | (17) | b ^= true; // fast |
| 110 | 0 | } | |
| 111 | |||
| 112 | /** Trigger method for findings. */ | ||
| 113 | public void design () | ||
| 114 | { | ||
| 115 | // Trigger PMD design/AssignmentToNonFinalStatic | ||
| 116 | 0 | (18) | sNoneFinalStatic = 1; |
| 117 | 0 | } | |
| 118 | |||
| 119 | /** | ||
| 120 | * Trigger method for findings. | ||
| 121 | * @return a singleton object. | ||
| 122 | */ | ||
| 123 | public Object getSingleton () | ||
| 124 | { | ||
| 125 | // Trigger PMD design/NonThreadSafeSingleton | ||
| 126 | 0 | (19) | if (sSingleton == null) |
| 127 | { | ||
| 128 | 0 | sSingleton = new Object(); | |
| 129 | } | ||
| 130 | 0 | return sSingleton; | |
| 131 | } | ||
| 132 | |||
| 133 | /** | ||
| 134 | * Trigger PMD basic/UselessOverridingMethod. | ||
| 135 | * @return a String. | ||
| 136 | */ | ||
| 137 | (20) | public String toString () | |
| 138 | { | ||
| 139 | 0 | return super.toString(); | |
| 140 | } | ||
| 141 | |||
| 142 | /** | ||
| 143 | * Trigger PMD design.xml/UnnecessaryLocalBeforeReturn. | ||
| 144 | * @return 97 | ||
| 145 | */ | ||
| 146 | public int foo () | ||
| 147 | { | ||
| 148 | 0 | final int x = 97; | |
| 149 | 0 | (21) | return x; |
| 150 | } | ||
| 151 | } |