/** @param className Interface or abstract class that class to load should extend or implement */
  public Class<?> loadAndResolve(String className, byte[] byteCode)
      throws IllegalArgumentException {
    // First things first: just to be sure; maybe we have already loaded it?
    Class<?> old = findLoadedClass(className);
    if (old != null) {
      return old;
    }

    Class<?> impl;

    // First: let's try calling it directly on parent, to be able to access protected/package-access
    // stuff:
    if (_cfgUseParentLoader) {
      try {
        Method method =
            ClassLoader.class.getDeclaredMethod(
                "defineClass", new Class[] {String.class, byte[].class, int.class, int.class});
        method.setAccessible(true);
        return (Class<?>) method.invoke(getParent(), className, byteCode, 0, byteCode.length);
      } catch (Exception e) {
      }
    }

    // but if that doesn't fly, try to do it from our own class loader
    try {
      impl = defineClass(className, byteCode, 0, byteCode.length);
    } catch (LinkageError e) {
      throw new IllegalArgumentException(
          "Failed to load class '" + className + "': " + e.getMessage(), e);
    }
    // important: must also resolve the class...
    resolveClass(impl);
    return impl;
  }
Ejemplo n.º 2
0
 public boolean browse(URL url) {
   try {
     return browseImpl(url);
   } catch (DesktopException e) {
     if (logger.isDebugEnabled()) {
       logger.error("Backend error starting browser", e);
     } else {
       logger.error(e.getMessage());
     }
     return false;
   } catch (LinkageError e) {
     logger.error("Linkage error starting browser: " + e.getMessage());
     return false;
   }
 }
 private static boolean loadHdf5Lib() {
   try {
     Class.forName(H5_CLASS_NAME);
     return true;
   } catch (ClassNotFoundException ignored) {
     // no logging here, H5 class may not be provided by intention
     return false;
   } catch (LinkageError e) {
     // warning here, because H5 class exists, but native libs couldn't be loaded
     SystemUtils.LOG.warning(
         MessageFormat.format(
             "{0}: HDF-5 library not available: {1}: {2}",
             Hdf5ProductWriterPlugIn.class, e.getClass(), e.getMessage()));
     return false;
   }
 }
Ejemplo n.º 4
0
 PluginManager(Config serverConfig, Iterable<ServerPlugin> plugins, LogProvider logProvider) {
   Map<String, Pair<ServerPlugin, ServerExtender>> extensions =
       new HashMap<String, Pair<ServerPlugin, ServerExtender>>();
   Log log = logProvider.getLog(getClass());
   for (ServerPlugin plugin : plugins) {
     PluginPointFactory factory = new PluginPointFactoryImpl();
     final ServerExtender extender = new ServerExtender(factory);
     try {
       plugin.loadServerExtender(extender);
     } catch (Exception ex) {
       log.warn("Failed to load plugin [%s]: %s", plugin.toString(), ex.getMessage());
       continue;
     } catch (LinkageError err) {
       log.warn("Failed to load plugin [%s]: %s", plugin.toString(), err.getMessage());
       continue;
     }
     Pair<ServerPlugin, ServerExtender> old =
         extensions.put(plugin.name, Pair.of(plugin, extender));
     if (old != null) {
       log.warn(
           String.format(
               "Extension naming conflict \"%s\" between \"%s\" and \"%s\"",
               plugin.name, old.first().getClass(), plugin.getClass()));
     }
   }
   for (Pair<ServerPlugin, ServerExtender> extension : extensions.values()) {
     log.info(String.format("Loaded server plugin \"%s\"", extension.first().name));
     for (PluginPoint point : extension.other().all()) {
       log.info(
           String.format(
               "  %s.%s: %s",
               point.forType().getSimpleName(), point.name(), point.getDescription()));
     }
     this.extensions.put(extension.first().name, extension.other());
   }
 }
Ejemplo n.º 5
0
 /** @tests java.lang.LinkageError#LinkageError(java.lang.String) */
 public void test_ConstructorLjava_lang_String() {
   LinkageError e = new LinkageError("fixture");
   assertEquals("fixture", e.getMessage());
   assertNull(e.getCause());
 }
Ejemplo n.º 6
0
 /** @tests java.lang.LinkageError#LinkageError() */
 public void test_Constructor() {
   LinkageError e = new LinkageError();
   assertNull(e.getMessage());
   assertNull(e.getLocalizedMessage());
   assertNull(e.getCause());
 }