| Line | Hits | Note | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * $Id: JCoderZJavaExample.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.guidelines.snippets; | ||
| 34 | |||
| 35 | |||
| 36 | import java.util.logging.Level; | ||
| 37 | import java.util.logging.Logger; | ||
| 38 | |||
| 39 | |||
| 40 | /** | ||
| 41 | * Class description goes here. | ||
| 42 | * @author Firstname Lastname | ||
| 43 | */ | ||
| 44 | public class JCoderZJavaExample | ||
| 45 | { | ||
| 46 | /* A class implementation comment can go here. */ | ||
| 47 | |||
| 48 | /** MIN_WIDTH documentation comment. */ | ||
| 49 | public static final int MIN_WIDTH = 4; | ||
| 50 | |||
| 51 | /** MAX_WIDTH documentation comment. */ | ||
| 52 | public static final int MAX_WIDTH = 999; | ||
| 53 | |||
| 54 | /** BAD_PARAM documentation comment. */ | ||
| 55 | public static final int BAD_PARAM = -1; | ||
| 56 | |||
| 57 | /** INTERNAL_ERROR documentation comment. */ | ||
| 58 | public static final int INTERNAL_ERROR = -2; | ||
| 59 | |||
| 60 | /** classVar1 documentation comment. */ | ||
| 61 | (1) | protected static int sClassVar1; | |
| 62 | |||
| 63 | /** | ||
| 64 | * The logger. | ||
| 65 | */ | ||
| 66 | 0 | private static final Logger logger = | |
| 67 | Logger.getLogger(JCoderZJavaExample.class.getName()); | ||
| 68 | |||
| 69 | private static final String CLASS_NAME = "JCoderZJavaExample"; | ||
| 70 | |||
| 71 | /** | ||
| 72 | * classVar2 documentation comment that happens to be more than one | ||
| 73 | * line long. | ||
| 74 | */ | ||
| 75 | private static Object sClassVar2; | ||
| 76 | |||
| 77 | /** instanceVar2 documentation comment. */ | ||
| 78 | (2) | protected int mInstanceVar2; | |
| 79 | |||
| 80 | /** instanceVar3 documentation comment. */ | ||
| 81 | private Object[] mInstanceVar3; | ||
| 82 | |||
| 83 | /** | ||
| 84 | * ... Constructor blah documentation comment... | ||
| 85 | */ | ||
| 86 | public JCoderZJavaExample () | ||
| 87 | 0 | { | |
| 88 | // ...implementation goes here... | ||
| 89 | 0 | if (logger.isLoggable(Level.FINER)) | |
| 90 | { | ||
| 91 | 0 | logger.finer("Sample constructor " + this); | |
| 92 | } | ||
| 93 | 0 | } | |
| 94 | |||
| 95 | /** | ||
| 96 | * ... method doSomething documentation comment... | ||
| 97 | */ | ||
| 98 | public final void setupConfiguration () | ||
| 99 | { | ||
| 100 | // write message to log | ||
| 101 | 0 | logger.info("Message"); | |
| 102 | 0 | } | |
| 103 | |||
| 104 | /** | ||
| 105 | * ... method doSomething documentation comment... | ||
| 106 | */ | ||
| 107 | public void doSomething () | ||
| 108 | { | ||
| 109 | // ...implementation goes here... | ||
| 110 | 0 | } | |
| 111 | |||
| 112 | /** | ||
| 113 | * ...method doSomethingElse documentation comment... | ||
| 114 | * @param someParam this is the input parameter | ||
| 115 | * @return result The method returns an int. | ||
| 116 | */ | ||
| 117 | public int doSomethingElse (Object someParam) | ||
| 118 | { | ||
| 119 | 0 | int result = BAD_PARAM; | |
| 120 | |||
| 121 | 0 | if (logger.isLoggable(Level.FINER)) | |
| 122 | { | ||
| 123 | 0 | logger.entering(CLASS_NAME, "doSomethingElse", | |
| 124 | new Object[] {someParam}); | ||
| 125 | } | ||
| 126 | |||
| 127 | // ...implementation goes here... | ||
| 128 | 0 | if (BAD_PARAM == result) | |
| 129 | { | ||
| 130 | 0 | final RuntimeException ex | |
| 131 | = new RuntimeException("Bad parameter"); | ||
| 132 | 0 | if (logger.isLoggable(Level.FINER)) | |
| 133 | { | ||
| 134 | 0 | logger.throwing(CLASS_NAME, "doSomethingElse", ex); | |
| 135 | } | ||
| 136 | 0 | throw ex; | |
| 137 | } | ||
| 138 | try | ||
| 139 | { | ||
| 140 | 0 | result = doSometingFine(); | |
| 141 | } | ||
| 142 | 0 | (3) | catch (Throwable th) |
| 143 | { | ||
| 144 | 0 | result = INTERNAL_ERROR; | |
| 145 | 0 | } | |
| 146 | |||
| 147 | (4) | // FIXME: finally must log exiting() function | |
| 148 | 0 | if (logger.isLoggable(Level.FINER)) | |
| 149 | { | ||
| 150 | 0 | logger.exiting(CLASS_NAME, "doSomethingElse", | |
| 151 | new Integer(result)); | ||
| 152 | } | ||
| 153 | 0 | return result; | |
| 154 | } | ||
| 155 | |||
| 156 | /** | ||
| 157 | * Method doSomethingElse documentation comment. | ||
| 158 | * @return result The method returns an int. | ||
| 159 | */ | ||
| 160 | private int doSometingFine () | ||
| 161 | { | ||
| 162 | // ...implementation goes here... | ||
| 163 | 0 | (5) | return 0; |
| 164 | } | ||
| 165 | |||
| 166 | } |
|
|
(6) | class org.jcoderz.guidelines.snippets.JCoderZJavaExample defines fields that are used only as locals | |||
|
|
(7) | org.jcoderz.guidelines.snippets.JCoderZJavaExample.sClassVar1 isn't final but should be | |||
|
|
(8) | Unused field: org.jcoderz.guidelines.snippets.JCoderZJavaExample.mInstanceVar3 | |||
|
|
(9) | Unused field: org.jcoderz.guidelines.snippets.JCoderZJavaExample.sClassVar2 | |||
|
|
(1) | 61 | : | 26 | Variable 'sClassVar1' must be private and have accessor methods. |
|
|
(2) | 78 | : | 19 | Variable 'mInstanceVar2' must be private and have accessor methods. |
|
|
(3) | 142 | : | 9 | Catching 'Throwable' is not allowed. |
|
|
(4) | 147 | : | 0 | Comment matches to-do format '(TODO|FIXME|CHECKME)'. |
|
|
(5) | 163 | : | 0 | private method org.jcoderz.guidelines.snippets.JCoderZJavaExample.doSometingFine() only returns one constant value |