java.lang.ArrayIndexOutOfBoundsException: -1

QOS.ch JIRA | Hans van der Meer | 10 years ago
  1. 0

    Below is code from CallerData (logback 0.9.7) This gives an error as shown below. java.lang.ArrayIndexOutOfBoundsException: -1 at ch.qos.logback.classic.spi.CallerData.extract(CallerData.java:101) at ch.qos.logback.classic.spi.LoggingEvent.getCallerData(LoggingEvent.java:246) In my code (Eclipse RCP) LoggingEvent's are collected by an appender in a java.util.List. Then a Jface TableViewer is allocated and the input set to that list. The processing of the accumulated LoggingEvents now each throw the ArrayIndexOutOfBoundsException. After registering the viewer containing object with the appender, new incoming LoggingEvents are given to the viewer and are processed without problem. It looks like the "int found" has kept its value of -1, presumably because the equals in line 88 never becomes true. I am inclined to consider this a bug, or at least unsafe coding, because a bad index in certain circumstances can reach the code in line 101. The code in lines 86-97 does not guarantee that a bad index cannot occur. 78 public static CallerData[] extract(Throwable t, String fqnOfInvokingClass) { 79 if (t == null) { 80 return null; 81 } 82 83 StackTraceElement[] steArray = t.getStackTrace(); 84 CallerData[] callerDataArray; 85 86 int found = -1; 87 for (int i = 0; i < steArray.length; i++) { 88 if(steArray[i].getClassName().equals(fqnOfInvokingClass)) { 89 // the caller is assumed to be the next stack frame, hence the +1. 90 found = i + 1; 91 } else { 92 if(found != -1) { 93 break; 94 } 95 } 96 97 } 98 99 callerDataArray = new CallerData[steArray.length - found]; 100 for (int i = found; i < steArray.length; i++) { 101 callerDataArray[i-found] = new CallerData(steArray[i]); 102 } 103 return callerDataArray; 104 } 105

    QOS.ch JIRA | 10 years ago | Hans van der Meer
    java.lang.ArrayIndexOutOfBoundsException: -1
  2. 0

    Below is code from CallerData (logback 0.9.7) This gives an error as shown below. java.lang.ArrayIndexOutOfBoundsException: -1 at ch.qos.logback.classic.spi.CallerData.extract(CallerData.java:101) at ch.qos.logback.classic.spi.LoggingEvent.getCallerData(LoggingEvent.java:246) In my code (Eclipse RCP) LoggingEvent's are collected by an appender in a java.util.List. Then a Jface TableViewer is allocated and the input set to that list. The processing of the accumulated LoggingEvents now each throw the ArrayIndexOutOfBoundsException. After registering the viewer containing object with the appender, new incoming LoggingEvents are given to the viewer and are processed without problem. It looks like the "int found" has kept its value of -1, presumably because the equals in line 88 never becomes true. I am inclined to consider this a bug, or at least unsafe coding, because a bad index in certain circumstances can reach the code in line 101. The code in lines 86-97 does not guarantee that a bad index cannot occur. 78 public static CallerData[] extract(Throwable t, String fqnOfInvokingClass) { 79 if (t == null) { 80 return null; 81 } 82 83 StackTraceElement[] steArray = t.getStackTrace(); 84 CallerData[] callerDataArray; 85 86 int found = -1; 87 for (int i = 0; i < steArray.length; i++) { 88 if(steArray[i].getClassName().equals(fqnOfInvokingClass)) { 89 // the caller is assumed to be the next stack frame, hence the +1. 90 found = i + 1; 91 } else { 92 if(found != -1) { 93 break; 94 } 95 } 96 97 } 98 99 callerDataArray = new CallerData[steArray.length - found]; 100 for (int i = found; i < steArray.length; i++) { 101 callerDataArray[i-found] = new CallerData(steArray[i]); 102 } 103 return callerDataArray; 104 } 105

    QOS.ch JIRA | 10 years ago | Hans van der Meer
    java.lang.ArrayIndexOutOfBoundsException: -1
  3. 0

    ArrayIndexOutOfBounds When Splitting String

    Stack Overflow | 4 years ago | n0shadow
    java.lang.ArrayIndexOutOfBoundsException: 1
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    ArrayIndexOutOfBoundsException occurring when program running

    Stack Overflow | 4 years ago | dharma
    java.lang.ArrayIndexOutOfBoundsException: 1
  6. 0

    Parsing Data from CSV to Array in Java

    Stack Overflow | 5 years ago
    java.lang.ArrayIndexOutOfBoundsException: 1

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ArrayIndexOutOfBoundsException

      -1

      at ch.qos.logback.classic.spi.CallerData.extract()
    2. Logback Classic Module
      LoggingEvent.getCallerData
      1. ch.qos.logback.classic.spi.CallerData.extract(CallerData.java:101)
      2. ch.qos.logback.classic.spi.LoggingEvent.getCallerData(LoggingEvent.java:246)
      2 frames