mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
02.30.2013 2201f3caea5dec0397451a7b1053cfbdd5efd85d
Fix OPENDJ-1079: OpenDJ UpgradeCli adds HTTP connection handler, which breaks Tomcat6 when OpenDJ is an embeddedDS

* avoid initializing classes during class property value validation as this causes dependencies to be loaded which may be missing in the case where the component is disabled. The class will be fully loaded later if the component is enabled (verified with HTTP connection handler)
* prevent class loading errors from causing the server initialization to hang
* attempt to catch and propagate class loading errors up the stack. They are still not displayed in any logs (OPENDJ-1227).

3 files modified
65 ■■■■ changed files
opends/src/server/org/opends/server/admin/ClassPropertyDefinition.java 26 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/IllegalPropertyValueException.java 20 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/IllegalPropertyValueStringException.java 19 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/ClassPropertyDefinition.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions copyright 2013 ForgeRock AS.
 */
package org.opends.server.admin;
@@ -105,7 +106,7 @@
         * performed.
         */
        try {
          loadClass(value);
          loadClass(value, true);
        } catch (ClassNotFoundException e) {
          // TODO: can we do something better here?
          throw new RuntimeException(e);
@@ -193,9 +194,9 @@
  // Load a named class.
  private static Class<?> loadClass(String className)
  private static Class<?> loadClass(String className, boolean initialize)
      throws ClassNotFoundException, LinkageError {
    return Class.forName(className, true, ClassLoaderProvider
    return Class.forName(className, initialize, ClassLoaderProvider
        .getInstance().getClassLoader());
  }
@@ -250,7 +251,7 @@
    try {
      validateValue(value);
    } catch (IllegalPropertyValueException e) {
      throw new IllegalPropertyValueStringException(this, value);
      throw new IllegalPropertyValueStringException(this, value, e.getCause());
    }
    return value;
@@ -297,7 +298,7 @@
    // Make sure that the named class is valid.
    validateClassName(className);
    Class<?> theClass = validateClassInterfaces(className);
    Class<?> theClass = validateClassInterfaces(className, true);
    // Cast it to the required type.
    return theClass.asSubclass(instanceOf);
@@ -334,7 +335,7 @@
     * check the interfaces that it implements/extends.
     */
    if (allowClassValidation) {
      validateClassInterfaces(value);
      validateClassInterfaces(value, false);
    }
  }
@@ -344,31 +345,30 @@
   * Make sure that named class implements the interfaces named by this
   * definition.
   */
  private Class<?> validateClassInterfaces(String className)
  private Class<?> validateClassInterfaces(String className, boolean initialize)
      throws IllegalPropertyValueException {
    String nvalue = className.trim();
    Class<?> theClass;
    try {
      theClass = loadClass(nvalue);
      theClass = loadClass(nvalue, initialize);
    } catch (Throwable t) {
      // If the class cannot be loaded then it is an invalid value.
      throw new IllegalPropertyValueException(this, className);
      throw new IllegalPropertyValueException(this, className, t);
    }
    for (String i : instanceOfInterfaces) {
      try {
        Class<?> instanceOfClass = loadClass(i);
        Class<?> instanceOfClass = loadClass(i, initialize);
        if (!instanceOfClass.isAssignableFrom(theClass)) {
          throw new IllegalPropertyValueException(this, className);
        }
      } catch (Exception e) {
      } catch (Throwable t) {
        /*
         * Should not happen because the class was validated when the property
         * definition was constructed.
         */
        throw new IllegalPropertyValueException(this, className);
        throw new IllegalPropertyValueException(this, className, t);
      }
    }
opends/src/server/org/opends/server/admin/IllegalPropertyValueException.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions copyright 2013 ForgeRock AS.
 */
package org.opends.server.admin;
@@ -67,6 +68,25 @@
  /**
   * Create a new illegal property value exception.
   *
   * @param pd
   *          The property definition.
   * @param value
   *          The illegal property value.
   * @param cause
   *          The cause.
   */
  public IllegalPropertyValueException(PropertyDefinition<?> pd, Object value,
      Throwable cause)
  {
    super(pd, createMessage(pd, value), cause);
    this.value = value;
  }
  /**
   * Get the illegal property value that caused the exception.
   *
   * @return Returns the illegal property value.
opends/src/server/org/opends/server/admin/IllegalPropertyValueStringException.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions copyright 2013 ForgeRock AS.
 */
package org.opends.server.admin;
@@ -68,6 +69,24 @@
  /**
   * Create a new illegal property value string exception.
   *
   * @param pd
   *          The property definition.
   * @param value
   *          The illegal property value string.
   * @param cause
   *          The cause.
   */
  public IllegalPropertyValueStringException(PropertyDefinition<?> pd,
      String value, Throwable cause) {
    super(pd, createMessage(pd, value), cause);
    this.value = value;
  }
  /**
   * Get the illegal property value string that caused the exception.
   *
   * @return Returns the illegal property value string.