Example usage for java.lang ArrayIndexOutOfBoundsException getMessage

List of usage examples for java.lang ArrayIndexOutOfBoundsException getMessage

Introduction

In this page you can find the example usage for java.lang ArrayIndexOutOfBoundsException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.mortbay.jetty.load.generator.listeners.CollectorServer.java

@Override
public void onResourceNode(Resource.Info info) {
    String path = info.getResource().getPath();

    Recorder recorder = recorderPerPath.get(path);
    if (recorder == null) {
        recorder = new Recorder(TimeUnit.MICROSECONDS.toNanos(1), //
                TimeUnit.MINUTES.toNanos(1), //
                3);//from ww  w.  ja  va  2 s . c  om
        recorderPerPath.put(path, recorder);
    }

    long time = info.getResponseTime() - info.getRequestTime();
    try {
        recorder.recordValue(time);
    } catch (ArrayIndexOutOfBoundsException e) {
        LOGGER.warn("skip error recording time {}, {}", time, e.getMessage());
    }

}

From source file:edu.harvard.mcz.imagecapture.RunnableJobTableModel.java

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    Object returnvalue = null;//from  w  ww . j a v  a 2 s  .  com
    try {
        switch (columnIndex) {
        case 0:
            returnvalue = (Integer) rowIndex;
            break;
        case 1:
            returnvalue = ((RunnableJob) jobs.toArray()[rowIndex]).getName();
            break;
        case 2:
            if (((RunnableJob) jobs.toArray()[rowIndex]).getStartTime() == null) {
                returnvalue = "----";
            } else {
                returnvalue = DateFormat.getTimeInstance()
                        .format(((RunnableJob) jobs.toArray()[rowIndex]).getStartTime());
            }
            break;
        case 3:
            returnvalue = ((RunnableJob) jobs.toArray()[rowIndex]).percentComplete();
            log.debug(returnvalue);
            break;
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        log.debug(e.getMessage());
        fireTableDataChanged();
    } catch (NullPointerException e) {
        log.debug(e.getMessage());
        fireTableDataChanged();
    }
    return returnvalue;
}

From source file:voldemort.store.cachestore.impl.BackupThread.java

public void start(int threshold) {
    if (store.getServerState() != State.Active) {
        logger.warn("Sever state is " + store.getServerState() + " can not run back up task");
        return;// ww w  .j a v a  2  s  .  c o m
    }
    logger.info("Start backup data to " + filename + " threshold " + threshold);
    try {
        store.setServerState(State.Backup);
        ChannelStore current = ChannelStore.open(filename, new HashMap<Key, Value>(), true, index, false);
        ChannelStore old = store.getList().get(index);
        int totalRecord = old.getTotalRecord();
        int error = 0;
        int deleted = 0;
        long per = 0;
        int j = 0;
        per = totalRecord / 10;
        // monitor threshhold MB/sec
        long begin = System.currentTimeMillis();
        int bytesPerSecond = 0;
        logger.info("total records " + totalRecord);
        for (int i = 0; i < totalRecord; i++) {
            if (per > 0 && (i + 1) % per == 0) {
                logger.info((++j * 10) + "% complete");
            }
            try {
                Key key = old.readKey(i);
                // key == null means delete flag is on
                if (key == null) {
                    deleted++;
                    continue;
                }
                CacheBlock block = store.getMap().get(key);
                if (block == null)
                    logger.info("key " + key.toString() + " is not longer in map");
                else if (block.getIndex() != index) {
                    logger.info("skip, block.getIndex " + block.getIndex() + " not equal to " + index);
                } else {
                    synchronized (block) {
                        transfer(old, block, current, key, i);
                    }
                    if (threshold > 0) {
                        bytesPerSecond += block.getDataLen();
                        if (bytesPerSecond > threshold) {
                            long d = System.currentTimeMillis() - begin;
                            // faster than thresh hold
                            if (d < 1000) {
                                try {
                                    Thread.sleep(1000 - d);
                                } catch (InterruptedException ex) {
                                    //swallow exception
                                }
                            }
                            // reset parameter
                            begin = System.currentTimeMillis();
                            bytesPerSecond = 0;
                        }
                    }

                }
            } catch (ArrayIndexOutOfBoundsException iex) {
                logger.error(iex.getMessage() + " rec #" + i);
                error++;
            } catch (Exception io) {
                // swallow exception
                logger.error(io.getMessage(), io);
                error++;
            }

        }
        if (error == 0) {
            logger.info("complete backup data " + filename + " total records " + totalRecord + " deleted "
                    + deleted);
        } else
            logger.error("backup data total " + error);
        if (current != null) {
            logger.info("close " + filename);
            current.close();
        }
    } catch (Throwable th) {
        //swallow the error
        logger.error(th.getMessage(), th);
    } finally {
        store.setServerState(State.Active);
    }
}

From source file:com.grouptuity.venmo.VenmoSDK.java

public static VenmoResponse validateVenmoPaymentResponse(String signed_payload) {
    String encoded_signature, payload;
    if (signed_payload == null) {
        return new VenmoResponse(null, null, null, "0");
    }//from w  w w . j a  v a 2 s.co  m
    try {
        String[] encodedsig_payload_array = signed_payload.split("\\.");
        encoded_signature = encodedsig_payload_array[0];
        payload = encodedsig_payload_array[1];
    } catch (ArrayIndexOutOfBoundsException e) {
        return new VenmoResponse(null, null, null, "0");
    }

    String decoded_signature = base64_url_decode(encoded_signature);
    String data;
    // check signature 
    String expected_sig = hash_hmac(payload, Grouptuity.VENMO_SECRET, "HmacSHA256");

    Log.d("VenmoSDK", "expected_sig using HmacSHA256:" + expected_sig);

    VenmoResponse myVenmoResponse;

    if (decoded_signature.equals(expected_sig)) {
        data = base64_url_decode(payload);

        try {
            JSONArray response = (JSONArray) JSONValue.parse(data);
            JSONObject obj = (JSONObject) response.get(0);
            String payment_id = obj.get("payment_id").toString();
            String note = obj.get("note").toString();
            String amount = obj.get("amount").toString();
            String success = obj.get("success").toString();
            myVenmoResponse = new VenmoResponse(payment_id, note, amount, success);
        } catch (Exception e) {
            Log.d("VenmoSDK", "Exception caught: " + e.getMessage());
            myVenmoResponse = new VenmoResponse(null, null, null, "0");
        }
    } else {
        Log.d("VenmoSDK", "Signature does NOT match");
        myVenmoResponse = new VenmoResponse(null, null, null, "0");
    }
    return myVenmoResponse;
}

From source file:com.yahoo.semsearch.fastlinking.DPSearch.java

/**
 * Run forward-backward algorithm on multiple entity candidates and returns a filtered list of coherent entities
 * Takes nbest list and/*from w  ww .  j a va  2s.co m*/
 * @param nBestList an array of arraylists of wiki entities; for each entity span we have a list of candidate
 *                       wikilinks (nbest list)
 * @param entitySurfaceForms an array of entity spans
 * @return DPSearch object that contains lattice of paths and likelihood scores
 */
public DPSearch dynamicProgrammingSearch(List<String>[] nBestList, String[] entitySurfaceForms) {

    int sequenceLength = entitySurfaceForms.length;
    int nBestLength = MAXNBEST;
    double[][] logSimilarityOverall = new double[sequenceLength][nBestLength];
    for (int i = 0; i < logSimilarityOverall.length; i++) {
        Arrays.fill(logSimilarityOverall[i], DEFAULT_LOG_LIKELIHOOD);
    }
    String[][] path = new String[sequenceLength][nBestLength];
    for (int i = 0; i < path.length; i++) {
        Arrays.fill(path[i], "");
    }
    ListIterator<String> it = nBestList[0].listIterator();
    while (it.hasNext()) {
        //MAKE SURE to call NextIndex before Next

        int index = it.nextIndex();
        String currentCandidate = it.next();

        double entity2WordSim = gensimEntityEmbeddings.entity2WordSimilarity(prependWiki(currentCandidate),
                entitySurfaceForms[0].replace(" ", "_"));
        double lexicalSim = gensimEntityEmbeddings.lexicalSimilarity(currentCandidate.replace("_", " "),
                entitySurfaceForms[0]);

        logSimilarityOverall[0][index] = Math.max(
                Math.log((1 - LEXSIM_LAMBDA) * entity2WordSim + LEXSIM_LAMBDA * lexicalSim),
                DEFAULT_LOG_LIKELIHOOD);

        path[0][index] = currentCandidate;
    }

    ListIterator<String> currentCandidateIterator, previousCandidateIterator;
    for (int i = 1; i < sequenceLength; i++) {
        currentCandidateIterator = nBestList[i].listIterator();

        while (currentCandidateIterator.hasNext()) {

            //MAKE SURE to call NextIndex before Next
            int currentCandidateIndex = currentCandidateIterator.nextIndex();
            String currentCandidate = currentCandidateIterator.next();

            double entity2WordSim = gensimEntityEmbeddings.entity2WordSimilarity(prependWiki(currentCandidate),
                    entitySurfaceForms[i].replace(" ", "_"));
            double lexicalSim = gensimEntityEmbeddings.lexicalSimilarity(currentCandidate.replace("_", " "),
                    entitySurfaceForms[i]);

            double candidateNBestSimilarity = Math
                    .log((1 - LEXSIM_LAMBDA) * entity2WordSim + LEXSIM_LAMBDA * lexicalSim);

            double bestSimilarity = 0.0;
            double interCandidateSimilarity = 0.0;
            int previousBestCandidateIndex = -1;
            previousCandidateIterator = nBestList[i - 1].listIterator();
            while (previousCandidateIterator.hasNext()) {

                //MAKE SURE to call NextIndex before Next

                int index = previousCandidateIterator.nextIndex();
                String previousCandidate = previousCandidateIterator.next();

                double entity2EntitySimilarity = gensimEntityEmbeddings
                        .entity2EntitySimilarity(prependWiki(previousCandidate), prependWiki(currentCandidate));

                double entity2EntityLexicalSimilarity = gensimEntityEmbeddings.lexicalSimilarity(
                        previousCandidate.replace("_", " "), currentCandidate.replace("_", " "));

                double jointSimilarity = (1 - LEXSIM_LAMBDA) * entity2EntitySimilarity
                        + LEXSIM_LAMBDA * entity2EntityLexicalSimilarity;
                interCandidateSimilarity = Math.log(jointSimilarity);

                if (bestSimilarity == 0.0) {
                    bestSimilarity = interCandidateSimilarity + logSimilarityOverall[i - 1][index];
                    previousBestCandidateIndex = index;

                } else if (interCandidateSimilarity + logSimilarityOverall[i - 1][index] > bestSimilarity) {
                    bestSimilarity = interCandidateSimilarity + logSimilarityOverall[i - 1][index];
                    previousBestCandidateIndex = index;

                }
            }
            try {
                logSimilarityOverall[i][currentCandidateIndex] = Math
                        .max(bestSimilarity + candidateNBestSimilarity, DEFAULT_LOG_LIKELIHOOD);

                path[i][currentCandidateIndex] = path[i - 1][previousBestCandidateIndex] + CANDIDATE_DELIMITER
                        + currentCandidate;

            } catch (ArrayIndexOutOfBoundsException e) {
                e.getMessage();
            }
        }

    }
    RealVector realVector = new ArrayRealVector(logSimilarityOverall[sequenceLength - 1]);
    int bestPathIndex = realVector.getMaxIndex();

    DPSearch dpSearch = new DPSearch(logSimilarityOverall, path);
    return dpSearch;
}

From source file:gov.bnl.channelfinder.api.ChannelFinderClientImpl.java

public static MultivaluedMap<String, String> buildSearchMap(String searchPattern) {
    MultivaluedMap<String, String> map = new MultivaluedMapImpl();
    searchPattern = searchPattern.replaceAll(", ", ",");
    String[] words = searchPattern.split("\\s");
    if (words.length <= 0) {
        throw new IllegalArgumentException();
    } else {//from  w w  w. j  a v a 2  s .c o  m
        for (int index = 0; index < words.length; index++) {
            if (!words[index].contains("=")) {
                // this is a name value
                if (words[index] != null)
                    map.add("~name", words[index]);
            } else {
                // this is a property or tag
                String[] keyValue = words[index].split("=");
                String key = null;
                String valuePattern;
                try {
                    key = keyValue[0];
                    valuePattern = keyValue[1];
                    if (key.equalsIgnoreCase("Tags")) {
                        key = "~tag";
                    }
                    for (String value : valuePattern.replace("||", ",").split(",")) {
                        map.add(key, value);
                    }
                } catch (ArrayIndexOutOfBoundsException e) {
                    if (e.getMessage().equals(String.valueOf(0))) {
                        throw new IllegalArgumentException(
                                "= must be preceeded by a propertyName or keyword Tags.");
                    } else if (e.getMessage().equals(String.valueOf(1)))
                        throw new IllegalArgumentException("key: '" + key + "' is specified with no pattern.");
                }

            }
        }
    }
    return map;
}

From source file:com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImplTest.java

/**
 * Test method for/*from   w  ww.  j  av a  2 s  .c o  m*/
 * {@link com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImpl#getQueryResponse(java.lang.String)}
 * .
 */
@Ignore
@Test
public void testGetQueryResponse() {
    logger.debug("RUNNING TEST FOR BASIC QUERY RESPONSE");
    jiraDataFactory = new JiraDataFactoryImpl(properties.getProperty("jira.credentials"),
            properties.getProperty("jira.base.url"), properties.getProperty("jira.query.endpoint"));
    jiraDataFactory.buildBasicQuery(query);
    try {
        JSONArray rs = jiraDataFactory.getQueryResponse();

        /*
         * Testing actual JSON for values
         */
        JSONArray dataMainArry = new JSONArray();
        JSONObject dataMainObj = new JSONObject();
        dataMainArry = (JSONArray) rs.get(0);
        dataMainObj = (JSONObject) dataMainArry.get(0);

        logger.info("Basic query response: " + dataMainObj.get("fields").toString());
        // fields
        assertTrue("No valid Number was found", dataMainObj.get("fields").toString().length() >= 1);
    } catch (NullPointerException npe) {
        fail("There was a problem with an object used to connect to Jira during the test\n" + npe.getMessage()
                + " caused by: " + npe.getCause());
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        fail("The object returned from Jira had no JSONObjects in it during the test; try increasing the scope of your test case query and try again\n"
                + aioobe.getMessage() + " caused by: " + aioobe.getCause());
    } catch (IndexOutOfBoundsException ioobe) {
        logger.info("JSON artifact may be empty - re-running test to prove this out...");
        JSONArray rs = jiraDataFactory.getQueryResponse();

        /*
         * Testing actual JSON for values
         */
        String strRs = new String();
        strRs = rs.toString();

        logger.info("Basic query response: " + strRs);
        assertEquals("There was nothing returned from Jira that is consistent with a valid response.", "[[]]",
                strRs);
    } catch (Exception e) {
        fail("There was an unexpected problem while connecting to Jira during the test\n" + e.getMessage()
                + " caused by: " + e.getCause());
    }
}

From source file:com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImplTest.java

/**
 * Test method for/*from w w  w.  j a v a2 s  .c o  m*/
 * {@link com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImpl#getPagingQueryResponse()}
 * .
 */
@Ignore
@Test
public void testGetPagingQueryResponse() {
    logger.debug("RUNNING TEST FOR PAGING QUERY RESPONSE");
    jiraDataFactory = new JiraDataFactoryImpl(1, properties.getProperty("jira.credentials"),
            properties.getProperty("jira.base.url"), properties.getProperty("jira.query.endpoint"));
    jiraDataFactory.buildBasicQuery(query);
    jiraDataFactory.buildPagingQuery(0);
    try {
        JSONArray rs = jiraDataFactory.getPagingQueryResponse();

        /*
         * Testing actual JSON for values
         */
        JSONArray dataMainArry = new JSONArray();
        JSONObject dataMainObj = new JSONObject();
        dataMainArry = (JSONArray) rs.get(0);
        dataMainObj = (JSONObject) dataMainArry.get(0);

        logger.info("Paging query response: " + dataMainObj.get("fields").toString());
        // fields
        assertTrue("No valid Number was found", dataMainObj.get("fields").toString().length() >= 1);
    } catch (NullPointerException npe) {
        fail("There was a problem with an object used to connect to Jira during the test:\n" + npe.getMessage()
                + " caused by: " + npe.getCause());
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        fail("The object returned from Jira had no JSONObjects in it during the test; try increasing the scope of your test case query and try again.\n"
                + aioobe.getMessage() + " caused by: " + aioobe.getCause());
    } catch (IndexOutOfBoundsException ioobe) {
        logger.info("JSON artifact may be empty - re-running test to prove this out...");

        JSONArray rs = jiraDataFactory.getPagingQueryResponse();

        /*
         * Testing actual JSON for values
         */
        String strRs = new String();
        strRs = rs.toString();

        logger.info("Paging query response: " + strRs);
        assertEquals("There was nothing returned from Jira that is consistent with a valid response.", "[[]]",
                strRs);
    } catch (Exception e) {
        fail("There was an unexpected problem while connecting to Jira during the test:\n" + e.getMessage()
                + " caused by: " + e.getCause());
    }
}

From source file:net.sf.gazpachoquest.rest.auth.TokenStore.java

/**
 * Returns <code>true</code> if the <code>value</code> is a valid secure
 * token as follows://from   w ww  .  j ava 2  s .c om
 * <ul>
 * <li>The string is not <code>null</code></li>
 * <li>The string contains three fields separated by an @ sign</li>
 * <li>The expiry time encoded in the second field has not yet passed</li>
 * <li>The hashing the third field, the expiry time and token number with
 * the secure token (indicated by the token number) gives the same value as
 * contained in the first field</li>
 * </ul>
 * <p>
 * Otherwise the method returns <code>false</code>.
 */
boolean isValid(String value) {
    String[] parts = split(value);
    if (parts != null) {

        // single digit token number
        int tokenNumber = parts[1].charAt(0) - '0';
        if (tokenNumber >= 0 && tokenNumber < currentTokens.length) {

            long cookieTime = Long.parseLong(parts[1].substring(1));
            if (System.currentTimeMillis() < cookieTime) {

                try {
                    SecretKey secretKey = currentTokens[tokenNumber];
                    String hmac = encode(cookieTime, parts[2], tokenNumber, secretKey);
                    return value.equals(hmac);
                } catch (ArrayIndexOutOfBoundsException e) {
                    log.error(e.getMessage(), e);
                } catch (InvalidKeyException e) {
                    log.error(e.getMessage(), e);
                } catch (IllegalStateException e) {
                    log.error(e.getMessage(), e);
                } catch (UnsupportedEncodingException e) {
                    log.error(e.getMessage(), e);
                } catch (NoSuchAlgorithmException e) {
                    log.error(e.getMessage(), e);
                }

                log.error("AuthNCookie value '{}' is invalid", value);

            } else {
                log.error("AuthNCookie value '{}' has expired {}ms ago", value,
                        (System.currentTimeMillis() - cookieTime));
            }

        } else {
            log.error("AuthNCookie value '{}' is invalid: refers to an invalid token number", value,
                    tokenNumber);
        }

    } else {
        log.error("AuthNCookie value '{}' has invalid format", value);
    }

    // failed verification, reason is logged
    return false;
}

From source file:org.openhab.binding.davis.internal.DavisBinding.java

public void sendCommand(DavisCommand command) {
    byte[] responseBlock;
    int offset = 0;

    logger.debug("sendCommand() method is called!");
    DavisCommandType commandType = DavisCommandType.getCommandTypeByCommand(command.getRequestCmd());

    try {/* ww w .  jav a  2s.co  m*/

        //command ber rs232 schicken (inkl '\n'), wait for ACK         
        writeString(command.getRequestCmd() + '\n');

        responseBlock = readResponse();

        switch (commandType.getResponsetype()) {
        case Constants.RESPONSE_TYPE_NONE:
            break;
        case Constants.RESPONSE_TYPE_ACK:
            byte[] resp = new byte[1];
            resp[0] = Constants.ACK;
            expectString(responseBlock, new String(resp));
            offset = 1;
            break;
        case Constants.RESPONSE_TYPE_OK:
            expectString(responseBlock, "\n\rOK\n\r");
            offset = 6;
            break;
        }

        switch (commandType.getResponselimitertype()) {
        case Constants.RESPONSE_LIMITER_TYPE_CRLF:
            if (responseBlock[responseBlock.length - 2] != '\n'
                    || responseBlock[responseBlock.length - 1] != '\r') {
                throw new IOException("expected CRLF at end of response missing");
            }
            break;
        case Constants.RESPONSE_LIMITER_TYPE_FIXED_SIZE:
            if (responseBlock.length - offset != commandType.getResponselength()) {
                throw new IOException("expected length of response: " + commandType.getResponselength()
                        + ", but got: " + (responseBlock.length - offset));
            }
            break;
        case Constants.RESPONSE_LIMITER_TYPE_MULTIPLE_CRLF:
            //TODO add support
            break;
        }

        switch (commandType.getCrcchecktype()) {
        case Constants.CRC_CHECK_TYPE_VAR1:
            if (!CRC16.check(responseBlock, offset, responseBlock.length - offset)) {
                throw new IOException("CRC error");
            }
            break;
        case Constants.CRC_CHECK_TYPE_NONE:
            break;
        }

        try {
            int responseLength = responseBlock.length - offset
                    - (commandType.getCrcchecktype() == Constants.CRC_CHECK_TYPE_VAR1 ? 2 : 0);
            byte[] inputBuf = new byte[responseLength];
            System.arraycopy(responseBlock, offset, inputBuf, 0, responseLength);

            String string = new String(inputBuf);
            logger.debug("parsing: " + escape(string));
            //aus response alle werte dekodieren fr es ein item gibt -> postUpdate
            Set<DavisValueType> valueTypes = DavisValueType.getValueTypesByCommandType(commandType);
            for (DavisValueType valueType : valueTypes) {
                //get items and post Updates for all items with key
                for (DavisBindingProvider provider : providers) {
                    List<String> itemNames = provider.getItemNamesForKey(valueType.getKey());
                    State state = valueType.getDataType().convertToState(inputBuf, valueType);
                    for (String itemName : itemNames) {
                        eventPublisher.postUpdate(itemName, state);
                    }
                }
            }
        } catch (ArrayIndexOutOfBoundsException aie) {
            logger.warn(aie.getMessage());
        }
    } catch (IOException e) {
        logger.warn(e.getMessage());
        resetAfterError();
    }
}