Example usage for java.lang RuntimeException printStackTrace

List of usage examples for java.lang RuntimeException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:kilim.tools.Weaver.java

static void weaveFile(String name, InputStream is, Detector detector) throws IOException {
    try {/*from   w  ww  .  j  a  v  a 2 s . com*/
        ClassWeaver cw = new ClassWeaver(is, detector);
        cw.weave();
        writeClasses(cw);
    } catch (KilimException ke) {
        log.error("***** Error weaving " + name + ". " + ke.getMessage());
        // ke.printStackTrace();
        err = 1;
    } catch (RuntimeException re) {
        log.error("***** Error weaving " + name + ". " + re.getMessage());
        re.printStackTrace();
        err = 1;
    } catch (IOException ioe) {
        err = 1;
        log.error("***** Unable to find/process '" + name + "'\n" + ioe.getMessage());
    }
}

From source file:com.openteach.diamond.container.Container.java

private static void fireLifecycleEvent(String eventType) throws Exception {
    for (LifecycleListener listener : lifecycleListeners) {
        try {// w  ww  . j  a  v a  2 s.  co m
            listener.fire(eventType);
        } catch (RuntimeException e) { //runtime?
            e.printStackTrace();
        }
    }
}

From source file:com.taobao.weex.ui.animation.WXAnimationModule.java

public static void startAnimation(WXSDKInstance mWXSDKInstance, WXComponent component,
        @NonNull WXAnimationBean animationBean, @Nullable String callback) {
    if (component == null) {
        return;//from  w  ww . j a v a2s  .  c om
    }
    if (component.getHostView() == null) {
        AnimationHolder holder = new AnimationHolder(animationBean, callback);
        component.postAnimation(holder);
        return;
    }
    try {
        Animator animator = createAnimator(animationBean, component.getHostView(),
                mWXSDKInstance.getViewPortWidth());
        if (animator != null) {
            Animator.AnimatorListener animatorCallback = createAnimatorListener(mWXSDKInstance, callback);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
                component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
            }
            Interpolator interpolator = createTimeInterpolator(animationBean);
            if (animatorCallback != null) {
                animator.addListener(animatorCallback);
            }
            if (interpolator != null) {
                animator.setInterpolator(interpolator);
            }
            animator.setDuration(animationBean.duration);
            animator.start();
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
        WXLogUtils.e("", e);
    }
}

From source file:org.istsms.util.Javabean2JSON.java

private static Object toJavaCalendar(JSONObject jo) {
    if (jo == null)
        return null;
    try {/*  w ww.  j  a v a2 s .com*/
        if (jo.getString("__class").equals(Calendar.class.getCanonicalName())) {
            java.util.Calendar c = java.util.Calendar.getInstance();
            c.setTime(new java.util.Date(Long.parseLong(jo.getString("__value"))));
            c.setTimeZone(java.util.TimeZone.getTimeZone(jo.getString("__timezn")));
            return c;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (RuntimeException r) {
        r.printStackTrace();
    }
    return null;
}

From source file:specminers.referenceparser.graphvizdot.Main.java

public static void performConversion(Map<String, String> options)
        throws IOException, TransformerException, ParserConfigurationException {

    File dotFilesFolder = new File(options.get(PATH_OPTION));
    String[] extensions = new String[] { "dot" };
    boolean directConversion = options.containsKey(DIRECT_CONVERSION_OPTION);
    File outputDir = null;/*w  w  w.  j a  v a2  s . c o m*/

    if (options.containsKey(OUTPUT_OPTION)) {
        outputDir = new File(options.get(OUTPUT_OPTION));
    }

    List<File> specFiles = FileUtils.listFiles(dotFilesFolder, extensions, true).stream()
            .collect(Collectors.toList());

    for (File specFile : specFiles) {
        PradelsDotFilesToJffConverter converter = new PradelsDotFilesToJffConverter(specFile);
        converter.convert();
        File tempFile = File.createTempFile("jflap_", ".jff");

        if (directConversion) {

            try {
                converter.saveToFile(tempFile.getAbsolutePath());
                JffToRegexConverter regexGen = new JffToRegexConverter(tempFile);
                String classSpec = regexGen.getRegularExpression();

                if (outputDir != null && outputDir.exists()) {
                    File regexSpecFile;
                    regexSpecFile = java.nio.file.Paths.get(outputDir.getAbsolutePath(),
                            specFile.getName().replace(".dot", "") + "_regex.txt").toFile();
                    FileUtils.writeStringToFile(regexSpecFile, classSpec);
                } else {
                    System.out.println("Specification for file " + specFile.getName());
                    System.out.println(classSpec);
                }
            } catch (RuntimeException exception) {
                System.err.println("The automaton corresponding to the file " + specFile.getPath()
                        + " seems to have some problems, like the lack of initial or final states, or multiple final states. Check this before trying to convert this file. Error message sent by the converter "
                        + exception);
                exception.printStackTrace();
            } catch (OutOfMemoryError t) {
                System.err.println("The automaton corresponding to the file " + specFile.getPath()
                        + " seems to have some problems, like the lack of initial or final states, or multiple final states. Check this before trying to convert this file. Error message sent by the converter "
                        + t);
                t.printStackTrace();
            }
        } else {
            // Just want to save the jflap files
            if (outputDir != null && outputDir.exists()) {
                File jffFile;
                jffFile = java.nio.file.Paths.get(outputDir.getAbsolutePath(),
                        specFile.getName().replace(".dot", "") + "_jflap_automaton.jff").toFile();
                converter.saveToFile(jffFile.getAbsolutePath());
            } else {
                System.out.println("JFlap file for dot file " + specFile.getName());
                System.out.println(converter.getAsJffFormat());
            }
        }
    }
}

From source file:com.xlythe.engine.theme.Theme.java

/**
 * Gets android theme from theme apk. Can be 0 (no theme).
 *///from   w w  w . ja v  a 2s  . c o m
public static int getTheme(Context context) {
    int id = getId(context, "string", "app_theme");
    if (id == 0) {
        return 0;
    }

    String fieldName = getResources(context).getString(id).replace(".", "_");
    try {
        Field field = android.R.style.class.getField(fieldName);
        return field.getInt(null);
    } catch (RuntimeException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    return 0;
}

From source file:com.xlythe.engine.theme.Theme.java

/**
 * Gets android theme from theme apk. Can be 0 (no theme). This is for apps that want an
 * actionbar in their Settings but not in their main app.
 *//*  w  w w.  j av a  2  s  .co  m*/
public static int getSettingsTheme(Context context) {
    int id = getId(context, "string", "app_settings_theme");
    if (id == 0) {
        return 0;
    }

    String fieldName = getResources(context).getString(id).replace(".", "_");
    try {
        Field field = android.R.style.class.getField(fieldName);
        return field.getInt(null);
    } catch (RuntimeException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    return 0;
}

From source file:com.ricemap.spateDB.operations.Sampler.java

/**
 * Sample a ratio of the file through a MapReduce job
 * @param fs// w  ww .  j  a  v  a  2  s .  c om
 * @param files
 * @param ratio
 * @param threshold - Maximum number of elements to be sampled
 * @param output
 * @param inObj
 * @return
 * @throws IOException
 */
public static <T extends TextSerializable, O extends TextSerializable> int sampleMapReduceWithRatio(
        FileSystem fs, Path[] files, double ratio, long threshold, long seed, final ResultCollector<O> output,
        T inObj, O outObj) throws IOException {
    JobConf job = new JobConf(FileMBR.class);

    Path outputPath;
    FileSystem outFs = FileSystem.get(job);
    do {
        outputPath = new Path(files[0].toUri().getPath() + ".sample_" + (int) (Math.random() * 1000000));
    } while (outFs.exists(outputPath));

    job.setJobName("Sample");
    job.setMapOutputKeyClass(NullWritable.class);
    job.setMapOutputValueClass(Text.class);
    job.setClass(InClass, inObj.getClass(), TextSerializable.class);
    job.setClass(OutClass, outObj.getClass(), TextSerializable.class);

    job.setMapperClass(Map.class);
    job.setLong(RANDOM_SEED, seed);
    job.setFloat(SAMPLE_RATIO, (float) ratio);

    ClusterStatus clusterStatus = new JobClient(job).getClusterStatus();
    job.setNumMapTasks(clusterStatus.getMaxMapTasks() * 5);
    job.setNumReduceTasks(0);

    job.setInputFormat(ShapeLineInputFormat.class);
    job.setOutputFormat(TextOutputFormat.class);

    ShapeLineInputFormat.setInputPaths(job, files);
    TextOutputFormat.setOutputPath(job, outputPath);

    // Submit the job
    RunningJob run_job = JobClient.runJob(job);

    Counters counters = run_job.getCounters();
    Counter outputRecordCounter = counters.findCounter(Task.Counter.MAP_OUTPUT_RECORDS);
    final long resultCount = outputRecordCounter.getValue();

    Counter inputBytesCounter = counters.findCounter(Task.Counter.MAP_INPUT_BYTES);
    Sampler.sizeOfLastProcessedFile = inputBytesCounter.getValue();

    // Ratio of records to return from output based on the threshold
    // Note that any number greater than or equal to one will cause all
    // elements to be returned
    final double selectRatio = (double) threshold / resultCount;

    // Read job result
    int result_size = 0;
    if (output != null) {
        Text line = new Text();
        FileStatus[] results = outFs.listStatus(outputPath);

        for (FileStatus fileStatus : results) {
            if (fileStatus.getLen() > 0 && fileStatus.getPath().getName().startsWith("part-")) {
                LineReader lineReader = new LineReader(outFs.open(fileStatus.getPath()));
                try {
                    while (lineReader.readLine(line) > 0) {
                        if (Math.random() < selectRatio) {
                            if (output != null) {
                                outObj.fromText(line);
                                output.collect(outObj);
                            }
                            result_size++;
                        }
                    }
                } catch (RuntimeException e) {
                    e.printStackTrace();
                }
                lineReader.close();
            }
        }
    }

    outFs.delete(outputPath, true);

    return result_size;
}

From source file:org.apache.hadoop.hbase.HBaseTestCase.java

/**
 * Add content to region <code>r</code> on the passed column
 * <code>column</code>.//from   w w  w  .  j  a v  a 2 s .c  o  m
 * Adds data of the from 'aaa', 'aab', etc where key and value are the same.
 * @param updater  An instance of {@link Incommon}.
 * @param column
 * @param startKeyBytes Where to start the rows inserted
 * @param endKey Where to stop inserting rows.
 * @param ts Timestamp to write the content with.
 * @param writeToWAL
 * @return count of what we added.
 * @throws IOException
 */
public static long addContent(final Incommon updater, final String columnFamily, final String column,
        final byte[] startKeyBytes, final byte[] endKey, final long ts) throws IOException {
    long count = 0;
    // Add rows of three characters.  The first character starts with the
    // 'a' character and runs up to 'z'.  Per first character, we run the
    // second character over same range.  And same for the third so rows
    // (and values) look like this: 'aaa', 'aab', 'aac', etc.
    char secondCharStart = (char) startKeyBytes[1];
    char thirdCharStart = (char) startKeyBytes[2];
    EXIT: for (char c = (char) startKeyBytes[0]; c <= LAST_CHAR; c++) {
        for (char d = secondCharStart; d <= LAST_CHAR; d++) {
            for (char e = thirdCharStart; e <= LAST_CHAR; e++) {
                byte[] t = new byte[] { (byte) c, (byte) d, (byte) e };
                if (endKey != null && endKey.length > 0 && Bytes.compareTo(endKey, t) <= 0) {
                    break EXIT;
                }
                try {
                    Put put;
                    if (ts != -1) {
                        put = new Put(t, ts);
                    } else {
                        put = new Put(t);
                    }
                    try {
                        StringBuilder sb = new StringBuilder();
                        if (column != null && column.contains(":")) {
                            sb.append(column);
                        } else {
                            if (columnFamily != null) {
                                sb.append(columnFamily);
                                if (!columnFamily.endsWith(":")) {
                                    sb.append(":");
                                }
                                if (column != null) {
                                    sb.append(column);
                                }
                            }
                        }
                        byte[][] split = KeyValue.parseColumn(Bytes.toBytes(sb.toString()));
                        if (split.length == 1) {
                            put.add(split[0], new byte[0], t);
                        } else {
                            put.add(split[0], split[1], t);
                        }
                        put.setDurability(Durability.SKIP_WAL);
                        updater.put(put);
                        count++;
                    } catch (RuntimeException ex) {
                        ex.printStackTrace();
                        throw ex;
                    } catch (IOException ex) {
                        ex.printStackTrace();
                        throw ex;
                    }
                } catch (RuntimeException ex) {
                    ex.printStackTrace();
                    throw ex;
                } catch (IOException ex) {
                    ex.printStackTrace();
                    throw ex;
                }
            }
            // Set start character back to FIRST_CHAR after we've done first loop.
            thirdCharStart = FIRST_CHAR;
        }
        secondCharStart = FIRST_CHAR;
    }
    return count;
}

From source file:sh.isaac.api.LookupService.java

/**
 * Gets the.// w  ww.ja  va  2 s .  c  o m
 *
 * @return the {@link ServiceLocator} that is managing this ISAAC instance
 */
public static ServiceLocator get() {
    if (looker == null) {
        synchronized (STARTUP_LOCK) {
            if (looker == null) {
                startupFxPlatform();

                final ArrayList<String> packagesToSearch = new ArrayList<>(
                        Arrays.asList("sh", "one", "org.ihtsdo", "org.glassfish", "com.informatics"));
                final boolean readInhabitantFiles = Boolean
                        .valueOf(System.getProperty(Constants.READ_INHABITANT_FILES, "false"));

                if (System.getProperty(Constants.EXTRA_PACKAGES_TO_SEARCH) != null) {
                    final String[] extraPackagesToSearch = System
                            .getProperty(Constants.EXTRA_PACKAGES_TO_SEARCH).split(";");

                    packagesToSearch.addAll(Arrays.asList(extraPackagesToSearch));
                }

                try {
                    final String[] packages = packagesToSearch.toArray(new String[] {});

                    LOG.info("Looking for HK2 annotations "
                            + (readInhabitantFiles ? "from inhabitant files" : "skipping inhabitant files")
                            + "; and scanning in the packages: " + Arrays.toString(packages));

                    final ServiceLocator temp = HK2RuntimeInitializer.init("ISAAC", readInhabitantFiles,
                            packages);

                    if (looker != null) {
                        final RuntimeException e = new RuntimeException(
                                "RECURSIVE Lookup Service Reference!  Ensure that there are no static variables "
                                        + "objects utilizing the LookupService during their init!");

                        e.printStackTrace();
                        throw e;
                    }

                    looker = temp;
                    LOG.info("HK2 initialized.  Identifed " + looker.getAllServiceHandles((criteria) -> {
                        return true;
                    }).size() + " services");
                } catch (IOException | ClassNotFoundException | MultiException e) {
                    throw new RuntimeException(e);
                }

                try {
                    LookupService.startupWorkExecutors();
                } catch (final Exception e) {
                    final RuntimeException ex = new RuntimeException(
                            "Unexpected error trying to come up to the work executors level, possible classpath problems!",
                            e);

                    ex.printStackTrace(); // We are in a world of hurt if this happens, make sure this exception makes it out somewhere, and doesn't get eaten.
                    throw ex;
                }
            }
        }
    }

    return looker;
}