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:com.xhsoft.framework.common.utils.ClassUtil.java

/**
 * /*from   ww w  .  ja v a2 s .  co m*/
 * @return - String
 * @author: lizj
 */
public static String getCallerName(int depth) {
    String JDK_VERSION = System.getProperty("java.version");

    double version = 1.3D;

    try {
        JDK_VERSION = JDK_VERSION.substring(0, 3);

        version = Double.parseDouble(JDK_VERSION);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    if (DEBUG) {
        log.debug("java.version: " + version);
    }

    if (version >= 1.5D) {
        try {
            Thread currentThread = Thread.currentThread();

            StackTraceElement[] stack = (StackTraceElement[]) (Thread.class
                    .getMethod("getStackTrace", new Class[0]).invoke(currentThread, new Object[0]));

            if (stack != null && stack.length >= 3) {
                for (int i = 0; i < stack.length; i++) {
                    if (stack[i].getClassName().equals(ClassUtil.class.getName())
                            && "getCallerName".equals(stack[i].getMethodName())) {
                        if (i + 2 + depth < stack.length) {
                            return stack[i + 2 + depth].getClassName() + "."
                                    + stack[i + 2 + depth].getMethodName();
                        }
                    }
                }

                return null;
            }
        } catch (IllegalArgumentException e1) {
            e1.printStackTrace();
        } catch (SecurityException e1) {
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } catch (InvocationTargetException e1) {
            e1.printStackTrace();
        } catch (NoSuchMethodException e1) {
            e1.printStackTrace();
        }
    } else if (version >= 1.4D) {
        StackTraceElement[] stack = (new Throwable()).getStackTrace();

        if (stack != null && stack.length >= (3 + depth)) {
            return stack[2 + depth].getClassName() + "." + stack[2 + depth].getMethodName();
        }
    }

    java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream(4096);

    new Throwable().printStackTrace(new java.io.PrintStream(bos));

    String x = bos.toString();

    java.io.BufferedReader br = new java.io.BufferedReader(new java.io.StringReader(x));

    String val = null;
    String str = null;

    try {
        int i = 0;

        while ((str = br.readLine()) != null) {
            if (i++ == (3 + depth)) {
                str = StringUtil.getA5(str, "at ");

                val = str = StringUtil.getB4(str, "(");
            }
        }
    } catch (IOException e) {
    }

    return val;
}

From source file:com.ibm.soatf.component.osb.ServiceManager.java

public static boolean changeServiceStatus(String servicetype, boolean status, String serviceURI, String host,
        int port, String username, String password) throws FrameworkExecutionException {

    SessionManagementMBean sm = null;/* ww  w .  java2  s.co m*/
    JMXConnector conn = null;
    boolean result = true;
    String statusMsg = "";
    try {
        conn = initConnection(host, port, username, password);
        MBeanServerConnection mbconn = conn.getMBeanServerConnection();
        DomainRuntimeServiceMBean clusterService = (DomainRuntimeServiceMBean) MBeanServerInvocationHandler
                .newProxyInstance(mbconn, new ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME));
        sm = (SessionManagementMBean) clusterService.findService(SessionManagementMBean.NAME,
                SessionManagementMBean.TYPE, null);
        sm.createSession(SESSION_NAME);
        ALSBConfigurationMBean alsbSession = (ALSBConfigurationMBean) clusterService.findService(
                ALSBConfigurationMBean.NAME + "." + SESSION_NAME, ALSBConfigurationMBean.TYPE, null);

        if (servicetype.equals("ProxyService")) {
            Ref ref = constructRef("ProxyService", serviceURI);
            ProxyServiceConfigurationMBean proxyConfigMBean = (ProxyServiceConfigurationMBean) clusterService
                    .findService(ProxyServiceConfigurationMBean.NAME + "." + SESSION_NAME,
                            ProxyServiceConfigurationMBean.TYPE, null);
            if (status) {
                proxyConfigMBean.enableService(ref);
                statusMsg = "Enable the ProxyService : " + serviceURI;
                logger.info(statusMsg);
            } else {
                proxyConfigMBean.disableService(ref);
                statusMsg = "Disable the ProxyService : " + serviceURI;
                logger.info(statusMsg);
            }
        } else if (servicetype.equals("BusinessService")) {
            try {
                Ref ref = constructRef("BusinessService", serviceURI);
                BusinessServiceConfigurationMBean businessConfigMBean = (BusinessServiceConfigurationMBean) clusterService
                        .findService(BusinessServiceConfigurationMBean.NAME + "." + SESSION_NAME,
                                BusinessServiceConfigurationMBean.TYPE, null);
                if (status) {
                    businessConfigMBean.enableService(ref);
                    statusMsg = "Enable the BusinessService : " + serviceURI;
                    logger.info(statusMsg);
                } else {
                    businessConfigMBean.disableService(ref);
                    statusMsg = "Disable the BusinessService : " + serviceURI;
                    logger.info(statusMsg);
                }
            } catch (IllegalArgumentException ex) {
                logger.fatal(ExceptionUtils.getStackTrace(ex));
            }
        }
        sm.activateSession(SESSION_NAME, statusMsg);
        conn.close();
    } catch (Exception ex) {
        if (null != sm) {
            try {
                sm.discardSession(SESSION_NAME);
            } catch (Exception e) {
                logger.debug("Not able to discard the session. " + e.getLocalizedMessage());
                throw new FrameworkExecutionException(e);
            }
        }
        result = false;
        logger.error("Error in MBean Server connection. " + ex.getLocalizedMessage());
        ex.printStackTrace();
    } finally {
        if (null != conn) {
            try {
                conn.close();
            } catch (Exception e) {
                logger.debug("Not able to close the JMX connection. " + e.getLocalizedMessage());
                throw new FrameworkExecutionException(e);

            }
        }
    }

    return result;
}

From source file:com.sshtools.j2ssh.authentication.UserGridCredential.java

private static GSSCredential saslProxy(SshConnectionProperties properties, String password, int lengthHours)
        throws IOException {
    String hostname_k = DEFAULT_MYPROXY_SERVER_K;
    hostname_k = PreferencesStore.get(SshTerminalPanel.PREF_KRB5_MYPROXY_HOSTNAME, hostname_k);
    String username = System.getProperty("user.name");
    String realm = System.getenv("USERDNSDOMAIN");
    String kdc = System.getenv("USERDNSDOMAIN");
    String port_S = DEFAULT_MYPROXY_PORT_K;
    boolean use = true;
    if (properties != null) {
        if (!(properties instanceof SshToolsConnectionProfile))
            return null;
        SshToolsConnectionProfile profile = (SshToolsConnectionProfile) properties;
        hostname_k = profile.getApplicationProperty(SshTerminalPanel.PREF_KRB5_MYPROXY_HOSTNAME, hostname_k);
        username = profile.getApplicationProperty(SshTerminalPanel.PREF_KRB5_MYPROXY_USERNAME, username);
        realm = profile.getApplicationProperty(SshTerminalPanel.PREF_KRB5_MYPROXY_REALM, realm);
        kdc = profile.getApplicationProperty(SshTerminalPanel.PREF_KRB5_MYPROXY_KDC, kdc);
        use = profile.getApplicationPropertyBoolean(SshTerminalPanel.PREF_KRB5_MYPROXY_USE, use);
    }//from  w w  w . j av a  2 s.com
    use = use && SshTerminalPanel.PREF_KRB5_MYPROXY_ENABLED; // was support compiled in?
    if (!use)
        return null;

    port_S = PreferencesStore.get(SshTerminalPanel.PREF_KRB5_MYPROXY_PORT, port_S);
    int port = 7513;
    try {
        port = Integer.parseInt(port_S);
    } catch (NumberFormatException e) {
        log.warn("Could not parse the port number from defaults file (property name"
                + SshTerminalPanel.PREF_KRB5_MYPROXY_PORT + ", property value= " + port_S + ").");
    }
    GSSCredential gsscredential = null;
    CoGProperties cogproperties = CoGProperties.getDefault();
    CertUtil.init();
    MyProxy myproxy = new MyProxy(hostname_k, port);
    try {
        SASLParams params = null;
        if (password != null) {
            params = new SASLParams(username, password);
        } else {
            params = new SASLParams(username);
        }
        params.setRealm(realm);
        params.setLifetime(lengthHours * 3600);
        params.setKDC(kdc);
        gsscredential = myproxy.getSASL(null, params);
        if (SAVE_MYPROXY_PROXY) {
            GlobusCredential proxy = ((GlobusGSSCredentialImpl) gsscredential).getGlobusCredential();
            ProxyHelper.saveProxy(proxy, properties);
        }
        log.debug("A proxy has been received for user " + username);
    } catch (IllegalArgumentException exception) {
        exception.printStackTrace();
        StringWriter stringwriter = new StringWriter();
        exception.printStackTrace(new PrintWriter(stringwriter));
        log.debug(stringwriter);
        myProxyPrompt.setError("MyProxy: " + exception.getMessage());
        ;
    } catch (Exception exception) {
        exception.printStackTrace();
        StringWriter stringwriter = new StringWriter();
        exception.printStackTrace(new PrintWriter(stringwriter));
        log.debug(stringwriter);
    }
    return gsscredential;
}

From source file:net.easymfne.displayframes.Localization.java

/**
 * Attempt to load a selected locale file by name. If the file cannot be
 * read, fall back to default 'en_US' locale. If that file also cannot be
 * read, use a blank locale (thus all display names come from Bukkit).
 * //w  w  w  . jav  a  2s .  c o  m
 * @param plugin
 *            DisplayFrames plugin instance
 * @param localeName
 *            Name of desired locale
 */
protected static void load(DisplayFrames plugin, String localeName) {
    locale = new YamlConfiguration();
    File localeFile = new File(
            plugin.getDataFolder().getAbsolutePath() + LOCALE_FOLDER + localeName + LOCALE_EXTENSION);
    if (!localeFile.exists()) {
        try {
            plugin.saveResource("locale/" + localeName + LOCALE_EXTENSION, false);
        } catch (IllegalArgumentException e) {
            plugin.fancyLog(Level.WARNING, "Locale '" + localeName + "' is not included with this plugin.");
        }
    }
    try {
        locale.load(localeFile);
        plugin.fancyLog("Loaded strings from: " + localeName);
        return;
    } catch (FileNotFoundException e) {
        plugin.fancyLog(Level.WARNING, "Locale file not found for: " + localeName);
    } catch (IOException e) {
        plugin.fancyLog(Level.WARNING, "Locale file readable for: " + localeName);
    } catch (InvalidConfigurationException e) {
        plugin.fancyLog(Level.WARNING, "Locale file has syntax errors: " + localeName);
        e.printStackTrace();
    }
    plugin.fancyLog(Level.WARNING, "Falling back to Bukkit names");
}

From source file:de.geeksfactory.opacclient.apis.Zones.java

static List<LentItem> parseMediaList(Document doc) {
    List<LentItem> lent = new ArrayList<>();

    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd/MM/yyyy").withLocale(Locale.GERMAN);
    Pattern id_pat = Pattern.compile("javascript:renewItem\\('[0-9]+','(.*)'\\)");
    Pattern cannotrenew_pat = Pattern.compile("javascript:CannotRenewLoan\\('[0-9]+','(.*)','[0-9]+'\\)");

    for (Element table : doc
            .select(".LoansBrowseItemDetailsCellStripe table, " + ".LoansBrowseItemDetailsCell " + "table")) {
        LentItem item = new LentItem();

        for (Element tr : table.select("tr")) {
            String desc = tr.select(".LoanBrowseFieldNameCell").text().trim();
            String value = tr.select(".LoanBrowseFieldDataCell").text().trim();
            if (desc.equals("Titel")) {
                item.setTitle(value);/*from  w  w w .  j av  a  2  s  .  c  o  m*/
                if (tr.select(".LoanBrowseFieldDataCell a[href]").size() > 0) {
                    String href = tr.select(".LoanBrowseFieldDataCell a[href]").attr("href");
                    Map<String, String> params = getQueryParamsFirst(href);
                    if (params.containsKey("BACNO")) {
                        item.setId(params.get("BACNO"));
                    }
                }
            }
            if (desc.equals("Verfasser"))
                item.setAuthor(value);
            if (desc.equals("Mediennummer"))
                item.setBarcode(value);
            if (desc.equals("ausgeliehen in"))
                item.setHomeBranch(value);
            if (desc.matches("F.+lligkeits.*datum")) {
                value = value.split(" ")[0];
                try {
                    item.setDeadline(fmt.parseLocalDate(value));
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
            }
        }
        if (table.select(".button[Title~=Zum]").size() == 1) {
            Matcher matcher1 = id_pat.matcher(table.select(".button[Title~=Zum]").attr("href"));
            if (matcher1.matches())
                item.setProlongData(matcher1.group(1));
        } else if (table.select(".CannotRenewLink").size() == 1) {
            Matcher matcher = cannotrenew_pat.matcher(table.select(".CannotRenewLink").attr("href").trim());
            if (matcher.matches()) {
                item.setProlongData("cannotrenew|" + matcher.group(1));
            }
            item.setRenewable(false);
        }
        lent.add(item);
    }
    return lent;
}

From source file:com.zhongsou.souyue.ui.gallery.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    try {/*ww  w.  jav  a  2 s.c  om*/
        return super.onInterceptTouchEvent(event);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return false;
    } catch (ArrayIndexOutOfBoundsException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:com.cleanwiz.applock.files.widget.HackyViewPager.java

/**
 *  IllegalArgumentException /*from  ww w . j a  v a 2  s .  c  o m*/
 *
 * @param ev
 * @return
 */
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    try {
        return super.onInterceptTouchEvent(ev);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.kalypso.ogc.sensor.timeseries.TimeseriesUtils.java

/**
 * Returns a new instance of DateRangeArgument containing the beginning and the end of the forecast, given the
 * observation is a forecast.//www. j  a va 2  s .com
 * <p>
 * An observation is a forecast when it has the MD_VORHERSAGE Metadata.
 *
 * @param obs
 * @return date range of the forecast or null if obs isn't a forecast.
 */
public static DateRange isTargetForecast(final IObservation obs) {
    if (obs == null)
        return null;

    final MetadataList mdl = obs.getMetadataList();

    final String forecastFrom = mdl.getProperty(ITimeseriesConstants.MD_VORHERSAGE_START);
    final String forecastTo = mdl.getProperty(ITimeseriesConstants.MD_VORHERSAGE_ENDE);
    if (forecastFrom != null || forecastTo != null) {
        // new version: if one of the two is set, we assume that the zml is in new format
        final Date from = forecastFrom == null ? null : DateUtilities.parseDateTime(forecastFrom);
        final Date to = forecastTo == null ? null : DateUtilities.parseDateTime(forecastTo);
        return new DateRange(from, to);
    }

    // Backwards compability: still try to parse old 'Vorhersage' metadata
    final String range = mdl.getProperty(ITimeseriesConstants.MD_VORHERSAGE);
    if (range != null) {
        final String[] splits = range.split(";"); //$NON-NLS-1$
        if (splits.length == 2) {
            final String fromStr = splits[0];
            final String toStr = splits[1];

            try {
                final Date from = DateUtilities.parseDateTime(fromStr);
                final Date to = DateUtilities.parseDateTime(toStr);
                return new DateRange(from, to);
            } catch (final IllegalArgumentException e) {
                // ignore, probably it is an old zml
            }

            // TRICKY: in order to support backwards compatibility, we still try to parse the old format
            try {
                final Date from = FORECAST_DF.parse(fromStr);
                final Date to = FORECAST_DF.parse(toStr);
                return new DateRange(from, to);
            } catch (final ParseException e) {
                e.printStackTrace();
            }
        }
    }

    return null;
}

From source file:com.ericsun.duom.Widget.zoom.ViewPagerFixed.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    try {/*  w  w  w.  j av  a  2s.c  o m*/
        return super.onInterceptTouchEvent(ev);
    } catch (IllegalArgumentException ex) {
        ex.printStackTrace();
    }
    return false;
}

From source file:net.reichholf.dreamdroid.widget.DrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    try {//from  w  w w.ja  v  a 2s .  com
        return super.onInterceptTouchEvent(ev);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return false;
    } catch (ArrayIndexOutOfBoundsException e) {
        e.printStackTrace();
        return false;
    }
}