public PackagingDataCalculator getPackagingDataCalculator() { // if original instance (non-deserialized), and packagingDataCalculator // is not already initialized, then create an instance. // here we assume that (throwable == null) for deserialized instances if (throwable != null && packagingDataCalculator == null) { packagingDataCalculator = new PackagingDataCalculator(); } return packagingDataCalculator; }
private ClassPackagingData computeBySTEP(StackTraceElementProxy step, ClassLoader lastExactClassLoader) { String className = step.ste.getClassName(); ClassPackagingData cpd = cache.get(className); if (cpd != null) { return cpd; } Class type = bestEffortLoadClass(lastExactClassLoader, className); String version = getImplementationVersion(type); String codeLocation = getCodeLocation(type); cpd = new ClassPackagingData(codeLocation, version, false); cache.put(className, cpd); return cpd; }
public void calculatePackagingData() { if (calculatedPackageData) { return; } PackagingDataCalculator pdc = this.getPackagingDataCalculator(); if (pdc != null) { calculatedPackageData = true; pdc.calculate(this); } }
private ClassPackagingData calculateByExactType(Class type) { String className = type.getName(); ClassPackagingData cpd = cache.get(className); if (cpd != null) { return cpd; } String version = getImplementationVersion(type); String codeLocation = getCodeLocation(type); cpd = new ClassPackagingData(codeLocation, version); cache.put(className, cpd); return cpd; }
firsExactClassLoader = lastExactClassLoader; ClassPackagingData pi = calculateByExactType(callerClass); step.setClassPackagingData(pi); } else { missfireCount++; ClassPackagingData pi = computeBySTEP(step, lastExactClassLoader); step.setClassPackagingData(pi); populateUncommonFrames(commonFrames, stepArray, firsExactClassLoader);
public void calculate(IThrowableProxy tp) { while (tp != null) { populateFrames(tp.getStackTraceElementProxyArray()); IThrowableProxy[] suppressed = tp.getSuppressed(); if (suppressed != null) { for (IThrowableProxy current : suppressed) { populateFrames(current.getStackTraceElementProxyArray()); } } tp = tp.getCause(); } }
void populateUncommonFrames(int commonFrames, StackTraceElementProxy[] stepArray, ClassLoader firstExactClassLoader) { int uncommonFrames = stepArray.length - commonFrames; for (int i = 0; i < uncommonFrames; i++) { StackTraceElementProxy step = stepArray[i]; ClassPackagingData pi = computeBySTEP(step, firstExactClassLoader); step.setClassPackagingData(pi); } }
/** * @param lastGuaranteedClassLoader may be null * @param className * @return */ private Class bestEffortLoadClass(ClassLoader lastGuaranteedClassLoader, String className) { Class result = loadClass(lastGuaranteedClassLoader, className); if (result != null) { return result; } ClassLoader tccl = Thread.currentThread().getContextClassLoader(); if (tccl != lastGuaranteedClassLoader) { result = loadClass(tccl, className); } if (result != null) { return result; } try { return Class.forName(className); } catch (ClassNotFoundException e1) { return null; } catch (NoClassDefFoundError e1) { return null; } catch (Exception e) { e.printStackTrace(); // this is unexpected return null; } }
String getCodeLocation(Class type) { try { if (type != null) { // file:/C:/java/maven-2.0.8/repo/com/icegreen/greenmail/1.3/greenmail-1.3.jar CodeSource codeSource = type.getProtectionDomain().getCodeSource(); if (codeSource != null) { URL resource = codeSource.getLocation(); if (resource != null) { String locationStr = resource.toString(); // now lets remove all but the file name String result = getCodeLocation(locationStr, '/'); if (result != null) { return result; } return getCodeLocation(locationStr, '\\'); } } } } catch (Exception e) { // ignore } return "na"; }
private void populateFrames(StackTraceElementProxy[] stepArray) { // in the initial part of this method we populate package information for // common stack frames final Throwable t = new Throwable("local stack reference"); final StackTraceElement[] localteSTEArray = t.getStackTrace(); final int commonFrames = STEUtil.findNumberOfCommonFrames(localteSTEArray, stepArray); final int stepFirstCommon = stepArray.length - commonFrames; ClassLoader lastExactClassLoader = null; ClassLoader firsExactClassLoader = null; for (int i = 0; i < commonFrames; i++) { StackTraceElementProxy step = stepArray[stepFirstCommon + i]; ClassPackagingData pi = computeBySTEP(step, lastExactClassLoader); step.setClassPackagingData(pi); } populateUncommonFrames(commonFrames, stepArray, firsExactClassLoader); }
private void nesting() { throwable = new Throwable("x"); throwableProxy = new ThrowableProxy(throwable); PackagingDataCalculator pdc = new PackagingDataCalculator(); pdc.calculate(throwableProxy); }
private ClassPackagingData computeBySTEP(StackTraceElementProxy step, ClassLoader lastExactClassLoader) { String className = step.ste.getClassName(); ClassPackagingData cpd = cache.get(className); if (cpd != null) { return cpd; } Class type = bestEffortLoadClass(lastExactClassLoader, className); return makePackagingFromType(type, className); }
firsExactClassLoader = lastExactClassLoader; ClassPackagingData pi = calculateByExactType(callerClass); step.setClassPackagingData(pi); } else { missfireCount++; ClassPackagingData pi = computeBySTEP(step, lastExactClassLoader); step.setClassPackagingData(pi); populateUncommonFrames(commonFrames, stepArray, firsExactClassLoader);
private ClassPackagingData calculateByExactType(Class type) { String className = type.getName(); ClassPackagingData cpd = cache.get(className); if (cpd != null) { return cpd; } String version = getImplementationVersion(type); String codeLocation = getCodeLocation(type); cpd = new ClassPackagingData(codeLocation, version); cache.put(className, cpd); return cpd; }
public void calculate(IThrowableProxy tp) { while (tp != null) { populateFrames(tp.getStackTraceElementProxyArray()); IThrowableProxy[] suppressed = tp.getSuppressed(); if(suppressed != null) { for(IThrowableProxy current:suppressed) { populateFrames(current.getStackTraceElementProxyArray()); } } tp = tp.getCause(); } }
void populateUncommonFrames(int commonFrames, StackTraceElementProxy[] stepArray, ClassLoader firstExactClassLoader) { int uncommonFrames = stepArray.length - commonFrames; for (int i = 0; i < uncommonFrames; i++) { StackTraceElementProxy step = stepArray[i]; ClassPackagingData pi = computeBySTEP(step, firstExactClassLoader); step.setClassPackagingData(pi); } }
/** * @param lastGuaranteedClassLoader may be null * @param className * @return */ private Class bestEffortLoadClass(ClassLoader lastGuaranteedClassLoader, String className) { Class result = loadClass(lastGuaranteedClassLoader, className); if (result != null) { return result; } ClassLoader tccl = Thread.currentThread().getContextClassLoader(); if (tccl != lastGuaranteedClassLoader) { result = loadClass(tccl, className); } if (result != null) { return result; } try { return Class.forName(className); } catch (ClassNotFoundException e1) { return null; } catch (NoClassDefFoundError e1) { return null; } catch (Exception e) { e.printStackTrace(); // this is unexpected return null; } }
String getCodeLocation(Class type) { try { if (type != null) { // file:/C:/java/maven-2.0.8/repo/com/icegreen/greenmail/1.3/greenmail-1.3.jar CodeSource codeSource = type.getProtectionDomain().getCodeSource(); if (codeSource != null) { URL resource = codeSource.getLocation(); if (resource != null) { String locationStr = resource.toString(); // now lets remove all but the file name String result = getCodeLocation(locationStr, '/'); if (result != null) { return result; } return getCodeLocation(locationStr, '\\'); } } } } catch (Exception e) { // ignore } return "na"; }
firsExactClassLoader = lastExactClassLoader; ClassPackagingData pi = calculateByExactType(callerClass); step.setClassPackagingData(pi); } else { missfireCount++; ClassPackagingData pi = computeBySTEP(step, lastExactClassLoader); step.setClassPackagingData(pi); populateUncommonFrames(commonFrames, stepArray, firsExactClassLoader);
private ClassPackagingData computeBySTEP(StackTraceElementProxy step, ClassLoader lastExactClassLoader) { String className = step.ste.getClassName(); ClassPackagingData cpd = cache.get(className); if (cpd != null) { return cpd; } Class type = bestEffortLoadClass(lastExactClassLoader, className); String version = getImplementationVersion(type); String codeLocation = getCodeLocation(type); cpd = new ClassPackagingData(codeLocation, version, false); cache.put(className, cpd); return cpd; }