Example usage for java.lang IllegalArgumentException printStackTrace

List of usage examples for java.lang IllegalArgumentException printStackTrace

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:clus.statistic.CombStat.java

/**
 * Checks weather values of a target attribute are significantly different
 * @return/*  w ww.ja v a2  s .c  o m*/
 */
public boolean targetSignDifferent() {
    boolean res = false;
    int att = -1;
    String att_name;
    String att_name2;
    ClusStatistic targetStat = m_StatManager.getStatistic(ClusAttrType.ATTR_USE_TARGET);
    if (targetStat instanceof ClassificationStat) {
        for (int i = 0; i < targetStat.getNbNominalAttributes(); i++) {
            att_name = ((ClassificationStat) targetStat).getAttribute(i).getName();
            for (int j = 0; j < m_ClassStat.getNbNominalAttributes(); j++) {
                att_name2 = m_ClassStat.getAttribute(j).getName();
                if (att_name.equals(att_name2)) {
                    att = j;
                    break;
                }
            }
            if (SignDifferentNom(att)) {
                res = true;
                break; // TODO: If one target att significant, the whole rule significant!?
            }
        }
        // System.out.println("Target sign. testing: " + res);
        return res;
    } else if (targetStat instanceof RegressionStat) {
        for (int i = 0; i < targetStat.getNbNumericAttributes(); i++) {
            att_name = ((RegressionStat) targetStat).getAttribute(i).getName();
            for (int j = 0; j < m_RegStat.getNbNumericAttributes(); j++) {
                att_name2 = m_RegStat.getAttribute(j).getName();
                if (att_name.equals(att_name2)) {
                    att = j;
                    break;
                }
            }
            try {
                if (SignDifferentNum(att)) {
                    res = true;
                    break; // TODO: If one target att significant, the whole rule significant!?
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (MathException e) {
                e.printStackTrace();
            }
        }
        return res;
    } else {
        // TODO: Classification and regression
        return true;
    }
}

From source file:org.mili.core.service.UtilTest.java

@Test
public void testGetFile_MapString() throws Exception {
    Map<String, String> p = new Hashtable<String, String>();
    p.put("File", "./tmp/test.txt");
    // negativ//from   w  w  w . j  av a 2  s.  c  om
    try {
        Util.getFile(null, null);
        fail("Exception awaited !");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    }
    try {
        Util.getFile(p, null);
        fail("Exception awaited !");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    }
    try {
        Util.getFile(p, "");
        fail("Exception awaited !");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    }
    // normal
    try {
        FileUtils.writeStringToFile(new File("./tmp/test.txt"), "lala");
        File f = Util.getFile(p, "File");
        assertTrue(f.exists());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    // with work dir
    try {
        FileUtils.writeStringToFile(new File("./tmp/test.txt"), "lala");
        p.put(Service.P_WORKDIR, "./tmp");
        p.put("File", "./test.txt");
        File f = Util.getFile(p, "File");
        assertTrue(f.exists());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    return;
}

From source file:com.github.akinaru.rfdroid.activity.BtDevicesActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();
    Log.i(TAG, "RFdroidActivity onDestroy");
    //currentService.disconnect(deviceAddress);
    unregisterReceiver(mGattUpdateReceiver);

    try {/*from   w w w .j  a v  a  2 s  .  c  o  m*/
        if (bound) {
            unbindService(mServiceConnection);
            bound = false;
        }
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }
}

From source file:com.example.android.snake.SnakeView.java

public void displayNewPortion() {
    if (mWidth == (MAX_WIDTH - START_WIDTH) && mHeight == (MAX_HEIGHT - START_HEIGHT))
        setMode(WIN);//w  ww . j a  v  a 2  s.  c  o m
    if (!mFirstBlockHit) {
        mFirstBlockHit = true;
        mBackground.setVisibility(View.VISIBLE);
    }

    if (mWidth + WIDTH_INCR <= MAX_WIDTH)
        mWidth += WIDTH_INCR;
    else
        mWidth = MAX_WIDTH - START_WIDTH;
    if (mHeight + HEIGHT_INCR <= MAX_HEIGHT)
        mHeight += HEIGHT_INCR;
    else
        mHeight = MAX_HEIGHT - START_HEIGHT;
    String except;
    try {
        //mBackground.setImageBitmap((mSourceBitmap));
        Bitmap cropped = Bitmap.createBitmap(mSourceBitmap, START_WIDTH, START_HEIGHT, mWidth, mHeight, null,
                false);
        mBackground.setImageBitmap(cropped);
    } catch (java.lang.IllegalArgumentException e) {
        e.printStackTrace();
        except = e.toString();
        return;
    }
}

From source file:com.asp.tranlog.TsvImporterMapper.java

/**
 * Convert a line of TSV text into an HBase table row.
 *///from w w w .j  a  v a 2  s.  c om
@Override
public void map(LongWritable offset, Text value, Context context) throws IOException {

    byte[] lineBytes = value.getBytes();

    // String lineStr = new String(value.getBytes(), 0, value.getLength(),
    // "gb18030");
    // byte[] lineBytes = new Text(lineStr).getBytes();

    int i = 0;
    try {
        ImportTsv.TsvParser.ParsedLine parsed = parser.parse(lineBytes, value.getLength());

        // ImportTsv.TsvParser.ParsedLine parsed = parser.parse(
        // lineBytes, Text.utf8Length(lineStr));

        byte[] rowKeyBytes = createRowkeyByteArray(lineBytes, parsed);
        ImmutableBytesWritable rowKey = new ImmutableBytesWritable(rowKeyBytes);

        Put put = new Put(rowKeyBytes);
        put.setWriteToWAL(false);

        for (i = 0; i < parsed.getColumnCount(); i++) {

            KeyValue kv = null;
            if (columnTypes[i] == ImportTsv.COL_TYPE_STRING) {
                kv = new KeyValue(rowKeyBytes, parser.getFamily(i), parser.getQualifier(i), 0,
                        parser.getQualifier(i).length, ts, KeyValue.Type.Put, lineBytes,
                        parsed.getColumnOffset(i), parsed.getColumnLength(i));
            } else {
                byte[] colBytes = convertColBytes(lineBytes, parsed, i);
                if (colBytes == null)
                    throw new ImportTsv.TsvParser.BadTsvLineException("Failed to get bytes for column " + i);
                kv = new KeyValue(rowKeyBytes, parser.getFamily(i), parser.getQualifier(i), ts, colBytes);
            }
            if (kv == null)
                throw new ImportTsv.TsvParser.BadTsvLineException("Failed to get bytes for column " + i);
            put.add(kv);
        }
        context.write(rowKey, put);
    } catch (ImportTsv.TsvParser.BadTsvLineException badLine) {
        if (skipBadLines) {
            System.err.println("Bad line: " + new String(lineBytes, "gb18030") + ":" + i + "\n");
            LOG.error("Bad line: " + new String(lineBytes, "gb18030") + "," + i);
            incrementBadLineCount(1);
            return;
        } else {
            throw new IOException(badLine);
        }
    } catch (IllegalArgumentException e) {
        if (skipBadLines) {
            System.err.println("Bad line: " + new String(lineBytes, "gb18030") + ":" + i + "\n");
            LOG.error("Bad line: " + new String(lineBytes, "gb18030") + "," + i);
            incrementBadLineCount(1);
            return;
        } else {
            throw new IOException(e);
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.hadoop.hdfs.AvatarShell.java

/**
 * run//ww  w  . ja v  a2s  . c o  m
 */
public int run(String argv[]) throws Exception {
    if (argv.length < 1) {
        printUsage();
        return -1;
    }

    AvatarShellCommand cmd = AvatarShellCommand.parseCommand(argv);
    if (cmd == null) {
        printUsage();
        return -1;
    }

    int exitCode = 0;

    if (conf.get(FSConstants.DFS_FEDERATION_NAMESERVICES) != null && (!cmd.isServiceCommand)
            && (!cmd.isAddressCommand)) {
        printServiceErrorMessage("AvatarShell", conf);
        return -1;
    }

    String serviceName = null;
    if (cmd.isServiceCommand) {
        serviceName = cmd.serviceArgs[0];
    }

    // commands without -{zero|one} prefix
    if (cmd.isWaitTxIdCommand) {
        AvatarZooKeeperClient zk = new AvatarZooKeeperClient(conf, null);
        try {
            processServiceName(serviceName, true);
            waitForLastTxIdNode(zk, originalConf);
        } catch (Exception e) {
            exitCode = -1;
            printError(e);
        } finally {
            zk.shutdown();
        }
        if (exitCode == 0) {
            LOG.info("Primary shutdown was successful!");
        }
        return exitCode;
    }

    if (cmd.isFailoverCommand || cmd.isPrepfailoverCommand) {
        boolean prep = cmd.isPrepfailoverCommand;
        try {
            processServiceName(serviceName, true);
            exitCode = failover(serviceName, prep);
        } catch (Exception e) {
            exitCode = -1;
            printError(e);
        }
        String prefix = prep ? "Prep" : "";
        if (exitCode == 0) {
            LOG.info(prefix + "Failover was successful!");
            if (prep) {
                System.out.println("WARNING: Standby is in pre-failover state! If the failover "
                        + "is not performed, the standby needs to be restarted to "
                        + "continue checkpointing.");
            }
        } else {
            LOG.error(prefix + "Failover failed!");
            if (prep) {
                System.out.println("WARNING: Standby is in bad state! Restart the standby node!");
            }
        }
        return exitCode;
    }

    /////////////////////// direct commands (-zero -one -address)

    String address = cmd.isAddressCommand ? cmd.addressArgs[0] : null;
    String instance = cmd.isZeroCommand ? StartupOption.NODEZERO.getName()
            : (cmd.isOneCommand ? StartupOption.NODEONE.getName() : null);

    if (!processServiceName(serviceName, false)) {
        return -1;
    }

    // remove 0/1 suffix
    if (instance != null) {
        if ((conf = AvatarZKShell.updateConf(instance, originalConf)) == null) {
            printUsage();
            return -1;
        }
    }
    initAvatarRPC(address);

    try {
        if (cmd.isShowAvatarCommand) {
            exitCode = showAvatar();
        } else if (cmd.isSetAvatarCommand) {
            exitCode = setAvatar("primary", contains(cmd.setAvatarArgs, "force"), serviceName, instance);
        } else if (cmd.isIsInitializedCommand) {
            exitCode = isInitialized();
        } else if (cmd.isMetasaveCommand) {
            exitCode = metasave(cmd.metasageArgs[0]);
        } else if (cmd.isSaveNamespaceCommand) {
            exitCode = saveNamespace(cmd.getSaveNamespaceArgs());
        } else if (cmd.isShutdownAvatarCommand) {
            shutdownAvatar(serviceName);
        } else if (cmd.isSafemodeCommand) {
            processSafeMode(cmd.safemodeArgs[0]);
        } else {
            exitCode = -1;
            System.err.println("Unknown command");
            printUsage();
        }
    } catch (IllegalArgumentException arge) {
        exitCode = -1;
        arge.printStackTrace();
        printError(arge);
        printUsage();
    } catch (RemoteException e) {
        //
        // This is a error returned by avatarnode server. Print
        // out the first line of the error mesage, ignore the stack trace.
        exitCode = -1;
        try {
            String[] content;
            content = e.getLocalizedMessage().split("\n");
            System.err.println(content[0]);
        } catch (Exception ex) {
            System.err.println(ex.getLocalizedMessage());
        }
    } catch (IOException e) {
        //
        // IO exception encountered locally.
        // 
        exitCode = -1;
        printError(e);
    } catch (Throwable re) {
        exitCode = -1;
        printError(re);
    } finally {
    }
    if (exitCode == 0) {
        LOG.info("Command was successful!");
    }
    return exitCode;
}

From source file:edu.stevens.cpe.reservior.Reservoir.java

public Reservoir(int neuronCount, NetworkTopology topology, Class<T> clazz) throws ReserviorException {
    startTime = System.nanoTime();
    this.neuronCount = neuronCount;
    this.topology = topology;
    this.neuronClass = clazz;

    try {//from  w w w.j  av a  2  s  . c om

        createNeurons();
        //TODO move me to network
        System.setProperty("org.bushe.swing.event.eventBusClass",
                "org.bushe.swing.event.DiscreteTimeThreadSafeEventService");
        EventServiceLocator.setEventService("DiscreteTimeThreadSafeEventService",
                new DiscreteTimeThreadSafeEventService());
        initConnections();

    } catch (IllegalArgumentException e) {
        throw new ReserviorException(e);
    } catch (SecurityException e) {
        throw new ReserviorException(e);
    } catch (InstantiationException e) {
        throw new ReserviorException(e);
    } catch (IllegalAccessException e) {
        throw new ReserviorException(e);
    } catch (InvocationTargetException e) {
        throw new ReserviorException(e);
    } catch (NoSuchMethodException e) {
        throw new ReserviorException(e);
    } catch (EventServiceExistsException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.denimgroup.threadfix.service.defects.BugzillaDefectTracker.java

/**
 * @param client//from  w ww.  j a  v a 2 s  .c  o m
 * @throws XmlRpcException
 */
private String login(XmlRpcClient client) {

    Map<String, String> loginMap = new HashMap<String, String>();
    loginMap.put("login", this.username);
    loginMap.put("password", this.password);
    loginMap.put("rememberlogin", "Bugzilla_remember");

    Object[] loginArray = new Object[1];
    loginArray[0] = loginMap;

    Object loginResult = null;
    try {
        loginResult = client.execute("User.login", loginArray);
    } catch (XmlRpcException e) {
        if (e.getMessage().contains("The username or password you entered is not valid")) {
            return LOGIN_FAILURE;
        }
        e.printStackTrace();
    } catch (IllegalArgumentException e2) {
        if (e2.getMessage().contains("Host name may not be null")) {
            return BAD_CONFIGURATION;
        } else {
            e2.printStackTrace();
            return BAD_CONFIGURATION;
        }
    }

    if (loginResult == null) {
        return null;
    } else {
        return loginResult.toString();
    }
}

From source file:org.mili.core.graphics.GraphicsUtilTest.java

@Test
public void test_void_writeImage_File_Graphics() {
    // negativ//from w  ww . jav a 2s  . co  m
    try {
        GraphicsUtil.writeImage(null, null);
        fail("here was null given, but method works !");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    } catch (IOException e) {
        assertTrue(true);
    }
    try {
        Image i = GraphicsUtil.readImage(new File(this.dir, "test.jpg"));
        GraphicsUtil.writeImage(new File(this.dir, "/xyz/test.jpg"), i);
        fail("here was directory not exists, but method works !");
    } catch (IOException e) {
        assertTrue(true);
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        GraphicsUtil.writeImage(new File(this.dir, "test.jpg"), null);
        fail("here null given, but method works !");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    } catch (IOException e) {
        assertTrue(true);
    }
    try {
        Image i = GraphicsUtil.readImage(new File(this.dir, "test.jpg"));
        GraphicsUtil.writeImage(null, i);
        fail("here null given, but method works !");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    } catch (IOException e) {
        assertTrue(true);
    }
    // positiv
    try {
        Image i = GraphicsUtil.readImage(new File(this.dir, "test.jpg"));
        GraphicsUtil.writeImage(new File(this.dir, "test_2.jpg"), i);
        assertTrue(true);
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }
    return;
}

From source file:com.denimgroup.threadfix.service.defects.BugzillaDefectTracker.java

/**
 * @param client//www  .ja  v a2 s .  c om
 * @return
 */
@SuppressWarnings("unchecked")
private String getProducts(XmlRpcClient client) {
    String productList = "";

    try {
        Map<String, Object[]> productsMap = (HashMap<String, Object[]>) client
                .execute("Product.get_accessible_products", new Object[] {});
        Object[] ids = productsMap.get("ids");

        StringBuffer buffer = new StringBuffer();

        Map<String, Object[]> params = new HashMap<String, Object[]>();
        params.put("ids", ids);

        Map<String, Object[]> productMap = (HashMap<String, Object[]>) client.execute("Product.get",
                new Object[] { params });
        Object[] products = productMap.get("products");

        for (Object item : products) {
            Map<String, Object> product = (HashMap<String, Object>) item;
            String productName = (String) product.get("name");
            buffer.append(productName).append(',');
        }

        productList = buffer.toString();
        productList = productList.substring(0, productList.length() - 1);
    } catch (XmlRpcException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e2) {
        if (e2.getMessage().contains("Host name may not be null")) {
            return BAD_CONFIGURATION;
        } else {
            e2.printStackTrace();
            return BAD_CONFIGURATION;
        }
    }
    if (productList == "") {
        setLastError("There were problems communicating with the Bugzilla server.");
        return "Authentication failed";
    }

    return productList;
}