InstantiationUtil { public static void checkForInstantiation(Class<?> clazz) { final String errorMessage = checkForInstantiationError(clazz); if (errorMessage != null) { throw new RuntimeException("The class '" + clazz.getName() + "' is not instantiable: " + errorMessage); } } private  InstantiationUtil(); static T instantiate(Class<T> clazz, Class<? super T> castTo); static T instantiate(Class<T> clazz); static boolean hasPublicNullaryConstructor(Class<?> clazz); static boolean isPublic(Class<?> clazz); static boolean isProperClass(Class<?> clazz); static boolean isNonStaticInnerClass(Class<?> clazz); static void checkForInstantiation(Class<?> clazz); static String checkForInstantiationError(Class<?> clazz); static T readObjectFromConfig(Configuration config, String key, ClassLoader cl); static void writeObjectToConfig(Object o, Configuration config, String key); static byte[] serializeToByteArray(TypeSerializer<T> serializer, T record); static T deserializeFromByteArray(TypeSerializer<T> serializer, byte[] buf); static T deserializeFromByteArray(TypeSerializer<T> serializer, T reuse, byte[] buf); @SuppressWarnings("unchecked") static T deserializeObject(byte[] bytes, ClassLoader cl); static byte[] serializeObject(Object o); static T clone(T obj); static T clone(T obj, ClassLoader classLoader);  }
@Test(expected = RuntimeException.class) public void testCheckForInstantiationOfPrivateClass() { InstantiationUtil.checkForInstantiation(TestClass.class); }