private WeavingException weavingException(WovenClass wovenClass, Exception e) { String msg = format("There was a serious error trying to weave the class %s. See the associated exception for more information.", wovenClass.getClassName()); // This is a failure that should stop the class loading! LOGGER.error(msg, e); return new WeavingException(msg, e); } }
fwCtx.frameworkError(twh.reference.getBundle(), we); final ClassFormatError cfe = new ClassFormatError( "WeavingException thrown: " + we.getMessage() + " by hook " + twh.getClass().getName()); cfe.initCause(we);
public boolean isSuperClassWoven(WovenClass wovenClass) { ClassReader cReader = new ClassReader(wovenClass.getBytes()); try { Class<?> superClass = Class.forName(cReader.getSuperName().replace('/', '.'), false, wovenClass.getBundleWiring().getClassLoader()); return WovenProxy.class.isAssignableFrom(superClass); } catch (ClassNotFoundException e) { String failureMessage = NLS.MESSAGES.getMessage("fatal.weaving.failure", wovenClass.getClassName()); //This is a failure that should stop the class loading! LOGGER.error(failureMessage, e); throw new WeavingException(failureMessage, e); } }
private static boolean transformClass(WovenClass wovenClass, ClassLoader cl, ClassTransformer transformer) throws ThreadDeath, OutOfMemoryError { try { byte[] result = transformer .transform(cl, wovenClass.getClassName(), wovenClass.getDefinedClass(), wovenClass.getProtectionDomain(), wovenClass.getBytes()); if (result != null) { wovenClass.setBytes(result); wovenClass.getDynamicImports().add("org.eclipse.persistence.*"); wovenClass.getDynamicImports().add("org.apache.openjpa.*"); return true; } } catch (Exception t) { Bundle b = wovenClass.getBundleWiring().getBundle(); String msg = String.format("Weaving failure on class %s in bundle %s/%s using transformer %s", wovenClass.getClassName(), b.getSymbolicName(), b.getVersion(), transformer); throw new WeavingException(msg, t); } return false; }
throw new WeavingException(failureMessage, e);
@Override public void weave(WovenClass wovenClass) { if (wovenClass.getBundleWiring().getBundle() == puInfo.getBundle() && managedClasses.contains(wovenClass.getClassName())) { try { synchronized (this) { LOG.debug("weaving {}", wovenClass.getClassName()); byte[] transformed = transformer.transform(cl, wovenClass.getClassName(), wovenClass.getDefinedClass(), wovenClass.getProtectionDomain(), wovenClass.getBytes()); wovenClass.setBytes(transformed); /* * * TODO Hard-coded list of packages for OpenJPA and Eclipselink. We should only * add the ones required for the given provider. */ wovenClass.getDynamicImports().add("org.apache.openjpa.enhance"); wovenClass.getDynamicImports().add("org.apache.openjpa.util"); wovenClass.getDynamicImports().add("org.eclipse.persistence.*"); wovenClass.getDynamicImports().add("org.hibernate.*"); wovenClass.getDynamicImports().add("javassist.util.proxy"); } } catch (IllegalClassFormatException exc) { throw new WeavingException("cannot transform " + wovenClass.getClassName(), exc); } } }