IDEA IntelliJ Spinnt Intelliji oder ich?

Thallius

Top Contributor
Hi,

in folgendem Code

Code:
private LocalTime getStartTimeForMVSJob(Fieldengineer fe, LocalDateTime startDate)
{
   MultiJob lastJob = null;
   String date = Util.sqlDateFromLocalDateTime(startDate).substring(0, 10);
   for (MultiJob job: allJobs)
   {
      if(job.feno.equals(fe.feno) && job.assStart().substring(0, 10).equals(date))
      {
         if(lastJob == null || lastJob.assStart().compareTo(job.assStart()) <= 0)
            lastJob = job;
      }
   }
   int hour = 8;
   if(lastJob != null)
   {
      String lastStart = lastJob.assStart();
      hour = Integer.parseInt(lastStart.substring(11, 2)) + 1;
   }
   return LocalTime.of(hour, 0, 0);
}

bekomme ich in der Zeile

Code:
      hour = Integer.parseInt(lastStart.substring(11, 2)) + 1;

von Intelliji die Meldung "The call to substring ever fails as index is out of bounds".

Die Methode assStart() sieht so aus:

Code:
public String assStart()
{
   if(startDate != null)
      return Util.sqlDateFromLocalDateTime(startDate);
   else
      return null;
}

und Util.sqlDateFromLocalDateTime so

Code:
public static String sqlDateFromLocalDateTime(LocalDateTime date) 
{
   if(date == null)
      return null;
   return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}

Jetzt erklärt mir bitte einer wie Intelliji auf die komische Idee kommt, dass ein String mit 19 Zeichen einen Index out of bounds an Index 11 auslösen soll?

Gruß

Claus
 

Ähnliche Java Themen

Neue Themen


Oben