private Class<?> defineClass(final String name, final ClassSpec classSpec) {
   // Ensure that the package is loaded
   final int lastIdx = name.lastIndexOf('.');
   if (lastIdx != -1) {
     // there's a package name; get the Package for it
     final String packageName = name.substring(0, lastIdx);
     final Package pkg = getPackage(packageName);
     if (pkg != null) {
       // Package is defined already
       if (pkg.isSealed() && !pkg.isSealed(classSpec.getCodeSource().getLocation())) {
         // use the same message as the JDK
         throw new SecurityException("sealing violation: package " + packageName + " is sealed");
       }
     } else {
       final PackageSpec spec;
       try {
         spec = getModule().getLocalPackageSpec(name);
         definePackage(packageName, spec);
       } catch (IOException e) {
         definePackage(packageName, null);
       }
     }
   }
   final Class<?> newClass;
   try {
     final byte[] bytes = classSpec.getBytes();
     newClass = defineClass(name, bytes, 0, bytes.length, classSpec.getCodeSource());
   } catch (Error e) {
     if (debugDefines) System.err.println("Failed to define class '" + name + "': " + e);
     throw e;
   } catch (RuntimeException e) {
     if (debugDefines) System.err.println("Failed to define class '" + name + "': " + e);
     throw e;
   }
   final AssertionSetting setting = classSpec.getAssertionSetting();
   if (setting != AssertionSetting.INHERIT) {
     setClassAssertionStatus(name, setting == AssertionSetting.ENABLED);
   }
   return newClass;
 }