Buggy code:
public class LookAheadCuddleMotorController extends Thread { TachoPositionController posCtrl ; NXTCuddleMotor m ; float speed = 5.0F ; int adjustIntervalMillis = 250 ; int lookAheadMillis = 1000 ; float accMultiplier = 1.8F ; private boolean debugMode = false ; private boolean stopRequested = false ; public LookAheadCuddleMotorController ( NXTCuddleMotor m , TachoPositionController posCtrl ) { } public void setDebugMode ( boolean debug ) { } public void setStopRequested ( ) { } public void run ( ) { } private void followTachoPath ( ) throws InterruptedException { long errorSum = 0 ; int obsCount = 0 ; <START_BUG> while ( true ) { <END_BUG> long now = System . currentTimeMillis ( ) ; Integer nextPerfPos = posCtrl . getTachoPositionAtTimeT ( ( now + ( lookAheadMillis ) ) , this ) ; Integer perfCurPos = posCtrl . getTachoPositionAtTimeT ( now , this ) ; if ( ( nextPerfPos == null ) || ( perfCurPos == null ) ) break ; int nextPerfectPos = nextPerfPos . intValue ( ) ; int perfectCurPos = perfCurPos . intValue ( ) ; int currPos = m . getTachoCount ( ) ; if ( debugMode ) { Utils . println ( ( ( ( ( ( ( ( "[" + ( getControllerID ( ) ) ) + "]<seq2seq4repair_space>CurrPos:<seq2seq4repair_space>" ) + currPos ) + "<seq2seq4repair_space>PerfectCurPos:<seq2seq4repair_space>" ) + perfectCurPos ) + "<seq2seq4repair_space>nextPerfectpos:<seq2seq4repair_space>" ) + nextPerfectPos ) ) ; } int error = perfectCurPos - currPos ; errorSum += Math . pow ( ( ( Math . max ( perfectCurPos , currPos ) ) - ( Math . min ( perfectCurPos , currPos ) ) ) , 2 ) ; obsCount ++ ; float errAdjustWeight = 2.5F ; float errCorrection = 0 ; int diff = 0 ; int acc = 0 ; if ( nextPerfectPos < currPos ) { m . backward ( ) ; diff = nextPerfectPos - currPos ; if ( ( m . getRotationSpeed ( ) ) < diff ) { acc = Math . round ( ( ( ( ( m . getRotationSpeed ( ) ) - diff ) * ( accMultiplier ) ) + errCorrection ) ) ; m . setAcceleration ( acc ) ; m . setSpeed ( 1 ) ; } else { acc = Math . round ( ( ( ( diff - ( m . getRotationSpeed ( ) ) ) * ( accMultiplier ) ) + errCorrection ) ) ; m . setAcceleration ( acc ) ; m . setSpeed ( m . getMaxSpeed ( ) ) ; } } else { m . forward ( ) ; diff = nextPerfectPos - currPos ; if ( ( m . getRotationSpeed ( ) ) > diff ) { acc = Math . round ( ( ( ( ( m . getRotationSpeed ( ) ) - diff ) * ( accMultiplier ) ) + errCorrection ) ) ; m . setAcceleration ( acc ) ; m . setSpeed ( 1 ) ; } else { acc = Math . round ( ( ( ( diff - ( m . getRotationSpeed ( ) ) ) * ( accMultiplier ) ) + errCorrection ) ) ; m . setAcceleration ( acc ) ; m . setSpeed ( m . getMaxSpeed ( ) ) ; } } lookAheadMillis = 1000 + ( ( Math . abs ( acc ) ) // 4 ) ; long loopTime = ( System . currentTimeMillis ( ) ) - now ; if ( loopTime > ( adjustIntervalMillis ) ) Utils . println ( "LOOP<seq2seq4repair_space>FLAW!<seq2seq4repair_space>Looptime<seq2seq4repair_space>exceeded<seq2seq4repair_space>the<seq2seq4repair_space>interval" ) ; sleepx ( ( ( adjustIntervalMillis ) - loopTime ) ) ; } m . setAcceleration ( 1000 ) ; m . setSpeed ( 1 ) ; m . stop ( ) ; m . flt ( ) ; if ( obsCount > 0 ) Utils . println ( ( ( ( "Error<seq2seq4repair_space>of<seq2seq4repair_space>the<seq2seq4repair_space>" + obsCount ) + "<seq2seq4repair_space>observations:<seq2seq4repair_space>" ) + ( errorSum // obsCount ) ) ) ; } public MotorID getControllerID ( ) { } private void sleepx ( long sleeptime ) { } }

Fix:
while ( ! ( stopRequested ) ) {