TemplateCache.java

Index Score
freemarker.cache
FreeMarker

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
SIZESize of the file in bytes
BLOCKSNumber of blocks
CYCLOMATICCyclomatic complexity
JAVA0143JAVA0143 Synchronized method
JAVA0123JAVA0123 Use all three components of for loop
INTERFACE_COMPLEXITYInterface complexity
LOCLines of code
COMPARISONSNumber of comparison operators
PARAMSNumber of formal parameter declarations
RETURNSNumber of return points from functions
LOGICAL_LINESNumber of statements
EXITSProcedure exits
LINESNumber of lines in the source file
ELOCEffective lines of code
PROGRAM_VOCABHalstead program vocabulary
UNIQUE_OPERANDSNumber of unique operands
JAVA0034JAVA0034 Missing braces in if statement
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
OPERATORSNumber of operators
COMMENTSComment lines
EXEC_COMMENTSComments in executable code
JAVA0177JAVA0177 Variable declaration missing initializer
LINE_COMMENTNumber of line comments
DOC_COMMENTNumber of javadoc comment lines
UNIQUE_OPERATORSNumber of unique operators
JAVA0163JAVA0163 Empty statement
JAVA0150JAVA0150 java.lang.Error (or subclass) thrown
DECL_COMMENTSComments in declarations
LOOPSNumber of loops
JAVA0166JAVA0166 Generic exception caught
PROGRAM_VOLUMEHalstead program volume
FUNCTIONSNumber of function declarations
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0173JAVA0173 Unused method parameter
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0130JAVA0130 Non-static method does not use instance fields
JAVA0075JAVA0075 Method parameter hides field
WHITESPACENumber of whitespace lines
NEST_DEPTHMaximum nesting depth
JAVA0145JAVA0145 Tab character used in source file
/* * Copyright (c) 2003 The Visigoth Software Society. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowledgement: * "This product includes software developed by the * Visigoth Software Society (http://www.visigoths.org/)." * Alternately, this acknowledgement may appear in the software itself, * if and wherever such third-party acknowledgements normally appear. * * 4. Neither the name "FreeMarker", "Visigoth", nor any of the names of the * project contributors may be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact visigoths@visigoths.org. * * 5. Products derived from this software may not be called "FreeMarker" or "Visigoth" * nor may "FreeMarker" or "Visigoth" appear in their names * without prior written permission of the Visigoth Software Society. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE VISIGOTH SOFTWARE SOCIETY OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Visigoth Software Society. For more * information on the Visigoth Software Society, please see * http://www.visigoths.org/ */ package freemarker.cache; import java.io.IOException; import java.io.Reader; import java.io.Serializable; import java.io.StringWriter; import java.lang.reflect.UndeclaredThrowableException; import java.security.CodeSource; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.StringTokenizer; import freemarker.core.Environment; import freemarker.log.Logger; import freemarker.template.Configuration; import freemarker.template.Template; /** * A class that performs caching and on-demand loading of the templates. * The actual loading is delegated to a {@link TemplateLoader}. Also, * various constructors provide you with convenient caches with predefined * behavior. Typically you don't use this class directly - in normal * circumstances it is hidden behind a {@link Configuration}. * @author Attila Szegedi, szegedia at freemail dot hu * @version $Id: TemplateCache.java,v 1.62 2004/03/17 01:14:33 ddekany Exp $ */ public class TemplateCache { private static final String ASTERISKSTR = "*"; private static final String LOCALE_SEPARATOR = "_"; private static final char ASTERISK = '*'; private static final String CURRENT_DIR_PATH_PREFIX = "./"; private static final String CURRENT_DIR_PATH = "/./"; private static final String PARENT_DIR_PATH_PREFIX = "../"; private static final String PARENT_DIR_PATH = "/../"; private static final char SLASH = '/'; private static final Logger logger = Logger.getLogger("freemarker.cache"); private final TemplateLoader mainLoader; /** Here we keep our cached templates */ private final CacheStorage storage; private final boolean isStorageConcurrent; /** The default refresh delay in milliseconds. */ private long delay = 5000; /** Specifies if localized template lookup is enabled or not */ private boolean localizedLookup = true; private Configuration config; /** * Returns a template cache that will first try to load a template from * the file system relative to the current user directory (i.e. the value * of the system property <code>user.dir</code>), then from the classpath. * This default template cache suits many applications. */ public TemplateCache() { this(createDefaultTemplateLoader()); } private static TemplateLoader createDefaultTemplateLoader() { try { return new FileTemplateLoader(); } catch(Exception e) { logger.warn("Could not create a file template loader for current directory", e); return null; } } /** * Creates a new template cache with a custom template loader that is used * to load the templates. * @param loader the template loader to use. */ public TemplateCache(TemplateLoader loader) { this(loader, new SoftCacheStorage()); } /** * Creates a new template cache with a custom template loader and cache * storage that are used to load and store the templates. * @param loader the template loader to use. * @param storage the cache storage to use */ public TemplateCache(TemplateLoader loader, CacheStorage storage) { this.mainLoader = loader; this.storage = storage; if(storage == null) { throw new IllegalArgumentException("storage == null"); } isStorageConcurrent = storage instanceof ConcurrentCacheStorage && ((ConcurrentCacheStorage)storage).isConcurrent(); } /** * Sets the configuration object to which this cache belongs. This method * is called by the configuration itself to establish the relation, and * should not be called by users. * @param config the configuration that this cache belongs to */ public void setConfiguration(Configuration config) { this.config = config; clear(); } /** * Returns the template loader used by this cache. * @return the template loader used by this cache. */ public TemplateLoader getTemplateLoader() { return mainLoader; } /** * Returns the cache storage used by this cache. * @return the cache storage used by this cache. */ public CacheStorage getCacheStorage() { return storage; } /** * Loads a template with the given name, in the specified locale and * using the specified character encoding. * * @param name the name of the template. Can't be null. The exact syntax of the name * is interpreted by the underlying {@link TemplateLoader}, but the * cache makes some assumptions. First, the name is expected to be * a hierarchical path, with path components separated by a slash * character (not with backslash!). The path (the name) must <em>not</em> begin with slash; * the path is always relative to the "template root directory". * Then, the <tt>..</tt> and <tt>.</tt> path metaelements will be resolved. * For example, if the name is <tt>a/../b/./c.ftl</tt>, then it will be * simplified to <tt>b/c.ftl</tt>. The rules regarding this are same as with conventional * UN*X paths. The path must not reach outside the template root directory, that is, * it can't be something like <tt>"../templates/my.ftl"</tt> (not even if the pervious path * happens to be equivalent with <tt>"/my.ftl"</tt>). * Further, the path is allowed to contain at most * one path element whose name is <tt>*</tt> (asterisk). This path metaelement triggers the * <i>acquisition mechanism</i>. If the template is not found in * the location described by the concatenation of the path left to the * asterisk (called base path) and the part to the right of the asterisk * (called resource path), the cache will attempt to remove the rightmost * path component from the base path ("go up one directory") and concatenate * that with the resource path. The process is repeated until either a * template is found, or the base path is completely exhausted. * * @param locale the requested locale of the template. Can't be null. * Assuming you have specified <code>en_US</code> as the locale and * <code>myTemplate.html</code> as the name of the template, the cache will * first try to retrieve <code>myTemplate_en_US.html</code>, then * <code>myTemplate_en.html</code>, and finally * <code>myTemplate.html</code>. * * @param encoding the character encoding used to interpret the template * source bytes. Can't be null. * * @param parse if true, the loaded template is parsed and interpreted * as a regular FreeMarker template. If false, the loaded template is * treated as an unparsed block of text. * * @return the loaded template, or null if the template is not found. * @throws IOException if an I/O exception occurs while loading the * template */ public Template getTemplate(String name, Locale locale, String encoding, boolean parse) throws IOException { if (name == null) { throw new IllegalArgumentException("Argument \"name\" can't be null"); } if (locale == null) { throw new IllegalArgumentException("Argument \"locale\" can't be null"); } if (encoding == null) { throw new IllegalArgumentException("Argument \"encoding\" can't be null"); } name = normalizeName(name); if(name == null) { return null; } Template result = null; if (mainLoader != null) { result = getTemplate(mainLoader, name, locale, encoding, parse); } return result; } private Template getTemplate(TemplateLoader loader, String name, Locale locale, String encoding, boolean parse) throws IOException { boolean debug = logger.isDebugEnabled(); String debugName = debug ? name + "[" + locale + "," + encoding + (parse ? ",parsed] " : ",unparsed] ") : null; TemplateKey tk = new TemplateKey(name, locale, encoding, parse); CachedTemplate cachedTemplate; if(isStorageConcurrent) { cachedTemplate = (CachedTemplate)storage.get(tk); } else { synchronized(storage) { cachedTemplate = (CachedTemplate)storage.get(tk); } } long now = System.currentTimeMillis(); long lastModified = -1L; Object newlyFoundSource = null; boolean rethrown = false; try { if (cachedTemplate != null) { // If we're within the refresh delay, return the cached copy if (now - cachedTemplate.lastChecked < delay) { if(debug) { logger.debug(debugName + "cached copy not yet stale; using cached."); } // Can be null, indicating a cached negative lookup Object t = cachedTemplate.templateOrException; if(t instanceof Template || t == null) { return (Template)t; } else if(t instanceof RuntimeException) { throwLoadFailedException((RuntimeException)t); } else if(t instanceof IOException) { rethrown = true; throwLoadFailedException((IOException)t); } throw new AssertionError("t is " + t.getClass().getName()); } // Clone as the instance bound to the map should be treated as // immutable to ensure proper concurrent semantics cachedTemplate = cachedTemplate.cloneCachedTemplate(); // Update the last-checked flag cachedTemplate.lastChecked = now; // Find the template source newlyFoundSource = findTemplateSource(name, locale); // Template source was removed if (newlyFoundSource == null) { if(debug) { logger.debug(debugName + "no source found."); } storeNegativeLookup(tk, cachedTemplate, null); return null; } // If the source didn't change and its last modified date // also didn't change, return the cached version. lastModified = loader.getLastModified(newlyFoundSource); boolean lastModifiedNotChanged = lastModified == cachedTemplate.lastModified; boolean sourceEquals = newlyFoundSource.equals(cachedTemplate.source); if(lastModifiedNotChanged && sourceEquals) { if(debug) { logger.debug(debugName + "using cached since " + newlyFoundSource + " didn't change."); } storeCached(tk, cachedTemplate); return (Template)cachedTemplate.templateOrException; } else { if(debug && !sourceEquals) { logger.debug("Updating source, info for cause: " + "sourceEquals=" + sourceEquals + ", newlyFoundSource=" + newlyFoundSource + ", cachedTemplate.source=" + cachedTemplate.source); } if(debug && !lastModifiedNotChanged) { logger.debug("Updating source, info for cause: " + "lastModifiedNotChanged=" + lastModifiedNotChanged + ", cache lastModified=" + cachedTemplate.lastModified + " != file lastModified=" + lastModified); } // Update the source cachedTemplate.source = newlyFoundSource; } } else { if(debug) { logger.debug("Could not find template in cache, " + "creating new one; id=[" + tk.name + "[" + tk.locale + "," + tk.encoding + (tk.parse ? ",parsed] " : ",unparsed] ") + "]"); } // Construct a new CachedTemplate entry. Note we set the // cachedTemplate.lastModified to Long.MIN_VALUE. This is // a flag that signs it has to be explicitly queried later on. cachedTemplate = new CachedTemplate(); cachedTemplate.lastChecked = now; newlyFoundSource = findTemplateSource(name, locale); if (newlyFoundSource == null) { storeNegativeLookup(tk, cachedTemplate, null); return null; } cachedTemplate.source = newlyFoundSource; cachedTemplate.lastModified = lastModified = Long.MIN_VALUE; } if(debug) { logger.debug("Compiling FreeMarker template " + debugName + " from " + newlyFoundSource); } // If we get here, then we need to (re)load the template Object source = cachedTemplate.source; Template t = loadTemplate(loader, name, locale, encoding, parse, source); cachedTemplate.templateOrException = t; cachedTemplate.lastModified = lastModified == Long.MIN_VALUE ? loader.getLastModified(source) : lastModified; storeCached(tk, cachedTemplate); return t; } catch(RuntimeException e) { storeNegativeLookup(tk, cachedTemplate, e); throw e; } catch(IOException e) { if(!rethrown) { storeNegativeLookup(tk, cachedTemplate, e); } throw e; } finally { if(newlyFoundSource != null) { loader.closeTemplateSource(newlyFoundSource); } } } private void throwLoadFailedException(Exception e) throws IOException { IOException ioe = new IOException("There was an error loading the " + "template on an earlier attempt; it is attached as a cause"); ioe.initCause(e); throw ioe; } private void storeNegativeLookup(TemplateKey tk, CachedTemplate cachedTemplate, Exception e) { cachedTemplate.templateOrException = e; cachedTemplate.source = null; cachedTemplate.lastModified = 0L; storeCached(tk, cachedTemplate); } private void storeCached(TemplateKey tk, CachedTemplate cachedTemplate) { if(isStorageConcurrent) { storage.put(tk, cachedTemplate); } else { synchronized(storage) { storage.put(tk, cachedTemplate); } } } private Template loadTemplate(TemplateLoader loader, String name, Locale locale, String encoding, boolean parse, Object source) throws IOException { Template template; CodeSource codeSource; if(config.isSecure() && loader instanceof SecureTemplateLoader) { codeSource = ((SecureTemplateLoader)loader).getCodeSource(source); } else { codeSource = null; } Reader reader = loader.getReader(source, encoding); try { if(parse) { try { template = createTemplate(name, reader, config, encoding, codeSource); } catch (Template.WrongEncodingException wee) { encoding = wee.specifiedEncoding; reader = loader.getReader(source, encoding); template = createTemplate(name, reader, config, encoding, codeSource); } template.setLocale(locale); } else { // Read the contents into a StringWriter, then construct a single-textblock // template from it. StringWriter sw = new StringWriter(); char[] buf = new char[4096]; for(;;) { int charsRead = reader.read(buf); if (charsRead > 0) { sw.write(buf, 0, charsRead); } else if(charsRead == -1) { break; } } template = Template.getPlainTextTemplate(name, sw.toString(), config); template.setLocale(locale); } template.setEncoding(encoding); } finally { reader.close(); } return template; } /** * Gets the delay in milliseconds between checking for newer versions of a * template source. * @return the current value of the delay */ public synchronized long getDelay() { return delay; } /** * Sets the delay in milliseconds between checking for newer versions of a * template sources. * @param delay the new value of the delay */ public synchronized void setDelay(long delay) { this.delay = delay; } /** * Returns if localized template lookup is enabled or not. * @return true if localized template lookup is enabled, false otherwise. */ public synchronized boolean getLocalizedLookup() { return localizedLookup; } /** * Sets whether to enable localized template lookup or not. * @param localizedLookup true to enable localized template lookup, false * to disable it. */ public synchronized void setLocalizedLookup(boolean localizedLookup) { this.localizedLookup = localizedLookup; } /** * Removes all entries from the cache, forcing reloading of templates * on subsequent {@link #getTemplate(String, Locale, String, boolean)} * calls. */ public void clear() { synchronized (storage) { storage.clear(); if(mainLoader instanceof StatefulTemplateLoader) { ((StatefulTemplateLoader)mainLoader).resetState(); } } } /** * Resolves a relative template path to absolute template path for purposes * of an inclusion via the include directive. Can only be invoked during * template processing. * @param env the Environment associated with the current thread. * @param parentTemplateDir the absolute directory path of the template * containing the include directive. * @param templateNameString the potentially relative path specified in the * include directive. * @return the absolute path resolved against the specified parent * directory. */ public static String getFullTemplatePath(Environment env, String parentTemplateDir, String templateNameString) { if (templateNameString.indexOf("://") >0) { ; } else if (templateNameString.length() > 0 && templateNameString.charAt(0) == '/') { int protIndex = parentTemplateDir.indexOf("://"); if (protIndex >0) { templateNameString = parentTemplateDir.substring(0, protIndex + 2) + templateNameString; } else { templateNameString = templateNameString.substring(1); } } else { templateNameString = parentTemplateDir + templateNameString; } return templateNameString; } private Object findTemplateSource(String name, Locale locale) throws IOException { if (getLocalizedLookup()) { int lastDot = name.lastIndexOf('.'); String prefix = lastDot == -1 ? name : name.substring(0, lastDot); String suffix = lastDot == -1 ? "" : name.substring(lastDot); String localeName = LOCALE_SEPARATOR + locale.toString(); StringBuilder buf = new StringBuilder(name.length() + localeName.length()); buf.append(prefix); for (;;) { buf.setLength(prefix.length()); String path = buf.append(localeName).append(suffix).toString(); Object templateSource = acquireTemplateSource(path); if (templateSource != null) { return templateSource; } int lastUnderscore = localeName.lastIndexOf('_'); if (lastUnderscore == -1) { break; } localeName = localeName.substring(0, lastUnderscore); } return null; } else { return acquireTemplateSource(name); } } private Object acquireTemplateSource(String path) throws IOException { int asterisk = path.indexOf(ASTERISK); // Shortcut in case there is no acquisition if(asterisk == -1) { return mainLoader.findTemplateSource(path); } StringTokenizer tok = new StringTokenizer(path, "/"); int lastAsterisk = -1; List<String> tokpath = new ArrayList<String>(); while(tok.hasMoreTokens()) { String pathToken = tok.nextToken(); if(pathToken.equals(ASTERISKSTR)) { if(lastAsterisk != -1) { tokpath.remove(lastAsterisk); } lastAsterisk = tokpath.size(); } tokpath.add(pathToken); } String basePath = concatPath(tokpath, 0, lastAsterisk); String resourcePath = concatPath(tokpath, lastAsterisk + 1, tokpath.size()); if(resourcePath.endsWith("/")) { resourcePath = resourcePath.substring(0, resourcePath.length() - 1); } StringBuilder buf = new StringBuilder(path.length()).append(basePath); int l = basePath.length(); boolean debug = logger.isDebugEnabled(); for(;;) { String fullPath = buf.append(resourcePath).toString(); if(debug) { logger.debug("Trying to find template source " + fullPath); } Object templateSource = mainLoader.findTemplateSource(fullPath); if(templateSource != null) { return templateSource; } if(l == 0) { return null; } l = basePath.lastIndexOf(SLASH, l - 2) + 1; buf.setLength(l); } } private static String concatPath(List path, int from, int to) { StringBuilder buf = new StringBuilder((to - from) * 16); for(int i = from; i < to; ++i) { buf.append(path.get(i)).append('/'); } return buf.toString(); } protected Template createTemplate(String name, Reader reader, Configuration config, String encoding, CodeSource codeSource) throws IOException { return new Template(name, reader, config, encoding, codeSource); } private static String normalizeName(String name) { if (name.indexOf("://") >0) { return name; } for(;;) { int parentDirPathLoc = name.indexOf(PARENT_DIR_PATH); if(parentDirPathLoc == 0) { // If it starts with /../, then it reaches outside the template // root. return null; } if(parentDirPathLoc == -1) { if(name.startsWith(PARENT_DIR_PATH_PREFIX)) { // Another attempt to reach out of template root. return null; } break; } int previousSlashLoc = name.lastIndexOf(SLASH, parentDirPathLoc - 1); name = name.substring(0, previousSlashLoc + 1) + name.substring(parentDirPathLoc + PARENT_DIR_PATH.length()); } for(;;) { int currentDirPathLoc = name.indexOf(CURRENT_DIR_PATH); if(currentDirPathLoc == -1) { if(name.startsWith(CURRENT_DIR_PATH_PREFIX)) { name = name.substring(CURRENT_DIR_PATH_PREFIX.length()); } break; } name = name.substring(0, currentDirPathLoc) + name.substring(currentDirPathLoc + CURRENT_DIR_PATH.length() - 1); } // Editing can leave us with a leading slash; strip it. if(name.length() > 1 && name.charAt(0) == SLASH) { name = name.substring(1); } return name; } /** * This class holds a (name, locale) pair and is used as the key in * the cached templates map. */ private static final class TemplateKey { private final String name; private final Locale locale; private final String encoding; private final boolean parse; TemplateKey(String name, Locale locale, String encoding, boolean parse) { this.name = name; this.locale = locale; this.encoding = encoding; this.parse = parse; } public boolean equals(Object o) { if (o instanceof TemplateKey) { TemplateKey tk = (TemplateKey)o; return parse == tk.parse && name.equals(tk.name) && locale.equals(tk.locale) && encoding.equals(tk.encoding); } return false; } public int hashCode() { return name.hashCode() ^ locale.hashCode() ^ encoding.hashCode() ^ (parse ? Boolean.FALSE : Boolean.TRUE).hashCode(); } } /** * This class holds the cached template and associated information * (the source object, and the last-checked and last-modified timestamps). * It is used as the value in the cached templates map. Note: this class * is Serializable to allow custom 3rd party CacheStorage implementations * to serialize/replicate them; FreeMarker code itself doesn't rely on its * serializability. */ private static final class CachedTemplate implements Cloneable, Serializable { private static final long serialVersionUID = 1L; Object templateOrException; Object source; long lastChecked; long lastModified; public CachedTemplate cloneCachedTemplate() { try { return (CachedTemplate)super.clone(); } catch(CloneNotSupportedException e) { throw new UndeclaredThrowableException(e); } } } }

The table below shows all metrics for TemplateCache.java.

MetricValueDescription
BLOCKS110.00Number of blocks
BLOCK_COMMENT51.00Number of block comment lines
COMMENTS207.00Comment lines
COMMENT_DENSITY 0.57Comment density
COMPARISONS67.00Number of comparison operators
CYCLOMATIC109.00Cyclomatic complexity
DECL_COMMENTS20.00Comments in declarations
DOC_COMMENT135.00Number of javadoc comment lines
ELOC365.00Effective lines of code
EXEC_COMMENTS15.00Comments in executable code
EXITS68.00Procedure exits
FUNCTIONS28.00Number of function declarations
HALSTEAD_DIFFICULTY93.34Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY107.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 1.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 1.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 1.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 1.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.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
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.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 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 2.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 5.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 1.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 1.00JAVA0137 Non-abstract class missing constructor
JAVA0138 1.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 4.00JAVA0143 Synchronized method
JAVA0144 1.00JAVA0144 Line exceeds maximum M characters
JAVA0145 2.00JAVA0145 Tab character used in source file
JAVA0150 1.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 1.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 2.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 1.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 3.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.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 1.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
JAVA0254 0.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
LINES748.00Number of lines in the source file
LINE_COMMENT21.00Number of line comments
LOC498.00Lines of code
LOGICAL_LINES229.00Number of statements
LOOPS 7.00Number of loops
NEST_DEPTH 5.00Maximum nesting depth
OPERANDS1012.00Number of operands
OPERATORS1862.00Number of operators
PARAMS47.00Number of formal parameter declarations
PROGRAM_LENGTH2874.00Halstead program length
PROGRAM_VOCAB366.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS60.00Number of return points from functions
SIZE29757.00Size of the file in bytes
UNIQUE_OPERANDS309.00Number of unique operands
UNIQUE_OPERATORS57.00Number of unique operators
WHITESPACE43.00Number of whitespace lines