Java 类java.lang.ArrayIndexOutOfBoundsException 实例源码

项目:feathers-sdk    文件:DMessage.java   
/**
 * Place a string into the message (using UTF-8 encoding)
 */
public void putString(String s) throws ArrayIndexOutOfBoundsException, UnsupportedEncodingException
{
    /* convert the string into a byte array */
    byte[] bytes = s.getBytes("UTF-8"); //$NON-NLS-1$
    int length = bytes.length;
    int endAt = m_index + length + 1;

    if (endAt > m_content.length)
        throw new ArrayIndexOutOfBoundsException(endAt+" > "+m_content.length); //$NON-NLS-1$

    /* copy the string as a byte array */
    System.arraycopy(bytes, 0, m_content, m_index, length);
    m_index += length;

    /* now the null terminator */
    m_content[m_index++] = '\0';

    debugAppendString(s);
}
项目:Chronicle-Map    文件:ReplicatedGlobalMutableState$$Native.java   
@Override
public void setModificationIteratorInitAt(int index, boolean _modificationIteratorInit) {
    if (index < 0 || index >= 128) {
        throw new ArrayIndexOutOfBoundsException(index + " is out of bounds, array length 128");
    }
    int bitOffset = 240 + index;
    int byteOffset = bitOffset / 8;
    int bitShift = bitOffset & 7;
    int b = bs.readByte(offset + byteOffset);
    if (_modificationIteratorInit) {
        b |= (1 << bitShift);
    } else {
        b &= ~(1 << bitShift);
    }
    bs.writeByte(offset + byteOffset, (byte) b);
}
项目:freeVM    文件:Test9.java   
public Result test1() {
    int length = 20000;
    int index[] = new int[length];
    byte arr[] = new byte[length];
    try {
        for (int k = 0; k < length; k=+2) {
            arr[index[k] - 10000000] -= index[k];
        }
        return failed("TEST FAILED: ArrayIndexOutOfBoundsException " +
                "wasn't thrown");
    } catch (ArrayIndexOutOfBoundsException ae) {
        return passed();
    } catch (Throwable e) {
        log.add(e);
        return failed("TEST FAILED: unexpected " + e);
    }
}
项目:freeVM    文件:Test9.java   
public Result test2() {
    int length = 10000;
    int index[] = new int[length];
    long arr[] = new long[length];
    index[1] = length-1;
    int neg = -1;
    try {
        for (int k = length-1; k>0; k--) {
            arr[index[k] - neg] = 0;
        }
        return failed("TEST FAILED: ArrayIndexOutOfBoundsException " +
                "wasn't thrown");
    } catch (ArrayIndexOutOfBoundsException ae) {
        return passed();
    } catch (Throwable e) {
        log.add(e);
        return failed("TEST FAILED: unexpected " + e);
    }
}
项目:freeVM    文件:Test1.java   
public int test() {
    log.info("Start Test1 ...");
    try {
        boolean flag = false;
        int limit = 25000;
        Object[] obj = new Object[limit];
        for (int i=0; i<limit; i++) {
            try {
                obj[i] = String.valueOf(i);
            } finally {
                if (i > limit/2) flag = true;
                if (flag) obj = new Object[limit-1];
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        return pass();
    }
    return fail("TEST FAILED: ArrayIndexOutOfBoundsException " +
            " wasn't thrown");
}
项目:quorrabot    文件:Logger.java   
public void log(LogType t, String s) {
    try {
        this.queue.add(new LogItem(t, s));
    } catch (ArrayIndexOutOfBoundsException ex) {
        /* At shutdown this throws an exception. */
    }
}
项目:ics4u    文件:SeatingPlan.java   
/**
 * Sets the String element in the layout array to a name if it is a valid position 
 * pre: none
 * post: none
 */
public void setStudent(String name, int x, int y) {
    try {
        layout[y][x] = name;
        seatInvalid = false;
    } catch (ArrayIndexOutOfBoundsException e) {
        seatInvalid = true;
        System.out.println("(" + (x + 1) + ", " + (y + 1) + ") is not a valid seat.");
    }
}
项目:feathers-sdk    文件:DMessage.java   
private long get(int bytes) throws ArrayIndexOutOfBoundsException
{
    if (m_index+bytes > m_content.length)
        throw new ArrayIndexOutOfBoundsException(m_content.length-m_index+" < "+bytes); //$NON-NLS-1$

    long value = 0;
    for (int i=0; i<bytes; ++i) {
        long byteValue = m_content[m_index++] & 0xff;
        long byteValueShifted = byteValue << (8*i);
        value |= byteValueShifted;
    }

    debugAppendNumber(value, bytes);
    return value;
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Heart wrenchingly slow but since we don't have a length so we can't
 * do much better
 */
public String getString() throws ArrayIndexOutOfBoundsException
{
    int startAt = m_index;
    boolean done = false;

    /* scan looking for a terminating null */
    while(!done)
    {
        int ch = m_content[m_index++];
        if (ch == 0)
            done = true;
        else if (m_index > m_content.length)
            throw new ArrayIndexOutOfBoundsException("no string terminator found @"+m_index); //$NON-NLS-1$
    }

    /* build a new string and return it */
    String s;
    try
    {
        // The player uses UTF-8
        s = new String(m_content, startAt, m_index-startAt-1, "UTF-8"); //$NON-NLS-1$
    }
    catch(UnsupportedEncodingException uee)
    {
        // couldn't convert so let's try the default
        s = new String(m_content, startAt, m_index-startAt-1);
    }
    debugAppendString(s);
    return s;
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Appends a number to the end of the message
 * @param val the number
 * @param bytes how many bytes should be written
 */
public void put(long val, int bytes) throws ArrayIndexOutOfBoundsException
{
    if (m_index+bytes > m_content.length)
        throw new ArrayIndexOutOfBoundsException(m_content.length-m_index+" < "+bytes); //$NON-NLS-1$

    for (int i=0; i<bytes; ++i)
        m_content[m_index++] = (byte)(val >> 8*i);

    debugAppendNumber(val, bytes);
}
项目:pluotsorbet    文件:constructor.java   
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    ArrayIndexOutOfBoundsException object1 = new ArrayIndexOutOfBoundsException();
    harness.check(object1 != null);
    harness.check(object1.toString(), "java.lang.ArrayIndexOutOfBoundsException");

    ArrayIndexOutOfBoundsException object2 = new ArrayIndexOutOfBoundsException("nothing happens");
    harness.check(object2 != null);
    harness.check(object2.toString(), "java.lang.ArrayIndexOutOfBoundsException: nothing happens");

    ArrayIndexOutOfBoundsException object3 = new ArrayIndexOutOfBoundsException(null);
    harness.check(object3 != null);
    harness.check(object3.toString(), "java.lang.ArrayIndexOutOfBoundsException");

    ArrayIndexOutOfBoundsException object4 = new ArrayIndexOutOfBoundsException(0);
    harness.check(object4 != null);
    harness.check(object4.toString(), "java.lang.ArrayIndexOutOfBoundsException: 0");

    ArrayIndexOutOfBoundsException object5 = new ArrayIndexOutOfBoundsException(-1);
    harness.check(object5 != null);
    harness.check(object5.toString(), "java.lang.ArrayIndexOutOfBoundsException: -1");

    ArrayIndexOutOfBoundsException object6 = new ArrayIndexOutOfBoundsException(Integer.MAX_VALUE);
    harness.check(object6 != null);
    harness.check(object6.toString(), "java.lang.ArrayIndexOutOfBoundsException: 2147483647");

}
项目:pluotsorbet    文件:TryCatch.java   
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    // flag that is set when exception is caught
    boolean caught = false;
    try {
        throw new ArrayIndexOutOfBoundsException("ArrayIndexOutOfBoundsException");
    }
    catch (ArrayIndexOutOfBoundsException e) {
        // correct exception was caught
        caught = true;
    }
    harness.check(caught);
}
项目:Chronicle-Map    文件:ReplicatedGlobalMutableState$$Native.java   
@Override
public boolean getModificationIteratorInitAt(int index) {
    if (index < 0 || index >= 128) {
        throw new ArrayIndexOutOfBoundsException(index + " is out of bounds, array length 128");
    }
    int bitOffset = 240 + index;
    int byteOffset = bitOffset / 8;
    int bitShift = bitOffset & 7;
    return (bs.readByte(offset + byteOffset) & (1 << bitShift)) != 0;
}
项目:freeVM    文件:Test3.java   
public int test() {
    log.info("Start Test3 ...");
    int arr[] = new int[limit];
    arr[1] = 1;
    try {
        for(int k=1; k<limit; ) {
            log.info("k=" + k + ": arr[" + (k-1) + "] will be called");
            k=arr[k-1];
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        return pass();
    }
    return fail("TEST FAILED: ArrayIndexOutOfBoundsException wasn't thrown");
}
项目:freeVM    文件:Test2.java   
public int test() {
    log.info("Start Test2 ...");
    try {
        Thread[] threads = new Thread[limit];
        for (i=0; i<limit; i++) {
            if (i == (limit-1))  meth();
            threads[i] = threads[i]; 
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        return pass();
    }
    return fail("TEST FAILED: ArrayIndexOutOfBoundsException " +
            " wasn't thrown");
}
项目:Jogre    文件:ChineseCheckersModel.java   
/**
 * Retrieve the owner of a space on the board
 *
 * @param (col, row)           Location of board space
 * @return owner of the space
 */
public int getOwner(int col, int row) {
    try {
        return ownerBoard[col][row];
    } catch (ArrayIndexOutOfBoundsException e) {
        return -1;
    }
}
项目:Jogre    文件:ChineseCheckersModel.java   
/**
 * Retrieve the move vector for a space on the board
 *
 * @param (col, row)           Location of board space
 * @param theSpace             The board space
 * @return the move vector that ends at that space.
 */
public Vector getMoveVector(int col, int row) {
    try {
        return moveVectors[col][row];
    } catch (ArrayIndexOutOfBoundsException e) {
        return null;
    }
}
项目:Jogre    文件:ChineseCheckersModel.java   
/**
 * Determine if the given space exists or not.
 */
public boolean exists(Point boardPoint) {
    try {
        return existArray[boardPoint.x][boardPoint.y];
    } catch (ArrayIndexOutOfBoundsException e) {
        return false;
    }
}
项目:Jogre    文件:AbstracModel.java   
/**
 * Indicate if the given player has the given card.
 *
 * @param   playerId    The player to check for the card
 * @param   suit        The suit of the card
 * @param   value       The value of the card
 * @return  true or false
 */
public boolean playerHasCard(int playerId, int suit, int value) {
    try {
        return (taken[playerId][value][suit] > NOT_HAVE);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("Error: Asked for pl= " + playerId + ", suit= " + suit + ", value= " + value);
        return false;
    }
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Extract the next byte
 */
public int getByte() throws ArrayIndexOutOfBoundsException
{
    return (int) get(1);
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Extract the next 2 bytes, which form a 16b integer, from the message
 */
public int getWord() throws ArrayIndexOutOfBoundsException
{
    return (int) get(2);
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Extract the next 4 bytes, which form a 32b integer, from the message
 */
public long getDWord() throws ArrayIndexOutOfBoundsException
{
    return get(4);
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Extract the next 8 bytes, which form a 64b integer, from the message
 */
public long getLong() throws ArrayIndexOutOfBoundsException
{
    return get(8);
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Extract a pointer from the message -- either 8 bytes or 4 bytes,
 * depending on how big pointers are in the target Flash player
 */
public long getPtr() throws ArrayIndexOutOfBoundsException
{
    return get(getSizeofPtr());
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Appends a byte to the end of the message
 */
public void putByte(byte val) throws ArrayIndexOutOfBoundsException
{
    put(val, 1);
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Appends 2 bytes, which form a 16b integer, into the message
 */
public void putWord(int val) throws ArrayIndexOutOfBoundsException
{
    put(val, 2);
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Appends 4 bytes, which form a 32b integer, into the message
 */
public void putDWord(int val) throws ArrayIndexOutOfBoundsException
{
    put(val, 4);
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Appends 8 bytes, which form a 64b integer, into the message
 */
public void putLong(long val) throws ArrayIndexOutOfBoundsException
{
    put(val, 8);
}
项目:feathers-sdk    文件:DMessage.java   
/**
 * Appends a pointer into the message -- either 8 bytes or 4 bytes,
 * depending on how big pointers are in the target Flash player
 */
public void putPtr(long val) throws ArrayIndexOutOfBoundsException
{
    put(val, getSizeofPtr());
}
项目:Jogre    文件:HexModel.java   
/**
 * Attempt to make a move on the board.
 *
 * @param (col, row)        Location of board space to be played
 * @param playerSeat        The player which is playing on the space
 * @return validity of the play
 *          true = valid play
 *          false = invalid play
 */
public boolean makeMove(int col, int row, int playerSeat) {
    if (!isValidPlay(col, row)) {
        return false;
    }

    // Check for the second player invoking the "pie-rule"
    if ((turnNumber == 2) && (ownerBoard[col][row] != PLAYER_NONE)) {
        // Remove player 1's piece from the board.
        ownerBoard[col][row] = PLAYER_NONE;
        islandBoard[col][row] = 0;

        // Change player 2's move to the mirror image position.
        col = (numCols - 1 - col);
    }

    // Make the play on the board
    ownerBoard[col][row] = playerSeat;
    if ((col == magicCol) && (row == magicRow)) {
        islandBoard[col][row] = magicIsland[playerSeat];
    } else {
        islandBoard[col][row] = turnNumber;
    }

    // See if we join any islands as a result of this move.
    HexBoardUtils.getNeighbors(col, row, neighborArray);
    for (int i=0; i<6; i++) {
        int nc = neighborArray[0][i];
        int nr = neighborArray[1][i];
        try {
            if (ownerBoard[nc][nr] == playerSeat) {
                mergeIslands(islandBoard[col][row], islandBoard[nc][nr]);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            // The neighbor was off the board, so ignore this one...
        }
    }

    turnNumber += 1;

    // Update the Observers
    refreshObservers();

    return true;
}
项目:barrel-cdf-generator    文件:SpectrumExtract.java   
private static float find511(double[] x, double[] y){
   GaussianFitter fitter = 
      new GaussianFitter(new LevenbergMarquardtOptimizer());
   double[] 
      fit_params = {10, Constants.DOUBLE_FILL, 1},
      curve = new double[PEAK_511_WIDTH - 4];
   int[]
      high_area = new int[PEAK_511_WIDTH];
   double
      m, b, 
      slope = 0,
      this_low= 0,
      last_low = 0;
   int
      apex = 0,
      high_cnt = 0;

   // guess at a linear background
   m = (y[PEAK_511_WIDTH - 1] - y[0]) / (x[PEAK_511_WIDTH - 1] - x[0]);
   b = y[0] - m * x[0];

   //convert y to cnts/bin_width
   for(int bin_i = 0; bin_i < x.length; bin_i++){
      y[bin_i] /= (
         RAW_EDGES[2][bin_i + PEAK_511_START + 1] - 
         RAW_EDGES[2][bin_i + PEAK_511_START]
      );
   }

   //take the second derivitave to find peak
   for(int bin_i = 2; bin_i < x.length - 2; bin_i++){
      curve[bin_i - 2] = y[bin_i + 2] - (2 * y[bin_i]) + y[bin_i - 2];
   }

   //find low point of second derivitave using moving average
   this_low  = (curve[0] + curve[1] + curve[2]);
   last_low = this_low;
   for(int bin_i = 2; bin_i < curve.length - 1; bin_i++){
      this_low += (curve[bin_i + 1] - curve[bin_i - 2]);
      if(this_low < last_low){
         apex = bin_i + 2;
         last_low = this_low;
      }
   }

   //do the curve fit
   try{
      fit_params[1] = x[apex]; //guess for peak location
      for(int bin_i = apex - 3; bin_i < apex + 3; bin_i++){
         fitter.addObservedPoint(x[bin_i],  y[bin_i]);
      }
      fit_params = fitter.fit(fit_params);
   }
   catch(ArrayIndexOutOfBoundsException ex){
      System.out.println(
         "Payload ID: " + CDF_Gen.getSetting("currentPayload") + 
         " Date: " + CDF_Gen.getSetting("date"));
      System.out.println("Gaussian out of bounds: " + apex);
      fit_params[1] = Constants.DOUBLE_FILL;
   }
   return (float)fit_params[1];
}
项目:Jogre    文件:AbstracModel.java   
/**
 * Indicate the status of the given card with respect to the
 * given player.
 *
 * @param   playerId    The player to check for the card
 * @param   suit        The suit of the card
 * @param   value       The value of the card
 * @return  NOT_AVAILABLE => Other player has already taken card
 *          NOT_HAVE => This card is still not taken by either player
 *          TAKEN => This card has been taken by this player
 *          JUST_TAKEN => This card has been taken by this player on his last turn
 */
public int getPlayerCardCode(int playerId, int suit, int value) {
    try {
        return (taken[playerId][value][suit]);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("Error: Asked for pl= " + playerId + ", suit= " + suit + ", value= " + value);
        return NOT_HAVE;
    }
}
项目:Jogre    文件:HexModel.java   
/**
 * Determine if the requested play is valid or not.
 *
 * To be valid the space must exist and it must either be empty OR
 * it must be turn number 2.  (In the case where it is turn number 2,
 * the the second player is invoking the "pie-rule" and taking the
 * first player's move for himself.)
 *
 * @param (col, row)        Location of board space to be tested
 * @return true or false
 */
public boolean isValidPlay(int col, int row) {
    try {
        return (existArray[col][row] &&
                     ((ownerBoard[col][row] == PLAYER_NONE) ||
                      (turnNumber == 2)) );
    } catch (ArrayIndexOutOfBoundsException e) {
        return false;
    }
}