JDK-8307978 : java.util.GregorianCalendar.computeTime() crashes with lenient=false
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 11
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2023-05-11
  • Updated: 2023-05-12
Description
ADDITIONAL SYSTEM INFORMATION :
 Linux and Windows 64Bit with Java 11.0.19 Corretto and Adoptium


A DESCRIPTION OF THE PROBLEM :
Core Dump when using GregorianCalen


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Using the class below on my machine results in a crashed JVM in ~90% of cases.
When starting with lenient=false it always crashed (~12 tries)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should not crash
ACTUAL -
crashes

---------- BEGIN SOURCE ----------
import java.util.Calendar;
import java.util.Date;
import java.util.stream.IntStream;

public class Datetest
{
  public static void main( String[] args )

  {

	  Datetest.crashMe(false);
	  Datetest.crashMe(true);

  }

  public static void crashMe(boolean crash) {
	    IntStream.range( 0, 8000 ).forEach( i -> {

	        Calendar timespan = Calendar.getInstance(); 
	        timespan = removeTime( new Date(), crash );
	        timespan.getTime();

	        if (i%10==0) {
	      	  System.out.println( "Crash: "+crash+ " Iteration: " + i + " / " + timespan.toString() );
	        }

	      } );
	  
  }
 

  public static Calendar removeTime( Date date, boolean crash_me )
  {

    Calendar calendar = Calendar.getInstance();
    if (crash_me) {
    	calendar.setLenient( false );
    }
    calendar.setTime( date );
    calendar = Datetest.removeTime( calendar );
    return calendar;

  }


  public static Calendar removeTime( Calendar calendar )

  {

    calendar.set( Calendar.HOUR_OF_DAY, 0 );

    calendar.set( Calendar.MINUTE, 0 );

    calendar.set( Calendar.SECOND, 0 );

    calendar.set( Calendar.MILLISECOND, 0 );

    return calendar;

  }

 

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Never crashes with lenient=true
I could also not reproduce this with 32bit-Build (5 tries)

FREQUENCY : often



Comments
The observations on Windows 10: JDK 11: Passed, no crash happened.
12-05-2023