Field.java

Index Score
org.apache.commons.validator
Commons Validator

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
COMMENTSComment lines
LOOPSNumber of loops
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
SIZESize of the file in bytes
RETURNSNumber of return points from functions
CYCLOMATICCyclomatic complexity
JAVA0179JAVA0179 Local variable hides visible field
INTERFACE_COMPLEXITYInterface complexity
LINESNumber of lines in the source file
BLOCKSNumber of blocks
EXITSProcedure exits
FUNCTIONSNumber of function declarations
JAVA0075JAVA0075 Method parameter hides field
OPERATORSNumber of operators
COMPARISONSNumber of comparison operators
PROGRAM_LENGTHHalstead program length
PARAMSNumber of formal parameter declarations
LOGICAL_LINESNumber of statements
OPERANDSNumber of operands
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
JAVA0034JAVA0034 Missing braces in if statement
LOCLines of code
ELOCEffective lines of code
WHITESPACENumber of whitespace lines
UNIQUE_OPERATORSNumber of unique operators
JAVA0117JAVA0117 Missing javadoc: method 'method'
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0145JAVA0145 Tab character used in source file
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.validator; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.collections.FastHashMap; // DEPRECATED import org.apache.commons.validator.util.ValidatorUtils; /** * This contains the list of pluggable validators to run on a field and any * message information and variables to perform the validations and generate * error messages. Instances of this class are configured with a * &lt;field&gt; xml element. * <p> * The use of FastHashMap is deprecated and will be replaced in a future * release. * </p> * * @version $Revision: 591548 $ $Date: 2007-11-02 23:43:41 -0400 (Fri, 02 Nov 2007) $ * @see org.apache.commons.validator.Form */ public class Field implements Cloneable, Serializable { /** * This is the value that will be used as a key if the <code>Arg</code> * name field has no value. */ private static final String DEFAULT_ARG = "org.apache.commons.validator.Field.DEFAULT"; /** * This indicates an indexed property is being referenced. */ public static final String TOKEN_INDEXED = "[]"; /** * The start of a token. */ protected static final String TOKEN_START = "${"; /** * The end of a token. */ protected static final String TOKEN_END = "}"; /** * A Vriable token. */ protected static final String TOKEN_VAR = "var:"; /** * The Field's property name. */ protected String property = null; /** * The Field's indexed property name. */ protected String indexedProperty = null; /** * The Field's indexed list property name. */ protected String indexedListProperty = null; /** * The Field's unique key. */ protected String key = null; /** * A comma separated list of validator's this field depends on. */ protected String depends = null; /** * The Page Number */ protected int page = 0; /** * The flag that indicates whether scripting should be generated * by the client for client-side validation. * @since Validator 1.4 */ protected boolean clientValidation = true; /** * The order of the Field in the Form. */ protected int fieldOrder = 0; /** * Internal representation of this.depends String as a List. This List * gets updated whenever setDepends() gets called. This List is * synchronized so a call to setDepends() (which clears the List) won't * interfere with a call to isDependency(). */ private List dependencyList = Collections.synchronizedList(new ArrayList()); /** * @deprecated Subclasses should use getVarMap() instead. */ protected FastHashMap hVars = new FastHashMap(); /** * @deprecated Subclasses should use getMsgMap() instead. */ protected FastHashMap hMsgs = new FastHashMap(); /** * Holds Maps of arguments. args[0] returns the Map for the first * replacement argument. Start with a 0 length array so that it will * only grow to the size of the highest argument position. * @since Validator 1.1 */ protected Map[] args = new Map[0]; /** * Gets the page value that the Field is associated with for * validation. * @return The page number. */ public int getPage() { return this.page; } /** * Sets the page value that the Field is associated with for * validation. * @param page The page number. */ public void setPage(int page) { this.page = page; } /** * Gets the position of the <code>Field</code> in the validation list. * @return The field position. */ public int getFieldOrder() { return this.fieldOrder; } /** * Sets the position of the <code>Field</code> in the validation list. * @param fieldOrder The field position. */ public void setFieldOrder(int fieldOrder) { this.fieldOrder = fieldOrder; } /** * Gets the property name of the field. * @return The field's property name. */ public String getProperty() { return this.property; } /** * Sets the property name of the field. * @param property The field's property name. */ public void setProperty(String property) { this.property = property; } /** * Gets the indexed property name of the field. This * is the method name that can take an <code>int</code> as * a parameter for indexed property value retrieval. * @return The field's indexed property name. */ public String getIndexedProperty() { return this.indexedProperty; } /** * Sets the indexed property name of the field. * @param indexedProperty The field's indexed property name. */ public void setIndexedProperty(String indexedProperty) { this.indexedProperty = indexedProperty; } /** * Gets the indexed property name of the field. This * is the method name that will return an array or a * <code>Collection</code> used to retrieve the * list and then loop through the list performing the specified * validations. * @return The field's indexed List property name. */ public String getIndexedListProperty() { return this.indexedListProperty; } /** * Sets the indexed property name of the field. * @param indexedListProperty The field's indexed List property name. */ public void setIndexedListProperty(String indexedListProperty) { this.indexedListProperty = indexedListProperty; } /** * Gets the validation rules for this field as a comma separated list. * @return A comma separated list of validator names. */ public String getDepends() { return this.depends; } /** * Sets the validation rules for this field as a comma separated list. * @param depends A comma separated list of validator names. */ public void setDepends(String depends) { this.depends = depends; this.dependencyList.clear(); StringTokenizer st = new StringTokenizer(depends, ","); while (st.hasMoreTokens()) { String depend = st.nextToken().trim(); if (depend != null && depend.length() > 0) { this.dependencyList.add(depend); } } } /** * Add a <code>Msg</code> to the <code>Field</code>. * @param msg A validation message. */ public void addMsg(Msg msg) { hMsgs.put(msg.getName(), msg); } /** * Retrieve a message value. * @param key Validation key. * @return A validation message for a specified validator. */ public String getMsg(String key) { Msg msg = getMessage(key); return (msg == null) ? null : msg.getKey(); } /** * Retrieve a message object. * @since Validator 1.1.4 * @param key Validation key. * @return A validation message for a specified validator. */ public Msg getMessage(String key) { return (Msg) hMsgs.get(key); } /** * The <code>Field</code>'s messages are returned as an * unmodifiable <code>Map</code>. * @since Validator 1.1.4 * @return Map of validation messages for the field. */ public Map getMessages() { return Collections.unmodifiableMap(hMsgs); } /** * Determines whether client-side scripting should be generated * for this field. The default is <code>true</code> * @return <code>true</code> for scripting; otherwise false * @see #setClientValidation(boolean) * @since Validator 1.4 */ public boolean isClientValidation() { return this.clientValidation; } /** * Sets the flag that determines whether client-side scripting should * be generated for this field. * @param clientValidation the scripting flag * @see #isClientValidation() * @since Validator 1.4 */ public void setClientValidation(boolean clientValidation) { this.clientValidation = clientValidation; } /** * Add an <code>Arg</code> to the replacement argument list. * @since Validator 1.1 * @param arg Validation message's argument. */ public void addArg(Arg arg) { // TODO this first if check can go away after arg0, etc. are removed from dtd if (arg == null || arg.getKey() == null || arg.getKey().length() == 0) { return; } determineArgPosition(arg); ensureArgsCapacity(arg); Map argMap = this.args[arg.getPosition()]; if (argMap == null) { argMap = new HashMap(); this.args[arg.getPosition()] = argMap; } if (arg.getName() == null) { argMap.put(DEFAULT_ARG, arg); } else { argMap.put(arg.getName(), arg); } } /** * Calculate the position of the Arg */ private void determineArgPosition(Arg arg) { int position = arg.getPosition(); // position has been explicity set if (position >= 0) { return; } // first arg to be added if (args == null || args.length == 0) { arg.setPosition(0); return; } // determine the position of the last argument with // the same name or the last default argument String key = arg.getName() == null ? DEFAULT_ARG : arg.getName(); int lastPosition = -1; int lastDefault = -1; for (int i = 0; i < args.length; i++) { if (args[i] != null && args[i].containsKey(key)) { lastPosition = i; } if (args[i] != null && args[i].containsKey(DEFAULT_ARG)) { lastDefault = i; } } if (lastPosition < 0) { lastPosition = lastDefault; } // allocate the next position arg.setPosition(++lastPosition); } /** * Ensures that the args array can hold the given arg. Resizes the array as * necessary. * @param arg Determine if the args array is long enough to store this arg's * position. */ private void ensureArgsCapacity(Arg arg) { if (arg.getPosition() >= this.args.length) { Map[] newArgs = new Map[arg.getPosition() + 1]; System.arraycopy(this.args, 0, newArgs, 0, this.args.length); this.args = newArgs; } } /** * Gets the default <code>Arg</code> object at the given position. * @param position Validation message argument's position. * @return The default Arg or null if not found. * @since Validator 1.1 */ public Arg getArg(int position) { return this.getArg(DEFAULT_ARG, position); } /** * Gets the <code>Arg</code> object at the given position. If the key * finds a <code>null</code> value then the default value will be * retrieved. * @param key The name the Arg is stored under. If not found, the default * Arg for the given position (if any) will be retrieved. * @param position The Arg number to find. * @return The Arg with the given name and position or null if not found. * @since Validator 1.1 */ public Arg getArg(String key, int position) { if ((position >= this.args.length) || (this.args[position] == null)) { return null; } Arg arg = (Arg) args[position].get(key); // Didn't find default arg so exit, otherwise we would get into // infinite recursion if ((arg == null) && key.equals(DEFAULT_ARG)) { return null; } return (arg == null) ? this.getArg(position) : arg; } /** * Retrieves the Args for the given validator name. * @param key The validator's args to retrieve. * @return An Arg[] sorted by the Args' positions (i.e. the Arg at index 0 * has a position of 0). * @since Validator 1.1.1 */ public Arg[] getArgs(String key){ Arg[] args = new Arg[this.args.length]; for (int i = 0; i < this.args.length; i++) { args[i] = this.getArg(key, i); } return args; } /** * Add a <code>Var</code> to the <code>Field</code>. * @param v The Validator Argument. */ public void addVar(Var v) { this.hVars.put(v.getName(), v); } /** * Add a <code>Var</code>, based on the values passed in, to the * <code>Field</code>. * @param name Name of the validation. * @param value The Argument's value. * @param jsType The Javascript type. */ public void addVar(String name, String value, String jsType) { this.addVar(new Var(name, value, jsType)); } /** * Retrieve a variable. * @param mainKey The Variable's key * @return the Variable */ public Var getVar(String mainKey) { return (Var) hVars.get(mainKey); } /** * Retrieve a variable's value. * @param mainKey The Variable's key * @return the Variable's value */ public String getVarValue(String mainKey) { String value = null; Object o = hVars.get(mainKey); if (o != null && o instanceof Var) { Var v = (Var) o; value = v.getValue(); } return value; } /** * The <code>Field</code>'s variables are returned as an * unmodifiable <code>Map</code>. * @return the Map of Variable's for a Field. */ public Map getVars() { return Collections.unmodifiableMap(hVars); } /** * Gets a unique key based on the property and indexedProperty fields. * @return a unique key for the field. */ public String getKey() { if (this.key == null) { this.generateKey(); } return this.key; } /** * Sets a unique key for the field. This can be used to change * the key temporarily to have a unique key for an indexed field. * @param key a unique key for the field */ public void setKey(String key) { this.key = key; } /** * If there is a value specified for the indexedProperty field then * <code>true</code> will be returned. Otherwise it will be * <code>false</code>. * @return Whether the Field is indexed. */ public boolean isIndexed() { return ((indexedListProperty != null && indexedListProperty.length() > 0)); } /** * Generate correct <code>key</code> value. */ public void generateKey() { if (this.isIndexed()) { this.key = this.indexedListProperty + TOKEN_INDEXED + "." + this.property; } else { this.key = this.property; } } /** * Replace constants with values in fields and process the depends field * to create the dependency <code>Map</code>. */ void process(Map globalConstants, Map constants) { this.hMsgs.setFast(false); this.hVars.setFast(true); this.generateKey(); // Process FormSet Constants for (Iterator i = constants.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); String key2 = TOKEN_START + key + TOKEN_END; String replaceValue = (String) constants.get(key); property = ValidatorUtils.replace(property, key2, replaceValue); processVars(key2, replaceValue); this.processMessageComponents(key2, replaceValue); } // Process Global Constants for (Iterator i = globalConstants.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); String key2 = TOKEN_START + key + TOKEN_END; String replaceValue = (String) globalConstants.get(key); property = ValidatorUtils.replace(property, key2, replaceValue); processVars(key2, replaceValue); this.processMessageComponents(key2, replaceValue); } // Process Var Constant Replacement for (Iterator i = hVars.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); String key2 = TOKEN_START + TOKEN_VAR + key + TOKEN_END; Var var = this.getVar(key); String replaceValue = var.getValue(); this.processMessageComponents(key2, replaceValue); } hMsgs.setFast(true); } /** * Replace the vars value with the key/value pairs passed in. */ private void processVars(String key, String replaceValue) { Iterator i = this.hVars.keySet().iterator(); while (i.hasNext()) { String varKey = (String) i.next(); Var var = this.getVar(varKey); var.setValue(ValidatorUtils.replace(var.getValue(), key, replaceValue)); } } /** * Replace the args key value with the key/value pairs passed in. */ private void processMessageComponents(String key, String replaceValue) { String varKey = TOKEN_START + TOKEN_VAR; // Process Messages if (key != null && !key.startsWith(varKey)) { for (Iterator i = hMsgs.values().iterator(); i.hasNext();) { Msg msg = (Msg) i.next(); msg.setKey(ValidatorUtils.replace(msg.getKey(), key, replaceValue)); } } this.processArg(key, replaceValue); } /** * Replace the arg <code>Collection</code> key value with the key/value * pairs passed in. */ private void processArg(String key, String replaceValue) { for (int i = 0; i < this.args.length; i++) { Map argMap = this.args[i]; if (argMap == null) { continue; } Iterator iter = argMap.values().iterator(); while (iter.hasNext()) { Arg arg = (Arg) iter.next(); if (arg != null) { arg.setKey( ValidatorUtils.replace(arg.getKey(), key, replaceValue)); } } } } /** * Checks if the validator is listed as a dependency. * @param validatorName Name of the validator to check. * @return Whether the field is dependant on a validator. */ public boolean isDependency(String validatorName) { return this.dependencyList.contains(validatorName); } /** * Gets an unmodifiable <code>List</code> of the dependencies in the same * order they were defined in parameter passed to the setDepends() method. * @return A list of the Field's dependancies. */ public List getDependencyList() { return Collections.unmodifiableList(this.dependencyList); } /** * Creates and returns a copy of this object. * @return A copy of the Field. */ public Object clone() { Field field = null; try { field = (Field) super.clone(); } catch(CloneNotSupportedException e) { throw new RuntimeException(e.toString()); } field.args = new Map[this.args.length]; for (int i = 0; i < this.args.length; i++) { if (this.args[i] == null) { continue; } Map argMap = new HashMap(this.args[i]); Iterator iter = argMap.keySet().iterator(); while (iter.hasNext()) { String validatorName = (String) iter.next(); Arg arg = (Arg) argMap.get(validatorName); argMap.put(validatorName, arg.clone()); } field.args[i] = argMap; } field.hVars = ValidatorUtils.copyFastHashMap(hVars); field.hMsgs = ValidatorUtils.copyFastHashMap(hMsgs); return field; } /** * Returns a string representation of the object. * @return A string representation of the object. */ public String toString() { StringBuffer results = new StringBuffer(); results.append("\t\tkey = " + key + "\n"); results.append("\t\tproperty = " + property + "\n"); results.append("\t\tindexedProperty = " + indexedProperty + "\n"); results.append("\t\tindexedListProperty = " + indexedListProperty + "\n"); results.append("\t\tdepends = " + depends + "\n"); results.append("\t\tpage = " + page + "\n"); results.append("\t\tfieldOrder = " + fieldOrder + "\n"); if (hVars != null) { results.append("\t\tVars:\n"); for (Iterator i = hVars.keySet().iterator(); i.hasNext();) { Object key = i.next(); results.append("\t\t\t"); results.append(key); results.append("="); results.append(hVars.get(key)); results.append("\n"); } } return results.toString(); } /** * Returns an indexed property from the object we're validating. * * @param bean The bean to extract the indexed values from. * @throws ValidatorException If there's an error looking up the property * or, the property found is not indexed. */ Object[] getIndexedProperty(Object bean) throws ValidatorException { Object indexedProperty = null; try { indexedProperty = PropertyUtils.getProperty(bean, this.getIndexedListProperty()); } catch(IllegalAccessException e) { throw new ValidatorException(e.getMessage()); } catch(InvocationTargetException e) { throw new ValidatorException(e.getMessage()); } catch(NoSuchMethodException e) { throw new ValidatorException(e.getMessage()); } if (indexedProperty instanceof Collection) { return ((Collection) indexedProperty).toArray(); } else if (indexedProperty.getClass().isArray()) { return (Object[]) indexedProperty; } else { throw new ValidatorException(this.getKey() + " is not indexed"); } } /** * Returns the size of an indexed property from the object we're validating. * * @param bean The bean to extract the indexed values from. * @throws ValidatorException If there's an error looking up the property * or, the property found is not indexed. */ private int getIndexedPropertySize(Object bean) throws ValidatorException { Object indexedProperty = null; try { indexedProperty = PropertyUtils.getProperty(bean, this.getIndexedListProperty()); } catch(IllegalAccessException e) { throw new ValidatorException(e.getMessage()); } catch(InvocationTargetException e) { throw new ValidatorException(e.getMessage()); } catch(NoSuchMethodException e) { throw new ValidatorException(e.getMessage()); } if (indexedProperty == null) { return 0; } else if (indexedProperty instanceof Collection) { return ((Collection)indexedProperty).size(); } else if (indexedProperty.getClass().isArray()) { return ((Object[])indexedProperty).length; } else { throw new ValidatorException(this.getKey() + " is not indexed"); } } /** * Executes the given ValidatorAction and all ValidatorActions that it * depends on. * @return true if the validation succeeded. */ private boolean validateForRule( ValidatorAction va, ValidatorResults results, Map actions, Map params, int pos) throws ValidatorException { ValidatorResult result = results.getValidatorResult(this.getKey()); if (result != null && result.containsAction(va.getName())) { return result.isValid(va.getName()); } if (!this.runDependentValidators(va, results, actions, params, pos)) { return false; } return va.executeValidationMethod(this, params, results, pos); } /** * Calls all of the validators that this validator depends on. * TODO ValidatorAction should know how to run its own dependencies. * @param va Run dependent validators for this action. * @param results * @param actions * @param pos * @return true if all of the dependent validations passed. * @throws ValidatorException If there's an error running a validator */ private boolean runDependentValidators( ValidatorAction va, ValidatorResults results, Map actions, Map params, int pos) throws ValidatorException { List dependentValidators = va.getDependencyList(); if (dependentValidators.isEmpty()) { return true; } Iterator iter = dependentValidators.iterator(); while (iter.hasNext()) { String depend = (String) iter.next(); ValidatorAction action = (ValidatorAction) actions.get(depend); if (action == null) { this.handleMissingAction(depend); } if (!this.validateForRule(action, results, actions, params, pos)) { return false; } } return true; } /** * Run the configured validations on this field. Run all validations * in the depends clause over each item in turn, returning when the first * one fails. * @param params A Map of parameter class names to parameter values to pass * into validation methods. * @param actions A Map of validator names to ValidatorAction objects. * @return A ValidatorResults object containing validation messages for * this field. * @throws ValidatorException If an error occurs during validation. */ public ValidatorResults validate(Map params, Map actions) throws ValidatorException { if (this.getDepends() == null) { return new ValidatorResults(); } ValidatorResults allResults = new ValidatorResults(); Object bean = params.get(Validator.BEAN_PARAM); int numberOfFieldsToValidate = this.isIndexed() ? this.getIndexedPropertySize(bean) : 1; for (int fieldNumber = 0; fieldNumber < numberOfFieldsToValidate; fieldNumber++) { Iterator dependencies = this.dependencyList.iterator(); ValidatorResults results = new ValidatorResults(); while (dependencies.hasNext()) { String depend = (String) dependencies.next(); ValidatorAction action = (ValidatorAction) actions.get(depend); if (action == null) { this.handleMissingAction(depend); } boolean good = validateForRule(action, results, actions, params, fieldNumber); if (!good) { allResults.merge(results); return allResults; } } allResults.merge(results); } return allResults; } /** * Called when a validator name is used in a depends clause but there is * no know ValidatorAction configured for that name. * @param name The name of the validator in the depends list. * @throws ValidatorException */ private void handleMissingAction(String name) throws ValidatorException { throw new ValidatorException("No ValidatorAction named " + name + " found for field " + this.getProperty()); } /** * Returns a Map of String Msg names to Msg objects. * @since Validator 1.2.0 * @return A Map of the Field's messages. */ protected Map getMsgMap() { return hMsgs; } /** * Returns a Map of String Var names to Var objects. * @since Validator 1.2.0 * @return A Map of the Field's variables. */ protected Map getVarMap() { return hVars; } }

The table below shows all metrics for Field.java.

MetricValueDescription
BLOCKS112.00Number of blocks
BLOCK_COMMENT16.00Number of block comment lines
COMMENTS361.00Comment lines
COMMENT_DENSITY 1.05Comment density
COMPARISONS70.00Number of comparison operators
CYCLOMATIC121.00Cyclomatic complexity
DECL_COMMENTS68.00Comments in declarations
DOC_COMMENT333.00Number of javadoc comment lines
ELOC344.00Effective lines of code
EXEC_COMMENTS10.00Comments in executable code
EXITS81.00Procedure exits
FUNCTIONS49.00Number of function declarations
HALSTEAD_DIFFICULTY85.61Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY127.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 7.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA010815.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 2.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 1.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 0.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA0145 0.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 0.00JAVA0177 Variable declaration missing initializer
JAVA0179 8.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 1.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA025410.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES948.00Number of lines in the source file
LINE_COMMENT12.00Number of line comments
LOC443.00Lines of code
LOGICAL_LINES231.00Number of statements
LOOPS16.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS1057.00Number of operands
OPERATORS2143.00Number of operators
PARAMS48.00Number of formal parameter declarations
PROGRAM_LENGTH3200.00Halstead program length
PROGRAM_VOCAB373.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS79.00Number of return points from functions
SIZE29447.00Size of the file in bytes
UNIQUE_OPERANDS321.00Number of unique operands
UNIQUE_OPERATORS52.00Number of unique operators
WHITESPACE144.00Number of whitespace lines