Buggy code:
public abstract class AbstractSubscription implements Subscription { private static final Logger LOG = LoggerFactory . getLogger ( AbstractSubscription . class ) ; protected Broker broker ; protected ConnectionContext context ; protected ConsumerInfo info ; protected final DestinationFilter destinationFilter ; protected final CopyOnWriteArrayList < Destination > destinations = new CopyOnWriteArrayList < Destination > ( ) ; private BooleanExpression selectorExpression ; private ObjectName objectName ; private int cursorMemoryHighWaterMark = 70 ; private boolean slowConsumer ; private long lastAckTime ; private final SubscriptionStatistics subscriptionStatistics = new SubscriptionStatistics ( ) ; public AbstractSubscription ( Broker broker , ConnectionContext context , ConsumerInfo info ) throws InvalidSelectorException { } private static BooleanExpression parseSelector ( ConsumerInfo info ) throws InvalidSelectorException { } @ Override public synchronized void acknowledge ( final ConnectionContext context , final MessageAck ack ) throws Exception { } @ Override public boolean matches ( MessageReference node , MessageEvaluationContext context ) throws IOException { } @ Override public boolean isWildcard ( ) { } @ Override public boolean matches ( ActiveMQDestination destination ) { } @ Override public void add ( ConnectionContext context , Destination destination ) throws Exception { } @ Override public List < MessageReference > remove ( ConnectionContext context , Destination destination ) throws Exception { } @ Override public ConsumerInfo getConsumerInfo ( ) { } @ Override public void gc ( ) { } @ Override public ConnectionContext getContext ( ) { } public ConsumerInfo getInfo ( ) { } public BooleanExpression getSelectorExpression ( ) { } @ Override public String getSelector ( ) { } @ Override public void setSelector ( String selector ) throws InvalidSelectorException { } @ Override public ObjectName getObjectName ( ) { } @ Override public void setObjectName ( ObjectName objectName ) { } @ Override public int getPrefetchSize ( ) { } public void setPrefetchSize ( int newSize ) { } @ Override public boolean isRecoveryRequired ( ) { } @ Override public boolean isSlowConsumer ( ) { } public void setSlowConsumer ( boolean val ) { } @ Override public boolean addRecoveredMessage ( ConnectionContext context , MessageReference message ) throws Exception { } @ Override public ActiveMQDestination getActiveMQDestination ( ) { } @ Override public boolean isBrowser ( ) { } @ Override public int getInFlightUsage ( ) { } public void addDestination ( Destination destination ) { } public void removeDestination ( Destination destination ) { } @ Override public int getCursorMemoryHighWaterMark ( ) { } @ Override public void setCursorMemoryHighWaterMark ( int cursorMemoryHighWaterMark ) { } @ Override public int countBeforeFull ( ) { <START_BUG> return ( getDispatchedQueueSize ( ) ) - ( info . getPrefetchSize ( ) ) ; <END_BUG> } @ Override public void unmatched ( MessageReference node ) throws IOException { } protected void doAddRecoveredMessage ( MessageReference message ) throws Exception { } @ Override public long getTimeOfLastMessageAck ( ) { } public void setTimeOfLastMessageAck ( long value ) { } public long getConsumedCount ( ) { } public void incrementConsumedCount ( ) { } public void resetConsumedCount ( ) { } @ Override public SubscriptionStatistics getSubscriptionStatistics ( ) { } }

Fix:
return ( info . getPrefetchSize ( ) ) - ( getDispatchedQueueSize ( ) ) ;