-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
7, 8, 9
-
generic
FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
In the below code example, the code goes into an infinite loop because the second time sc.nextInt() is called after it throws an exception, it just throws an exception instead of getting input.
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the above code.
2. Enter a non-number.
3. See it go into an infinite loop.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After printing " Not a number " , it should ask the user for another number.
ACTUAL -
The program keeps printing " Not a number " .
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Scanner sc = new Scanner(System.in);
while(true)
{
try
{
System.out.print( " Please enter a number " );
sc.nextInt();
break;
}
catch(InputMismatchException e)
{
System.err.println( " Not a number " );
}
}
---------- END SOURCE ----------
A DESCRIPTION OF THE PROBLEM :
In the below code example, the code goes into an infinite loop because the second time sc.nextInt() is called after it throws an exception, it just throws an exception instead of getting input.
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the above code.
2. Enter a non-number.
3. See it go into an infinite loop.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After printing " Not a number " , it should ask the user for another number.
ACTUAL -
The program keeps printing " Not a number " .
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Scanner sc = new Scanner(System.in);
while(true)
{
try
{
System.out.print( " Please enter a number " );
sc.nextInt();
break;
}
catch(InputMismatchException e)
{
System.err.println( " Not a number " );
}
}
---------- END SOURCE ----------