String (final ClassLoader loader, final String className, final boolean validateConstructor) { if (loader == null) { throw new IllegalArgumentException("loader cannot be null"); } if (className == null) { throw new IllegalArgumentException("className cannot be null"); } // These classes are not visible for passed class loader! if ("com.intellij.uiDesigner.HSpacer".equals(className) || "com.intellij.uiDesigner.VSpacer".equals(className)) { return null; } final Class<?> aClass; try { aClass = Class.forName(className, false, loader); } catch (final ClassNotFoundException exc) { return "Class \"" + className + "\"not found"; } catch (NoClassDefFoundError exc) { return "Cannot load class " + className + ": " + exc.getMessage(); } catch (ExceptionInInitializerError exc) { return "Cannot initialize class " + className + ": " + exc.getMessage(); } catch (UnsupportedClassVersionError exc) { return "Unsupported class version error: " + className; } if (validateConstructor) { try { final Constructor<?> constructor = aClass.getConstructor(); if ((constructor.getModifiers() & Modifier.PUBLIC) == 0) { return "Class \"" + className + "\" does not have default public constructor"; } } catch (final Exception exc) { return "Class \"" + className + "\" does not have default constructor"; } } // Check that JComponent is accessible via the loader if (!JComponent.class.isAssignableFrom(aClass)) { return "Class \"" + className + "\" is not an instance of javax.swing.JComponent"; } return null; }