AcceptorImpl.java

Index Score
com.limegroup.gnutella
FrostWire

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
JAVA0034JAVA0034 Missing braces in if statement
LINE_COMMENTNumber of line comments
EXEC_COMMENTSComments in executable code
DECL_COMMENTSComments in declarations
SIZESize of the file in bytes
EXITSProcedure exits
JAVA0020JAVA0020 Field name does not have required form
CYCLOMATICCyclomatic complexity
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
ELOCEffective lines of code
LOGICAL_LINESNumber of statements
LINESNumber of lines in the source file
OPERATORSNumber of operators
LOCLines of code
PROGRAM_LENGTHHalstead program length
BLOCKSNumber of blocks
COMMENTSComment lines
OPERANDSNumber of operands
FUNCTIONSNumber of function declarations
JAVA0264JAVA0264 Integer math in long context - check for overflow
RETURNSNumber of return points from functions
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
COMPARISONSNumber of comparison operators
INTERFACE_COMPLEXITYInterface complexity
JAVA0076JAVA0076 Use of magic number
UNIQUE_OPERATORSNumber of unique operators
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0144JAVA0144 Line exceeds maximum M characters
JAVA0119JAVA0119 Control variable changed within body of for loop
PROGRAM_VOLUMEHalstead program volume
JAVA0259JAVA0259 Return of collection/array field
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0116JAVA0116 Missing javadoc: field 'field'
BLOCK_COMMENTNumber of block comment lines
JAVA0126JAVA0126 Method declares unchecked exception in throws
PARAMSNumber of formal parameter declarations
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
LOOPSNumber of loops
NEST_DEPTHMaximum nesting depth
package com.limegroup.gnutella; import java.io.IOException; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.MulticastSocket; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; import java.net.UnknownHostException; import java.util.Arrays; import java.util.Random; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.limewire.concurrent.ThreadExecutor; import org.limewire.i18n.I18nMarker; import org.limewire.inspection.InspectablePrimitive; import org.limewire.io.IOUtils; import org.limewire.io.NetworkUtils; import org.limewire.net.AsyncConnectionDispatcher; import org.limewire.net.BlockingConnectionDispatcher; import org.limewire.net.ConnectionAcceptor; import org.limewire.net.ConnectionDispatcher; import org.limewire.nio.SocketFactory; import org.limewire.nio.channel.NIOMultiplexor; import org.limewire.nio.observer.AcceptObserver; import org.limewire.service.MessageService; import org.limewire.setting.SettingsGroupManager; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; import com.google.inject.name.Named; import com.limegroup.gnutella.filters.IPFilter; import com.limegroup.gnutella.settings.ConnectionSettings; /** * Listens on ports, accepts incoming connections, and dispatches threads to * handle those connections. Currently supports Gnutella messaging, HTTP, and * chat connections over TCP; more may be supported in the future.<p> * This class has a special relationship with UDPService and should really be * the only class that intializes it. See setListeningPort() for more * info. */ @Singleton public class AcceptorImpl implements ConnectionAcceptor, SocketProcessor, Acceptor { private static final Log LOG = LogFactory.getLog(AcceptorImpl.class); public static final long DEFAULT_INCOMING_EXPIRE_TIME = 30 * 60 * 1000; // 30 minutes public static final long DEFAULT_WAIT_TIME_AFTER_REQUESTS = 30 * 1000; // 30 seconds public static final long DEFAULT_TIME_BETWEEN_VALIDATES = 10 * 60 * 1000; // 10 minutes // various time delays for checking of firewalled status. private long incomingExpireTime = DEFAULT_INCOMING_EXPIRE_TIME; private long waitTimeAfterRequests = DEFAULT_WAIT_TIME_AFTER_REQUESTS; private long timeBetweenValidates = DEFAULT_TIME_BETWEEN_VALIDATES; /** Task for validating incoming requests */ private final IncomingValidator incomingValidator = new IncomingValidator(); /** * The socket that listens for incoming connections. Can be changed to * listen to new ports. * * LOCKING: obtain _socketLock before modifying either. Notify _socketLock * when done. */ private volatile ServerSocket _socket=null; /** * The port of the server socket. */ private volatile int _port = 6346; /** * The real address of this host--assuming there's only one--used for pongs * and query replies. This value is ignored if FORCE_IP_ADDRESS is * true. This is initialized in three stages: * 1. Statically initialized to all zeroes. * 2. Initialized in the Acceptor thread to getLocalHost(). * 3. Initialized each time a connection is initialized to the local * address of that connection's socket. * * Why are all three needed? Step (3) is needed because (2) can often fail * due to a JDK bug #4073539, or if your address changes via DHCP. Step (2) * is needed because (3) ignores local addresses of 127.x.x.x. Step (1) is * needed because (2) can't occur in the main thread, as it may block * because the update checker is trying to resolve addresses. (See JDK bug * #4147517.) Note this may delay the time to create a listening socket by * a few seconds; big deal! * * LOCKING: obtain Acceptor.class' lock */ private byte[] _address = new byte[4]; /** * The external address. This is the address as visible from other peers. * * LOCKING: obtain Acceptor.class' lock */ private byte[] _externalAddress = new byte[4]; /** * Variable for whether or not we have accepted an incoming connection -- * used to determine firewall status. */ @InspectablePrimitive("accepted incoming") private volatile boolean _acceptedIncoming = false; /** * Keep track of the last time we re-validated. */ private volatile long _lastConnectBackTime = 0; /** * Whether or not this Acceptor was started. All connections accepted prior * to starting are dropped. */ private volatile boolean _started; private final NetworkManager networkManager; private final Provider<UDPService> udpService; private final Provider<MulticastService> multicastService; private final Provider<ConnectionDispatcher> connectionDispatcher; private final ScheduledExecutorService backgroundExecutor; private final Provider<ActivityCallback> activityCallback; private final Provider<ConnectionManager> connectionManager; private final Provider<IPFilter> ipFilter; private final ConnectionServices connectionServices; private final Provider<UPnPManager> upnpManager; @InspectablePrimitive("upnp enabled") private final boolean upnpEnabled; @Inject public AcceptorImpl(NetworkManager networkManager, Provider<UDPService> udpService, Provider<MulticastService> multicastService, @Named("global") Provider<ConnectionDispatcher> connectionDispatcher, @Named("backgroundExecutor") ScheduledExecutorService backgroundExecutor, Provider<ActivityCallback> activityCallback, Provider<ConnectionManager> connectionManager, Provider<IPFilter> ipFilter, ConnectionServices connectionServices, Provider<UPnPManager> upnpManager) { this.networkManager = networkManager; this.udpService = udpService; this.multicastService = multicastService; this.connectionDispatcher = connectionDispatcher; this.backgroundExecutor = backgroundExecutor; this.activityCallback = activityCallback; this.connectionManager = connectionManager; this.ipFilter = ipFilter; this.connectionServices = connectionServices; this.upnpManager = upnpManager; // capture UPnP setting on construction, so start/stop can // work even if setting changes between the two. upnpEnabled = !ConnectionSettings.DISABLE_UPNP.getValue(); } /** Returns true if UPnP was enabled when Acceptor was constructed. */ private boolean isUPnPEnabled() { return upnpEnabled; } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#setAddress(java.net.InetAddress) */ public void setAddress(InetAddress address) { byte[] byteAddr = address.getAddress(); if( !NetworkUtils.isValidAddress(byteAddr) ) return; if( byteAddr[0] == 127 && ConnectionSettings.LOCAL_IS_PRIVATE.getValue()) { return; } boolean addrChanged = false; synchronized(AcceptorImpl.class) { if( !Arrays.equals(_address, byteAddr) ) { _address = byteAddr; addrChanged = true; } } if( addrChanged ) networkManager.addressChanged(); } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#setExternalAddress(java.net.InetAddress) */ public void setExternalAddress(InetAddress address) { byte[] byteAddr = address.getAddress(); if( byteAddr[0] == 127 && ConnectionSettings.LOCAL_IS_PRIVATE.getValue()) { return; } synchronized(AcceptorImpl.class) { _externalAddress = byteAddr; } } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#init() */ public void init() { int tempPort; // try a random port if we have not received an incoming connection // and have been running on the default port (6346) // and the user has not changed the settings boolean tryingRandom = ConnectionSettings.PORT.isDefault() && !ConnectionSettings.EVER_ACCEPTED_INCOMING.getValue() && !ConnectionSettings.FORCE_IP_ADDRESS.getValue(); Random gen = null; if (tryingRandom) { gen = new Random(); tempPort = gen.nextInt(50000)+2000; } else tempPort = ConnectionSettings.PORT.getValue(); //0. Get local address. This must be done here because it can // block under certain conditions. // See the notes for _address. try { if(isUPnPEnabled()) setAddress(NetworkUtils.getLocalAddress()); else setAddress(InetAddress.getLocalHost()); } catch (UnknownHostException e) { } catch (SecurityException e) { } // Create the server socket, bind it to a port, and listen for // incoming connections. If there are problems, we can continue // onward. //1. Try suggested port. int oldPort = tempPort; try { setListeningPort(tempPort); _port = tempPort; } catch (IOException e) { LOG.warn("can't set initial port", e); // 2. Try 20 different ports. int numToTry = 20; for (int i=0; i<numToTry; i++) { if(gen == null) gen = new Random(); tempPort = gen.nextInt(50000); tempPort += 2000;//avoid the first 2000 ports // do not try to bind to the multicast port. if (tempPort == ConnectionSettings.MULTICAST_PORT.getValue()) { numToTry++; continue; } try { setListeningPort(tempPort); _port = tempPort; break; } catch (IOException e2) { LOG.warn("can't set port", e2); } } // If we still don't have a socket, there's an error if(_socket == null) { MessageService.showError(I18nMarker.marktr("FrostWire was unable to set up a port to listen for incoming connections. Some features of FrostWire may not work as expected.")); } } if (_port != oldPort || tryingRandom) { ConnectionSettings.PORT.setValue(_port); SettingsGroupManager.instance().save(); networkManager.addressChanged(); } // Make sure UPnP gets setup. if(upnpManager.get().isNATPresent()) { setupUPnP(); } else { upnpManager.get().addListener(new UPnPListener() { public void natFound() { setupUPnP(); } }); } } private void setupUPnP() { // if we created a socket and have a NAT, and the user is not // explicitly forcing a port, create the mappings if (_socket != null && isUPnPEnabled()) { boolean natted = upnpManager.get().isNATPresent(); boolean validPort = NetworkUtils.isValidPort(_port); boolean forcedIP = ConnectionSettings.FORCE_IP_ADDRESS.getValue() && !ConnectionSettings.UPNP_IN_USE.getValue(); if(LOG.isDebugEnabled()) LOG.debug("Natted: " + natted + ", validPort: " + validPort + ", forcedIP: " + forcedIP); if(natted && validPort && !forcedIP) { int mappedPort = upnpManager.get().mapPort(_port); if(LOG.isDebugEnabled()) LOG.debug("UPNP port mapped: " + mappedPort); //if we created a mapping successfully, update the forced port if (mappedPort != 0 ) { upnpManager.get().clearMappingsOnShutdown(); // mark UPNP as being on so that if LimeWire shuts // down prematurely, we know the FORCE_IP was from UPnP // and that we can continue trying to use UPnP ConnectionSettings.FORCE_IP_ADDRESS.setValue(true); ConnectionSettings.FORCED_PORT.setValue(mappedPort); ConnectionSettings.UPNP_IN_USE.setValue(true); if (mappedPort != _port) networkManager.addressChanged(); // we could get our external address from the NAT but its too slow // so we clear the last connect back times and re-validate cause our // status may have changed. resetLastConnectBackTime(); udpService.get().resetLastConnectBackTime(); if (!acceptedIncoming()) incomingValidator.run(); } } } } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#start() */ public void start() { multicastService.get().start(); udpService.get().start(); connectionDispatcher.get().addConnectionAcceptor(this, false, "CONNECT", "\n\n"); backgroundExecutor.scheduleWithFixedDelay(incomingValidator, timeBetweenValidates, timeBetweenValidates, TimeUnit.MILLISECONDS); _started = true; } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#isAddressExternal() */ public boolean isAddressExternal() { if (!ConnectionSettings.LOCAL_IS_PRIVATE.getValue()) return true; synchronized(AcceptorImpl.class) { return Arrays.equals(getAddress(true), _externalAddress); } } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#isBlocking() */ public boolean isBlocking() { return false; } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#getExternalAddress() */ public byte[] getExternalAddress() { synchronized(AcceptorImpl.class) { return _externalAddress; } } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#getAddress(boolean) */ public byte[] getAddress(boolean checkForce) { if(checkForce && ConnectionSettings.FORCE_IP_ADDRESS.getValue()) { String address = ConnectionSettings.FORCED_IP_ADDRESS_STRING.getValue(); try { InetAddress ia = InetAddress.getByName(address); byte[] addr = ia.getAddress(); if(addr != null) return addr; } catch (UnknownHostException err) { // ignore and return _address } } synchronized (AcceptorImpl.class) { return _address; } } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#getConnectionDispatcher() */ public ConnectionDispatcher getConnectionDispatcher() { return connectionDispatcher.get(); } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#getPort(boolean) */ public int getPort(boolean checkForce) { if(checkForce && ConnectionSettings.FORCE_IP_ADDRESS.getValue()) return ConnectionSettings.FORCED_PORT.getValue(); return _port; } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#setListeningPort(int) */ public void setListeningPort(int port) throws IOException { //1. Special case: if unchanged, do nothing. if (_socket!=null && _port==port) return; //2. Special case if port==0. This ALWAYS works. //Note that we must close the socket BEFORE grabbing //the lock. Otherwise deadlock will occur since //the acceptor thread is listening to the socket //while holding the lock. Also note that port //will not have changed before we grab the lock. else if (port==0) { LOG.trace("shutting off service."); IOUtils.close(_socket); _socket=null; _port=0; //Shut off UDPService also! udpService.get().setListeningSocket(null); //Shut off MulticastServier too! multicastService.get().setListeningSocket(null); LOG.trace("service OFF."); return; } //3. Normal case. See note about locking above. /* Since we want the UDPService to bind to the same port as the * Acceptor, we need to be careful about this case. Essentially, we * need to confirm that the port can be bound by BOTH UDP and TCP * before actually acceping the port as valid. To effect this change, * we first attempt to bind the port for UDP traffic. If that fails, a * IOException will be thrown. If we successfully UDP bind the port * we keep that bound DatagramSocket around and try to bind the port to * TCP. If that fails, a IOException is thrown and the valid * DatagramSocket is closed. If that succeeds, we then 'commit' the * operation, setting our new TCP socket and UDP sockets. */ else { if(LOG.isDebugEnabled()) LOG.debug("changing port to " + port); DatagramSocket udpServiceSocket = udpService.get().newListeningSocket(port); LOG.trace("UDP Service is ready."); MulticastSocket mcastServiceSocket = null; try { InetAddress mgroup = InetAddress.getByName( ConnectionSettings.MULTICAST_ADDRESS.getValue() ); mcastServiceSocket = multicastService.get().newListeningSocket( ConnectionSettings.MULTICAST_PORT.getValue(), mgroup ); LOG.trace("multicast service setup"); } catch(IOException e) { LOG.warn("can't create multicast socket", e); } //a) Try new port. ServerSocket newSocket=null; try { newSocket = SocketFactory.newServerSocket(port, new SocketListener()); } catch (IOException e) { LOG.warn("can't create ServerSocket", e); udpServiceSocket.close(); throw e; } catch (IllegalArgumentException e) { LOG.warn("can't create ServerSocket", e); udpServiceSocket.close(); throw new IOException("could not create a listening socket"); } //b) Close old socket IOUtils.close(_socket); //c) Replace with new sock. _socket=newSocket; _port=port; LOG.trace("Acceptor ready.."); // Commit UDPService's new socket udpService.get().setListeningSocket(udpServiceSocket); // Commit the MulticastService's new socket // if we were able to get it if (mcastServiceSocket != null) { multicastService.get().setListeningSocket(mcastServiceSocket); } if(LOG.isDebugEnabled()) LOG.debug("listening UDP/TCP on " + _port); } } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#acceptedIncoming() */ public boolean acceptedIncoming() { return _acceptedIncoming; } /** * For testing. */ protected void setAcceptedIncoming(boolean incoming) { _acceptedIncoming = incoming; } /** * Sets the new incoming status. * Returns whether or not the status changed. */ boolean setIncoming(boolean canReceiveIncoming) { if (canReceiveIncoming) incomingValidator.cancelReset(); if (_acceptedIncoming == canReceiveIncoming) return false; _acceptedIncoming = canReceiveIncoming; activityCallback.get().acceptedIncomingChanged(canReceiveIncoming); return true; } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#acceptConnection(java.lang.String, java.net.Socket) */ public void acceptConnection(String word, Socket s) { checkFirewall(s.getInetAddress()); IOUtils.close(s); } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#checkFirewall(java.net.InetAddress) */ public void checkFirewall(InetAddress address) { // we have accepted an incoming socket -- only record // that we've accepted incoming if it's definitely // not from our local subnet and we aren't connected to // the host already. boolean changed = false; if(isOutsideConnection(address)) { synchronized (AcceptorImpl.class) { changed = setIncoming(true); ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true); } } if(changed) networkManager.incomingStatusChanged(); } /** * Listens for new incoming sockets & starts a thread to * process them if necessary. */ private class SocketListener implements AcceptObserver { public void handleIOException(IOException iox) { LOG.warn("IOX while accepting", iox); } public void shutdown() { LOG.debug("shutdown one SocketListener"); } public void handleAccept(Socket client) { processSocket(client); } } /* (non-Javadoc) * @see com.limegroup.gnutella.SocketProcessor#processSocket(java.net.Socket) */ /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#processSocket(java.net.Socket) */ public void processSocket(Socket client) { processSocket(client, null); } /* (non-Javadoc) * @see com.limegroup.gnutella.SocketProcessor#processSocket(java.net.Socket, java.lang.String) */ /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#processSocket(java.net.Socket, java.lang.String) */ public void processSocket(Socket client, String allowedProtocol) { if (!_started) { IOUtils.close(client); return; } // If the client was closed before we were able to get the address, // then getInetAddress will return null. InetAddress address = client.getInetAddress(); if (address == null || !NetworkUtils.isValidAddress(address) || !NetworkUtils.isValidPort(client.getPort())) { IOUtils.close(client); LOG.warn("connection closed while accepting"); } else if (!ipFilter.get().allow(address.getAddress())) { if (LOG.isWarnEnabled()) LOG.warn("Ignoring banned host: " + address); IOUtils.close(client); } else { if (LOG.isDebugEnabled()) LOG.debug("Dispatching new client connecton: " + address); // Set our IP address of the local address of this socket. InetAddress localAddress = client.getLocalAddress(); setAddress(localAddress); try { client.setSoTimeout(Constants.TIMEOUT); } catch (SocketException se) { IOUtils.close(client); return; } // Dispatch asynchronously if possible. if (client instanceof NIOMultiplexor) {// supports non-blocking reads ((NIOMultiplexor) client).setReadObserver(new AsyncConnectionDispatcher(connectionDispatcher.get(), client, allowedProtocol)); } else { ThreadExecutor.startThread(new BlockingConnectionDispatcher(connectionDispatcher .get(), client, allowedProtocol), "ConnectionDispatchRunner"); } } } /** * Determines whether or not this INetAddress is found an outside source, so as to correctly set "acceptedIncoming" * to true. * * This ignores connections from private or local addresses, ignores those who may be on the same subnet, and * ignores those who we are already connected to. */ private boolean isOutsideConnection(InetAddress addr) { // short-circuit for tests. if(!ConnectionSettings.LOCAL_IS_PRIVATE.getValue()) return true; return !connectionServices.isConnectedTo(addr) && !NetworkUtils.isLocalAddress(addr); } /** * Resets the last connectback time. */ public void resetLastConnectBackTime() { _lastConnectBackTime = 0; // long ago } /* (non-Javadoc) * @see com.limegroup.gnutella.Acceptor#shutdown() */ public void shutdown() { shutdownUPnP(); } private void shutdownUPnP() { if(isUPnPEnabled() && upnpManager.get().isNATPresent() && upnpManager.get().mappingsExist() && ConnectionSettings.UPNP_IN_USE.getValue()) { // reset the forced port values - must happen before we save them to disk ConnectionSettings.FORCE_IP_ADDRESS.revertToDefault(); ConnectionSettings.FORCED_PORT.revertToDefault(); ConnectionSettings.UPNP_IN_USE.revertToDefault(); } } /** * (Re)validates acceptedIncoming. */ private class IncomingValidator implements Runnable { private final AtomicBoolean validating = new AtomicBoolean(false); private AtomicReference<Future<?>> futureRef = new AtomicReference<Future<?>>(); public void run() { if (validating.getAndSet(true)) return; // clear and revalidate if we haven't done so in a while final long currTime = System.currentTimeMillis(); if (currTime - _lastConnectBackTime > incomingExpireTime){ // send a connectback request to a few peers and clear // _acceptedIncoming IF some requests were sent. if(connectionManager.get().sendTCPConnectBackRequests()) { _lastConnectBackTime = currTime; Runnable resetter = new Runnable() { public void run() { boolean changed = false; synchronized (AcceptorImpl.class) { changed = setIncoming(false); } if(changed) networkManager.incomingStatusChanged(); } }; // Cancel any old future before we schedule this one Future<?> oldRef = futureRef.get(); if(oldRef != null) oldRef.cancel(false); futureRef.set(backgroundExecutor.schedule(resetter, waitTimeAfterRequests, TimeUnit.MILLISECONDS)); } } validating.set(false); } void cancelReset() { Future<?> resetter = futureRef.get(); if (resetter != null) { resetter.cancel(false); // unset the ref if it's still the current future futureRef.compareAndSet(resetter, null); } } } public long getIncomingExpireTime() { return incomingExpireTime; } /** * Only used for testing. */ void setIncomingExpireTime(long incomingExpireTime) { this.incomingExpireTime = incomingExpireTime; } public long getWaitTimeAfterRequests() { return waitTimeAfterRequests; } /** * Only used for testing. */ void setWaitTimeAfterRequests(long waitTimeAfterRequests) { this.waitTimeAfterRequests = waitTimeAfterRequests; } public long getTimeBetweenValidates() { return timeBetweenValidates; } void setTimeBetweenValidates(long timeBetweenValidates) { this.timeBetweenValidates = timeBetweenValidates; } }

The table below shows all metrics for AcceptorImpl.java.

MetricValueDescription
BLOCKS89.00Number of blocks
BLOCK_COMMENT68.00Number of block comment lines
COMMENTS211.00Comment lines
COMMENT_DENSITY 0.54Comment density
COMPARISONS56.00Number of comparison operators
CYCLOMATIC108.00Cyclomatic complexity
DECL_COMMENTS38.00Comments in declarations
DOC_COMMENT85.00Number of javadoc comment lines
ELOC391.00Effective lines of code
EXEC_COMMENTS34.00Comments in executable code
EXITS90.00Procedure exits
FUNCTIONS38.00Number of function declarations
HALSTEAD_DIFFICULTY77.26Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY82.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 7.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
JAVA003425.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 0.00JAVA0075 Method parameter hides field
JAVA0076 6.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
JAVA0108 5.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 3.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 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 3.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 3.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 1.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 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 0.00JAVA0143 Synchronized method
JAVA0144 2.00JAVA0144 Line exceeds maximum M characters
JAVA0145226.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 1.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 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
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 2.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 3.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
LINES781.00Number of lines in the source file
LINE_COMMENT58.00Number of line comments
LOC470.00Lines of code
LOGICAL_LINES241.00Number of statements
LOOPS 1.00Number of loops
NEST_DEPTH 5.00Maximum nesting depth
OPERANDS957.00Number of operands
OPERATORS1985.00Number of operators
PARAMS29.00Number of formal parameter declarations
PROGRAM_LENGTH2942.00Halstead program length
PROGRAM_VOCAB410.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS53.00Number of return points from functions
SIZE28509.00Size of the file in bytes
UNIQUE_OPERANDS353.00Number of unique operands
UNIQUE_OPERATORS57.00Number of unique operators
WHITESPACE100.00Number of whitespace lines