BTConnection.java

Index Score
com.limegroup.bittorrent
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
DECL_COMMENTSComments in declarations
CYCLOMATICCyclomatic complexity
EXITSProcedure exits
FUNCTIONSNumber of function declarations
JAVA0020JAVA0020 Field name does not have required form
LOGICAL_LINESNumber of statements
RETURNSNumber of return points from functions
ELOCEffective lines of code
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
LINESNumber of lines in the source file
OPERATORSNumber of operators
LOCLines of code
EXEC_COMMENTSComments in executable code
COMPARISONSNumber of comparison operators
PROGRAM_LENGTHHalstead program length
UNIQUE_OPERANDSNumber of unique operands
SIZESize of the file in bytes
PROGRAM_VOCABHalstead program vocabulary
LINE_COMMENTNumber of line comments
COMMENTSComment lines
INTERFACE_COMPLEXITYInterface complexity
OPERANDSNumber of operands
BLOCKSNumber of blocks
DOC_COMMENTNumber of javadoc comment lines
UNIQUE_OPERATORSNumber of unique operators
WHITESPACENumber of whitespace lines
JAVA0076JAVA0076 Use of magic number
JAVA0075JAVA0075 Method parameter hides field
JAVA0109JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0145JAVA0145 Tab character used in source file
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
BLOCK_COMMENTNumber of block comment lines
JAVA0032JAVA0032 Switch statement missing default
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0264JAVA0264 Integer math in long context - check for overflow
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
package com.limegroup.bittorrent; import java.io.IOException; import java.net.SocketException; import java.nio.ByteBuffer; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.concurrent.ScheduledExecutorService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.limewire.collection.BitField; import org.limewire.collection.BitFieldSet; import org.limewire.collection.BitSet; import org.limewire.collection.NECallable; import org.limewire.io.IOUtils; import org.limewire.nio.AbstractNBSocket; import org.limewire.nio.NIODispatcher; import org.limewire.nio.channel.ChannelReadObserver; import org.limewire.nio.channel.ThrottleReader; import com.limegroup.bittorrent.disk.TorrentDiskManager; import com.limegroup.bittorrent.messages.BTBitField; import com.limegroup.bittorrent.messages.BTCancel; import com.limegroup.bittorrent.messages.BTChoke; import com.limegroup.bittorrent.messages.BTHave; import com.limegroup.bittorrent.messages.BTInterested; import com.limegroup.bittorrent.messages.BTMessage; import com.limegroup.bittorrent.messages.BTNotInterested; import com.limegroup.bittorrent.messages.BTPieceMessage; import com.limegroup.bittorrent.messages.BTRequest; import com.limegroup.bittorrent.messages.BTUnchoke; import com.limegroup.bittorrent.messages.BadBTMessageException; import com.limegroup.bittorrent.reader.BTMessageReader; import com.limegroup.gnutella.BandwidthManager; import com.limegroup.gnutella.InsufficientDataException; import com.limegroup.gnutella.uploader.UploadSlotListener; import com.limegroup.gnutella.uploader.UploadSlotManager; /** * Class wrapping a Bittorrent connection. */ public class BTConnection implements UploadSlotListener, BTMessageHandler, BTLink, PieceSendListener, PieceReadListener { private static final Log LOG = LogFactory.getLog(BTConnection.class); /** * This is the max size of a block that we will ever upload, requests larger * than this are dropped. */ private static final int MAX_BLOCK_SIZE = 64 * 1024; /** * the number of requests to send to any host without waiting for reply */ private static final int MAX_REQUESTS = 4; /** * connections that die after less than a minute won't be retried */ private static final long MIN_RETRYABLE_LIFE_TIME = 60 * 1000; /** * 2 minutes as suggested by spec + 5 seconds for network or * scheduling delays */ private static final int CONNECTION_TIMEOUT = 2 * 60 * 1000 + 5000; /* * the NBSocket we're using */ private AbstractNBSocket _socket; /* * Reader for the messages */ private final ChannelReadObserver _reader; /* * Writer for the messages */ private final BTChannelWriter _writer; /** * The pieces the remote host has */ private volatile BitSet _availableRanges; /** A bitfield view of what they have */ private volatile BitField _available; /** * the Set of BTIntervals we requested but which was not yet satisfied. */ private final Set<BTInterval> _requesting; /** * the Set of BTInterval requested by the remote host. */ private final Set<BTInterval> _requested; /** * the metaInfo of this torrent */ private final TorrentContext context; /** * the id of the remote client */ private final TorrentLocation _endpoint; private final BandwidthManager bwManager; private final UploadSlotManager usManager; /** * whether we choke them: if we are choking, all requests from the remote * host will be ignored */ private boolean _isChoked; /** * whether they choke us: only send requests if they are not choking us */ private volatile boolean _isChoking; /** * Indicates whether the remote host is interested in one of the ranges we * offer. */ private boolean _isInterested; /** * Indicates whether or not the remote host offers ranges we want */ private volatile boolean _isInteresting; /** * the time when this Connection was created */ private long _startTime; /** * The # of pieces the remote host is missing. */ private int numMissing; /** * The # of the round this connection was unchoked last time. */ private int unchokeRound; /** Whether this connection is currently using an upload slot */ private volatile boolean usingSlot; /** Bandwidth trackers for the outgoing and incoming bandwidth */ private SimpleBandwidthTracker up, downShort, downLong; /** Whether this connection is currently closing */ private volatile boolean closing; /** Cached runnables for handling of slot-related events */ private Runnable slotReleaser, slotNotifier; /** Listener for events generated by this connection */ private BTLinkListener listener; /** executor of network-related tasks */ private ScheduledExecutorService invoker; /** * Constructs instance of this * * @param sock * the Socket to the remote host. We assume that the Bittorrent * connection is already initialized and the headers were * exchanged successfully * @param info * the BTMetaInfo holding all information for this torrent * @param torrent * the ManagedTorrent to whom this connection belongs. */ public BTConnection(TorrentContext context, TorrentLocation ep, BandwidthManager bwManager, UploadSlotManager usManager) { _endpoint = ep; this.context = context; this.bwManager = bwManager; this.usManager = usManager; _availableRanges = new BitSet(context.getMetaInfo().getNumBlocks()); _available = new BitFieldSet(_availableRanges, context.getMetaInfo().getNumBlocks()); _requesting = new HashSet<BTInterval>(); _requested = new HashSet<BTInterval>(); // connections start choked and not interested _isChoked = true; _isChoking = true; _isInterested = false; _isInteresting = false; up = new SimpleBandwidthTracker(); downShort = new SimpleBandwidthTracker(1000); downLong = new SimpleBandwidthTracker(5000); _writer = new BTMessageWriter(this, this); _reader = new BTMessageReader(this, this, NIODispatcher.instance().getScheduledExecutorService(), NIODispatcher.instance().getBufferCache()); } /** * Initializes the connection */ public void init(AbstractNBSocket socket, BTLinkListener listener, ScheduledExecutorService invoker) { // if we were shutdown before initializing, return. if (closing) return; _socket = socket; try { _socket.setSoTimeout(CONNECTION_TIMEOUT); } catch (SocketException se){ shutdown(); return; } this.listener = listener; this.invoker = invoker; _startTime = System.currentTimeMillis(); _writer.init(invoker, CONNECTION_TIMEOUT - 5000, bwManager); ThrottleReader readThrottle = new ThrottleReader( bwManager.getReadThrottle()); _reader.setReadChannel(readThrottle); readThrottle.interestRead(true); _socket.setReadObserver(_reader); _socket.setWriteObserver(_writer); // if we have downloaded anything send a bitfield if (context.getDiskManager().getVerifiedBlockSize() > 0) { numMissing = context.getDiskManager().getNumMissing(_available); sendBitfield(); } } /* (non-Javadoc) * @see com.limegroup.bittorrent.Chokable#isChoked() */ public boolean isChoked() { return _isChoked; } /* (non-Javadoc) * @see com.limegroup.bittorrent.Chokable#isChoking() */ public boolean isChoking() { return _isChoking; } /* (non-Javadoc) * @see com.limegroup.bittorrent.Chokable#isInterested() */ public boolean isInterested() { return _isInterested; } /* (non-Javadoc) * @see com.limegroup.bittorrent.Chokable#shouldBeInterested() */ public boolean shouldBeInterested() { return numMissing > 0; } /* (non-Javadoc) * @see com.limegroup.bittorrent.Chokable#isInteresting() */ public boolean isInteresting() { return _isInteresting; } /* (non-Javadoc) * @see com.limegroup.bittorrent.BTLink#isWorthRetrying() */ public boolean isWorthRetrying() { // don't retry connections that were aborted immediately after starting // them, they were most likely terminated for a reason... return System.currentTimeMillis() - _startTime > MIN_RETRYABLE_LIFE_TIME; } /** * @return <tt>TorrentLocation</tt> we are connected to */ public TorrentLocation getEndpoint() { return _endpoint; } /** * Closes the connection. */ private void close() { if (closing) return; closing = true; // if not initialized just return if (_socket == null) return; IOUtils.close(_socket); clearRequests(); cancelSlotRequest(); listener.linkClosed(this); } private void cancelSlotRequest() { if (usingSlot) { if (LOG.isDebugEnabled()) LOG.debug(this+" cancelling slot request"); usManager.cancelRequest(this); } usingSlot = false; } /* (non-Javadoc) * @see com.limegroup.bittorrent.Chokable#getMeasuredBandwidth(boolean, boolean) */ public float getMeasuredBandwidth(boolean read, boolean shortTerm) { SimpleBandwidthTracker tracker; if (!read) tracker = up; else if (shortTerm) tracker = downShort; else tracker = downLong; tracker.measureBandwidth(); try { return tracker.getMeasuredBandwidth(); } catch (InsufficientDataException ide) { return 0; } } /* (non-Javadoc) * @see com.limegroup.bittorrent.BTMessageHandler#readBytes(int) */ public void readBytes(int read) { downShort.count(read); downLong.count(read); listener.countDownloaded(read); } /** * notification that some bytes have been written on this connection */ public void wroteBytes(int written) { up.count(written); context.getMetaInfo().countUploaded(written); //TODO: move/rename the persistent info to its own place } /** * Handles IOExceptions for this connection */ public void handleIOException(IOException iox) { if (LOG.isDebugEnabled()) LOG.debug(iox); shutdown(); } public void shutdown() { close(); } /** * Chokes the connection */ public void choke() { _requested.clear(); if (!_isChoked) { if (LOG.isDebugEnabled()) LOG.debug(this+" choking"); cancelSlotRequest(); _writer.enqueue(BTChoke.createMessage()); _isChoked = true; } } /** * Unchokes the connection * @param now the unchoking round. */ public void unchoke(int now) { unchokeRound = now; if (_isChoked) { if (LOG.isDebugEnabled()) LOG.debug(this +" unchoking, round "+now); _writer.enqueue(BTUnchoke.createMessage()); _isChoked = false; } } /** * @return the round during which the connection was last unchoked */ public int getUnchokeRound() { return unchokeRound; } /** * sets the round during which the connection was choked */ public void clearUnchokeRound() { unchokeRound = -1; } /** * Informs the remote that we are interested in downloading. */ private void sendInterested() { if (!_isInteresting) { if (LOG.isDebugEnabled()) LOG.debug(this+ " we become interested"); _writer.enqueue(BTInterested.createMessage()); _isInteresting = true; } } /** * Informs the remote we are not interested in downloading. */ void sendNotInterested() { cancelAllRequests(); if (_isInteresting) { if (LOG.isDebugEnabled()) LOG.debug(this+ " we lose interest"); _writer.enqueue(BTNotInterested.createMessage()); _isInteresting = false; } } /** * Tells the remote host, that we have a new piece. * * @param have the <tt>BTHave</tt> message representing a complete piece. */ public void sendHave(BTHave have) { int pieceNum = have.getPieceNum(); // As a minor optimization we will not inform the remote host of any // pieces that it already has if (!_available.get(pieceNum)) { numMissing++; _writer.enqueue(have); } // we should indicate that we are not interested anymore, so we are // not unchoked when we do not want to request anything. if (!context.getDiskManager().containsAnyWeMiss(_available)) { sendNotInterested(); return; } // remove all subranges that we may be requesting for (Iterator<BTInterval> iter = _requesting.iterator(); iter.hasNext();) { BTInterval req = iter.next(); if (req.getId() == pieceNum) { iter.remove(); sendCancel(req); } } if (!_isChoking) request(); } /** * Sends a bitfield message to the remote host. */ private void sendBitfield() { _writer.enqueue(BTBitField.createMessage(context)); } private void sendCancel(BTInterval in) { _writer.enqueue(new BTCancel(in)); } /** * Cancels all requests. */ private void cancelAllRequests() { for (BTInterval request : _requesting) sendCancel(request); clearRequests(); } /* (non-Javadoc) * @see com.limegroup.bittorrent.PieceSendListener#pieceSent() */ public void pieceSent() { if (LOG.isDebugEnabled()) LOG.debug(this+" piece sent"); usingSlot = false; usManager.requestDone(this); readyForWriting(); } /** * notifies this, that the connection is ready to write the next chunk of * the torrent */ private void readyForWriting() { if (_isChoked || _requested.isEmpty()) return; usingSlot = true; int proceed = usManager.requestSlot( this, !context.getDiskManager().isComplete()); if (proceed == -1) { // denied, choke the connection usingSlot = false; choke(); } else if (proceed == 0) beginPieceSend(); // else queued, will receive callback. } private void beginPieceSend() { if (_isChoked || _requested.isEmpty()) return; // pick a request from them Iterator<BTInterval> iter = _requested.iterator(); BTInterval in = iter.next(); iter.remove(); if (LOG.isDebugEnabled()) LOG.debug(this+" requesting disk read for "+in); context.getDiskManager().requestPieceRead(in, this); } /* (non-Javadoc) * @see com.limegroup.bittorrent.PieceReadListener#pieceRead(com.limegroup.bittorrent.BTInterval, byte[]) */ public void pieceRead(final BTInterval in, final byte [] data) { bwManager.applyUploadRate(); Runnable pieceSender = new Runnable() { public void run() { if (LOG.isDebugEnabled()) LOG.debug("disk read done for "+in); _writer.enqueue(new BTPieceMessage(in, data)); } }; invoker.execute(pieceSender); } /* (non-Javadoc) * @see com.limegroup.bittorrent.PieceReadListener#pieceReadFailed(com.limegroup.bittorrent.BTInterval) */ public void pieceReadFailed(BTInterval interval) { cancelSlotRequest(); } private void clearRequests() { for (BTInterval clear : _requesting) context.getDiskManager().releaseInterval(clear); _requesting.clear(); } /* (non-Javadoc) * @see com.limegroup.bittorrent.BTMessageHandler#processMessage(com.limegroup.bittorrent.messages.BTMessage) */ public void processMessage(BTMessage message) { if (LOG.isDebugEnabled()) LOG.debug(this +" handling message "+message); switch (message.getType()) { case BTMessage.CHOKE: _isChoking = true; clearRequests(); break; case BTMessage.UNCHOKE: _isChoking = false; if (_isInteresting) request(); break; case BTMessage.INTERESTED: _isInterested = true; listener.linkInterested(this); break; case BTMessage.NOT_INTERESTED: _isInterested = false; _requested.clear(); // forget what they requested listener.linkNotInterested(this); // if we have all pieces and the remote is not interested, // disconnect, - they have obviously completed their download, too if (context.getDiskManager().isComplete()) close(); break; case BTMessage.BITFIELD: handleBitField((BTBitField) message); break; case BTMessage.HAVE: handleHave((BTHave) message); break; case BTMessage.REQUEST: handleRequest((BTRequest) message); break; case BTMessage.CANCEL: handleCancel((BTCancel) message); break; } } /** * Removes the range specified in the <tt>BTCancel</tt> message * from the list of requests. * Note: if we are already sending this range, there's nothing * that can be done. */ private void handleCancel(BTCancel message) { BTInterval in = message.getInterval(); _requested.remove(in); // remove any sub-ranges as well for (Iterator<BTInterval> iter = _requested.iterator(); iter.hasNext();) { BTInterval current = iter.next(); if (in.getId() == current.getId() && (in.getLow() <= current.getHigh() && current.getLow() <= in.getHigh())) iter.remove(); } } /** * Processes a request for a range. */ private void handleRequest(BTRequest message) { // we do not process requests from choked connections; if we // just choked a connection, we may still receive some requests. if (_isChoked) return; BTInterval in = message.getInterval(); if (LOG.isDebugEnabled()) LOG.debug(this+ " got request for " + in); // ignore, that's a buggy client sending this request (didn't manage to // find out which one) - we could also throw an exception causing us to // disconnect... if (in.getId() > context.getMetaInfo().getNumBlocks()) { if (LOG.isDebugEnabled()) LOG.debug("got bad request " + message); return; } // we skip all requests for ranges larger than MAX_BLOCK_SIZE as // proposed by the BitTorrent spec. if (in.getHigh() - in.getLow() + 1 > MAX_BLOCK_SIZE) { if (LOG.isDebugEnabled()) LOG.debug("got long request"); return; } if (context.getDiskManager().hasBlock(in.getId())) _requested.add(in); if (!_requested.isEmpty() && !usingSlot) readyForWriting(); } /** * Notification that we are now receiving the specified piece * @return true if the piece was requested. */ public boolean startReceivingPiece(BTInterval interval) { // its ok to remove the piece from the list of pieces we request // because if the receiving fails the connection will be closed. if (!_requesting.remove(interval)) { if (LOG.isDebugEnabled()) LOG.debug("received unexpected range " + interval + " from " + _socket.getInetAddress() + " expected " + _requesting); return false; } if (LOG.isDebugEnabled()) LOG.debug(this + " starting to receive piece " + interval); return true; } public void finishReceivingPiece() { request(); } void request() { if (LOG.isDebugEnabled()) LOG.debug("requesting ranges from " + this); // if we still have more than one outstanding request, wait for them if (_requesting.size() > 1) return; // get new ranges to request if necessary while (_requesting.size() < MAX_REQUESTS) { BTInterval in = context.getDiskManager().leaseRandom(_available, _requesting); if (in == null) break; _requesting.add(in); _writer.enqueue(new BTRequest(in)); } } /* (non-Javadoc) * @see com.limegroup.bittorrent.BTMessageHandler#handlePiece(com.limegroup.bittorrent.BTPieceFactory) */ public void handlePiece(NECallable<BTPiece> factory) { context.getDiskManager().writeBlock(factory); } /** * handles a bitfield and reads in the available pieces contained therein */ private void handleBitField(BTBitField message) { ByteBuffer field = message.getPayload(); // the number of pieces int numBits = context.getMetaInfo().getNumBlocks(); int bitFieldLength = (numBits + 7) / 8; if (field.remaining() != bitFieldLength) handleIOException(new BadBTMessageException( "bad bitfield received! " + _endpoint.toString())); boolean willBeInteresting = false; for (int i = 0; i < numBits; i++) { byte mask = (byte) (0x80 >>> (i % 8)); if ((mask & field.get(i / 8)) == mask) { if (!willBeInteresting && !context.getDiskManager().hasBlock(i)) willBeInteresting = true; _availableRanges.set(i); } } if (_available.cardinality() == numBits) { _availableRanges = null; _available = context.getFullBitField(); numMissing = 0; } else numMissing = context.getDiskManager().getNumMissing(_available); if (willBeInteresting) sendInterested(); } /** * handles a have message and adds the available range contained therein */ private void handleHave(BTHave message) { int pieceNum = message.getPieceNum(); if (pieceNum >= _available.maxSize()) { shutdown(); return; } if (_available.get(pieceNum)) return; // dublicate Have, ignore. TorrentDiskManager v = context.getDiskManager(); _availableRanges.set(pieceNum); // tell the remote host we are interested if we don't have that range if (v.hasBlock(pieceNum)) numMissing--; else sendInterested(); if (_available.cardinality() == context.getMetaInfo().getNumBlocks()) { if (LOG.isDebugEnabled()) LOG.debug(this+" now has everything"); _availableRanges = null; _available = context.getFullBitField(); numMissing = 0; if (v.isComplete()) // we're also seed - goodbye shutdown(); } } public boolean equals(Object o) { if (o instanceof BTConnection) { BTConnection other = (BTConnection) o; return other._endpoint.equals(_endpoint); } return false; } public String toString() { StringBuilder b = new StringBuilder(_socket == null? "new" : "("+getHost()); if (isChoked()) b.append(" Ced"); if (isChoking()) b.append(" Cing"); if (isInterested()) b.append(" Ied"); if (isInteresting()) b.append(" Iing"); if (isSeed()) b.append(" Seed"); if (usingSlot) b.append(" U"); int requested = _requested.size(); if (requested > 0) b.append(" Q").append(requested); int requesting = _requesting.size(); if (requesting > 0) b.append (" D").append(requesting); b.append(")"); return b.toString(); } public String getHost() { return _socket.getInetAddress().getHostAddress(); } public void releaseSlot() { invoker.execute(getSlotReleaser()); } private Runnable getSlotReleaser() { if (slotReleaser == null) { slotReleaser = new Runnable() { public void run() { if (LOG.isDebugEnabled()) LOG.debug(BTConnection.this +" releasing slot"); choke(); } }; } return slotReleaser; } public void slotAvailable() { invoker.execute(getSlotNotifier()); } private Runnable getSlotNotifier() { if (slotNotifier == null) { slotNotifier = new Runnable() { public void run() { if (LOG.isDebugEnabled()) LOG.debug(BTConnection.this+" got available slot"); beginPieceSend(); } }; } return slotNotifier; } /* (non-Javadoc) * @see com.limegroup.bittorrent.Chokable#getAverageBandwidth() */ public float getAverageBandwidth() { return up.getAverageBandwidth(); } /* (non-Javadoc) * @see com.limegroup.bittorrent.Chokable#getMeasuredBandwidth() */ public float getMeasuredBandwidth() throws InsufficientDataException { return up.getMeasuredBandwidth(); } /* (non-Javadoc) * @see com.limegroup.bittorrent.Chokable#measureBandwidth() */ public void measureBandwidth() { up.measureBandwidth(); } /* (non-Javadoc) * @see com.limegroup.bittorrent.Chokable#isSeed() */ public boolean isSeed() { return _available.cardinality() == context.getMetaInfo().getNumBlocks(); } /* (non-Javadoc) * @see com.limegroup.bittorrent.BTLink#isBusy() */ public boolean isBusy() { return !isInteresting(); } /* (non-Javadoc) * @see com.limegroup.bittorrent.BTLink#isUploading() */ public boolean isUploading() { return isInterested() && !isChoked(); } /* (non-Javadoc) * @see com.limegroup.bittorrent.BTLink#suspendTraffic() */ public void suspendTraffic() { sendNotInterested(); choke(); } }

The table below shows all metrics for BTConnection.java.

MetricValueDescription
BLOCKS86.00Number of blocks
BLOCK_COMMENT69.00Number of block comment lines
COMMENTS240.00Comment lines
COMMENT_DENSITY 0.52Comment density
COMPARISONS74.00Number of comparison operators
CYCLOMATIC150.00Cyclomatic complexity
DECL_COMMENTS68.00Comments in declarations
DOC_COMMENT142.00Number of javadoc comment lines
ELOC461.00Effective lines of code
EXEC_COMMENTS20.00Comments in executable code
EXITS104.00Procedure exits
FUNCTIONS58.00Number of function declarations
HALSTEAD_DIFFICULTY93.96Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY102.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 8.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 1.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003453.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 2.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
JAVA010811.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 3.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 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 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 1.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 1.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
JAVA01451444.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 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 1.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
LINES925.00Number of lines in the source file
LINE_COMMENT29.00Number of line comments
LOC545.00Lines of code
LOGICAL_LINES300.00Number of statements
LOOPS 4.00Number of loops
NEST_DEPTH 3.00Maximum nesting depth
OPERANDS1079.00Number of operands
OPERATORS2320.00Number of operators
PARAMS26.00Number of formal parameter declarations
PROGRAM_LENGTH3399.00Halstead program length
PROGRAM_VOCAB418.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS76.00Number of return points from functions
SIZE23604.00Size of the file in bytes
UNIQUE_OPERANDS356.00Number of unique operands
UNIQUE_OPERATORS62.00Number of unique operators
WHITESPACE140.00Number of whitespace lines