Skip to content

Reusing stdin causes Nooblab to bug out sometimes #1

@samuelbsource

Description

@samuelbsource

If the program crashes in Nooblab (java), and you keep giving it input after that, and then restart the program, it will reuse the data that was inserted after the program crashed.

Try the following program:

import java.util.Scanner;	  	    	     		 			
	  	    	     		 			
public class Main	  	    	     		 			
{	  	    	     		 			
  public static void main(String[] args)	  	    	     		 			
  {	  	    	     		 			
    Scanner scanner = new Scanner(System.in);	  	    	     		 			
    boolean isRunning = true;	  	    	     		 			
	  	    	     		 			
    /* Start the main program loop */	  	    	     		 			
    while (isRunning)	  	    	     		 			
    {	  	    	     		 			
      System.out.println("==== Edu Track - main menu ====");	  	    	     		 			
      System.out.println("1. Input data");	  	    	     		 			
      System.out.println("2. Crash the program");	  	    	     		 			
      System.out.println("3. Exit");	  	    	     		 			
      System.out.print("Input: ");	  	    	     		 			
	  	    	     		 			
      String option = scanner.nextLine();	  	    	     		 			
      if (option.equals("1"))	  	    	     		 			
      {	  	    	     		 			
        System.out.println("You selected option #1");	  	    	     		 			
      }	  	    	     		 			
      else if (option.equals("2"))	  	    	     		 			
      {	  	    	     		 			
        throw new RuntimeException("I haz died!");	  	    	     		 			
      }	  	    	     		 			
      else {	  	    	     		 			
        isRunning = false;	  	    	     		 			
      }	  	    	     		 			
    }	  	    	     		 			
  }	  	    	     		 			
}

Steps to reproduce:

  1. Run the program
  2. Selection option #2
  3. Click on the terminal, input 1 [enter] 3 [Enter]
  4. Run the program again

It will print "You selected option #1" and then exit, which proofs that the data inputted into the terminal before the program run was reused.
I think this could be the source of issues when students sometimes report: "The test isn't working until I reload the page".

Would it be useful to flush the terminal before running the program?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions