List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s)
ClassNotFoundException
with the specified detail message. From source file:org.evosuite.instrumentation.TestabilityTransformationClassLoader.java
private Class<?> instrumentClass(String fullyQualifiedTargetClass) throws ClassNotFoundException { logger.info("Instrumenting class '{}'.", fullyQualifiedTargetClass); try {//from www. ja v a2 s. co m String className = fullyQualifiedTargetClass.replace('.', '/'); InputStream is = ResourceList.getClassAsStream(className); if (is == null) { throw new ClassNotFoundException("Class '" + className + ".class" + "' should be in target project, but could not be found!"); } ClassReader reader = new ClassReader(is); ClassNode classNode = new ClassNode(); reader.accept(classNode, ClassReader.SKIP_FRAMES); ClassVisitor cv = new CFGClassAdapter(classLoader, null, className); classNode.accept(cv); BooleanTestabilityTransformation tt = new BooleanTestabilityTransformation(classNode, this); // cv = new TraceClassVisitor(writer, new // PrintWriter(System.out)); //cv = new TraceClassVisitor(cv, new PrintWriter(System.out)); //cv = new CheckClassAdapter(cv); try { //tt.transform().accept(cv); //if (isTargetClassName(classNameWithDots)) classNode = tt.transform(); } catch (Throwable t) { throw new Error(t); } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); byte[] byteBuffer = writer.toByteArray(); Class<?> result = defineClass(fullyQualifiedTargetClass, byteBuffer, 0, byteBuffer.length); classes.put(fullyQualifiedTargetClass, result); logger.info("Keeping class: {}", fullyQualifiedTargetClass); return result; } catch (Throwable t) { throw new ClassNotFoundException(t.getMessage(), t); } }
From source file:com.cyclopsgroup.waterview.web.taglib.FieldTag.java
/** * @param type The type to set./*from ww w . ja va 2s . c o m*/ * * @throws ClassNotFoundException */ public void setType(String type) throws ClassNotFoundException { this.type = type; this.fieldType = TypeUtils.getNonePrimitiveType(type); if (fieldType == null) { throw new ClassNotFoundException(type); } }
From source file:com.runwaysdk.generation.loader.RunwayClassLoader.java
/** * actualLoad breaks the standard delegation model for ClassLoaders. It reads * the bytes of the requested class, and if the class implements * {@link Reloadable}, then it loads the class <b>without</b> delegating up * the loader hierarchy. If the target class does not implement * {@link Reloadable}, then this well delegate to the parent classloader. * /*from ww w . ja v a2 s . co m*/ * loadClass is synchronized with a {@link ReentrantLock}. * * @param name * The fully qualified name of the class * @param resolve * If <tt>true</tt> then resolve the class * @return The resulting <tt>Class</tt> object */ public Class<?> actualLoad(String name, boolean resolve) throws ClassNotFoundException { LockHolder.lock(this); debug(RunwayClassLoader.class, "Loading " + name); // Encompass everything in a try block so we can use finally to ensure that // the lock is released try { // First grab a cached copy, if it exists Class<?> c = classes.get(name); debug(c, "Found " + name + " in the cache"); // Next, check if the class has already been loaded by the system if (c == null) c = findLoadedClass(name); debug(c, "Found " + name + " through ClassLoader.findLoadedClass()"); // special case for arrays if (arrayPattern.matcher(name).matches()) { c = loadArray(name); debug(c, "Found " + name + " as an array"); } if (c == null) { // Invoke findClass in order to find the class. c = findClass(name); debug(c, "Found " + name + " with custom findClass"); } // If still not found, delegate to the default loader if (c == null && !(getParent() instanceof LoaderManager)) { c = getParent().loadClass(name); debug(c, "Found " + name + " by delegating to parent " + c.getClassLoader()); } // At this point, if c is null, we have failed to find the class if (c == null) { throw new ClassNotFoundException(name); } if (resolve) resolveClass(c); return c; } finally { LockHolder.unlock(); } }
From source file:org.evosuite.instrumentation.testability.TestabilityTransformationClassLoader.java
private Class<?> instrumentClass(String fullyQualifiedTargetClass) throws ClassNotFoundException { logger.info("Instrumenting class '" + fullyQualifiedTargetClass + "'."); try {/*from ww w. j av a 2 s .c o m*/ String className = fullyQualifiedTargetClass.replace('.', '/'); InputStream is = ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()) .getClassAsStream(className); if (is == null) { throw new ClassNotFoundException("Class '" + className + ".class" + "' should be in target project, but could not be found!"); } ClassReader reader = new ClassReader(is); ClassNode classNode = new ClassNode(); reader.accept(classNode, ClassReader.SKIP_FRAMES); ClassVisitor cv = new CFGClassAdapter(classLoader, null, className); classNode.accept(cv); BooleanTestabilityTransformation tt = new BooleanTestabilityTransformation(classNode, this); // cv = new TraceClassVisitor(writer, new // PrintWriter(System.out)); //cv = new TraceClassVisitor(cv, new PrintWriter(System.out)); //cv = new CheckClassAdapter(cv); try { //tt.transform().accept(cv); //if (isTargetClassName(classNameWithDots)) classNode = tt.transform(); } catch (Throwable t) { throw new Error(t); } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); byte[] byteBuffer = writer.toByteArray(); Class<?> result = defineClass(fullyQualifiedTargetClass, byteBuffer, 0, byteBuffer.length); classes.put(fullyQualifiedTargetClass, result); logger.info("Keeping class: " + fullyQualifiedTargetClass); return result; } catch (Throwable t) { throw new ClassNotFoundException(t.getMessage(), t); } }
From source file:org.paxle.desktop.impl.Activator.java
private void initUI(BundleContext context, String impl) throws Exception { String bundleName = BACKEND_IMPL_ROOT_PACKAGE + '.' + impl; Bundle bundle = findBundle(context, bundleName); if (bundle != null) { logger.info(String.format("Using implementation %s ...", impl)); } else {//from w w w . ja v a 2 s . com throw new ClassNotFoundException(String.format( "Unable to find bundle '%s' for implementation %s, is the bundle resolved?", bundleName, impl)); } if (impl == IMPL_JDIC) { /* * Initializing Jdic */ // JdicInit.init(); uiClassLoader.loadClass("org.paxle.desktop.backend.impl.jdic.JdicInit") .getMethod("init", (Class[]) null).invoke(null, (Object[]) null); } // use org.paxle.desktop.backend.*-tree and dialogues.Menu final String diBackendCName = String.format("%s.%s.%s", BACKEND_IMPL_ROOT_PACKAGE, impl, CLASSSIMPLE_DI_BACKEND); final IDIBackend dibackend = (IDIBackend) uiClassLoader.loadClass(diBackendCName).newInstance(); final ServiceManager sm = new ServiceManager(context); dialogue = new DialogueServices(sm); // TODO: when CrawlerCore installed, set crawlHelper CrawlStartHelper crawlHelper = null; dialogue.init(); this.initObject = new DesktopServices(sm, dibackend, dialogue, crawlHelper); context.registerService(IDesktopUtilities.class.getName(), Utilities.instance, null); context.registerService(IDialogueServices.class.getName(), dialogue, null); context.registerService(IDesktopServices.class.getName(), initObject, null); }
From source file:org.eclipse.wb.internal.core.utils.reflect.CompositeClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { for (int i = 0; i < m_classLoaders.size(); i++) { ClassLoader classLoader = m_classLoaders.get(i); // check namespace {/*from ww w. ja v a2 s.c o m*/ List<String> namespaces = m_classNamespaces.get(i); if (!hasNamespace(name, namespaces)) { continue; } } // try to load try { return classLoader.loadClass(name); } catch (ClassNotFoundException notFound) { // OK... try another one } } // not found throw new ClassNotFoundException(name); }
From source file:org.apache.openejb.util.classloader.URLClassLoaderFirst.java
@Override public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { final ReentrantLock lock = LOCK; lock.lock();/*from w w w . ja va 2s. c om*/ try { // already loaded? Class<?> clazz = findLoadedClass(name); if (clazz != null) { if (resolve) { resolveClass(clazz); } return clazz; } // JSE classes? if (canBeLoadedFromSystem(name)) { try { clazz = system.loadClass(name); if (clazz != null) { if (resolve) { resolveClass(clazz); } return clazz; } } catch (final ClassNotFoundException ignored) { // no-op } } // look for it in this classloader final boolean ok = !(shouldSkip(name) || shouldDelegateToTheContainer(this, name)); if (ok) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } // finally delegate clazz = loadFromParent(name, resolve); if (clazz != null) { return clazz; } if (!ok) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } throw new ClassNotFoundException(name); } finally { lock.unlock(); } }
From source file:org.eclipse.emf.mwe.core.WorkflowRunner.java
public boolean doRun(CommandLine line, String[] args) throws Exception { WorkflowEngine runner = new WorkflowEngine(); if (line.hasOption(ENGINE)) { try {// w w w . ja v a 2 s . c o m runner = (WorkflowEngine) Class.forName(line.getOptionValue(ENGINE)).newInstance(); } catch (Exception e) { throw new RuntimeException(e); } } Map<String, String> params = new HashMap<String, String>(); String wfFile = null; final String[] monitorOptValues = line.getOptionValues(MONITOR); if (line.hasOption(CMDL)) { // removed option --cmdLineProcessor final List<String> unprocessedArgs = new ArrayList<String>(); for (int i = 0; i < args.length; i++) { final String arg = args[i]; if (arg.equals("-" + CMDL) || arg.equals("--cmdLineProcessor")) { i++; // ignore this and next element } else if (arg.equals("-" + MONITOR) || arg.equals("--monitorClass")) { // i++; // ignore this and next element i = i + monitorOptValues.length; } else if (arg.endsWith(".oaw") || arg.endsWith(".mwe")) { if (wfFile != null) { throw new IllegalStateException("Workflow file already defined as '" + wfFile + "'!"); } wfFile = arg; // continue the loop (will be handled later) } else { unprocessedArgs.add(arg); } } final Class<?> cmdLineProcessor = ResourceLoaderFactory.createResourceLoader() .loadClass(line.getOptionValue(CMDL)); if (cmdLineProcessor == null) { throw new IllegalStateException( "cannot find class '" + line.getOptionValue(CMDL) + "' for command line processing."); } final Method method = cmdLineProcessor.getMethod("processCmdLine", String[].class, Map.class, WorkflowContext.class); method.invoke(cmdLineProcessor.newInstance(), unprocessedArgs.toArray(new String[0]), params, runner.getContext()); } else { params = resolveParams(line.getOptionValues(PARAM)); wfFile = line.getArgs()[0]; } if ((wfFile == null) || !(wfFile.endsWith(".oaw") || wfFile.endsWith(".mwe"))) { wrongCall(line); return false; } ProgressMonitor monitor = null; if (monitorOptValues != null) { final Class<?> clazz = ResourceLoaderFactory.createResourceLoader().loadClass(monitorOptValues[0]); if (clazz == null) { throw new ClassNotFoundException("Didn't find class " + monitorOptValues[0]); } monitor = (ProgressMonitor) clazz.newInstance(); if (monitor instanceof ProgressMonitor2) { ((ProgressMonitor2) monitor).init(monitorOptValues); } else if (monitor instanceof DebugMonitor) { // this complication is because of an API problem. // debug monitor throws an IOException and is not // compatible with ProgressMonitor2 interface. ((DebugMonitor) monitor).init(monitorOptValues); } } // normalize wfFile name so that it can be found in the class path // (necessary for debugger source lookup) URL wfUrl; int index = 0; do { wfUrl = ResourceLoaderFactory.createResourceLoader().getResource(wfFile); if (wfUrl == null) { index = wfFile.indexOf('/'); if (index >= 0) { wfFile = wfFile.substring(index + 1); } } } while ((wfUrl == null) && (index >= 0)); if (wfUrl == null) { String msg = "can't find the workflow file '" + line.getArgs()[0] + "' in the current class path"; throw new IllegalStateException(msg); } return runner.run(wfFile, monitor, params, null); }
From source file:org.nebulaframework.deployment.classloading.service.ClassLoadingServiceImpl.java
/** * {@inheritDoc}/*from w ww . jav a 2 s . c o m*/ */ @Override public byte[] findClass(UUID ownerId, String name) throws ClassNotFoundException, IllegalArgumentException { /* -- Remote Loading -- */ // Get ClassExporter of owner node GridNodeClassExporter exporter = regService.getGridNodeDelegate(ownerId).getClassExporter(); // Request class export byte[] bytes = exporter.exportClass(name); if (bytes != null) { return bytes; } // Class Not Found log.debug("[ClassLoadingService] Cannot Find Class"); throw new ClassNotFoundException("ClassLoaderService cannot locate class"); }
From source file:org.apache.axis2.context.externalize.MessageExternalizeUtils.java
/** * Read the Message//from w w w .j a v a2 s. c om * @param in * @param mc * @param correlationIDString * @return * @throws IOException */ public static SOAPEnvelope readExternal(ObjectInput in, MessageContext mc, String correlationIDString) throws IOException, ClassNotFoundException { if (log.isDebugEnabled()) { log.debug(correlationIDString + ":readExternal(): start"); } SOAPEnvelope envelope = null; // Read Prolog // Read the class name and object state String name = in.readUTF(); int revision = in.readInt(); if (log.isDebugEnabled()) { log.debug(correlationIDString + ":readExternal(): name= " + name + " revision= " + revision); } // make sure the object data is in a revision level we can handle if (revision != REVISION_2) { throw new ClassNotFoundException(ExternalizeConstants.UNSUPPORTED_REVID); } boolean gotMsg = in.readBoolean(); if (gotMsg != ACTIVE_OBJECT) { if (log.isDebugEnabled()) { log.debug(correlationIDString + ":readExternal(): end:" + "no message present"); } in.readInt(); // Read end of data blocks return envelope; } // Read optimized, optimized content-type, charset encoding and namespace uri boolean optimized = in.readBoolean(); String optimizedContentType = null; if (optimized) { optimizedContentType = in.readUTF(); } String charSetEnc = in.readUTF(); String namespaceURI = in.readUTF(); if (log.isDebugEnabled()) { log.debug(correlationIDString + ":readExternal(): " + "optimized=[" + optimized + "] " + "optimizedContentType=[" + optimizedContentType + "] " + "charSetEnc=[" + charSetEnc + "] " + "namespaceURI=[" + namespaceURI + "]"); } MessageInputStream mis = new MessageInputStream(in); StAXBuilder builder = null; try { if (optimized) { boolean isSOAP = true; builder = BuilderUtil.getAttachmentsBuilder(mc, mis, optimizedContentType, isSOAP); envelope = (SOAPEnvelope) builder.getDocumentElement(); envelope.buildWithAttachments(); } else { XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader(mis, charSetEnc); builder = new StAXSOAPModelBuilder(xmlreader, namespaceURI); envelope = (SOAPEnvelope) builder.getDocumentElement(); envelope.build(); } } catch (Exception ex) { // TODO: what to do if can't get the XML stream reader // For now, log the event log.error(correlationIDString + ":readExternal(): Error when deserializing persisted envelope: [" + ex.getClass().getName() + " : " + ex.getLocalizedMessage() + "]", ex); envelope = null; } finally { if (builder != null) { builder.close(); } // Close the message input stream. This will ensure that the // underlying stream is advanced past the message. mis.close(); if (log.isDebugEnabled()) { log.debug(correlationIDString + ":readExternal(): end"); } } return envelope; }