< prev index next >

src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java

Print this page
@@ -232,10 +232,13 @@
  
      public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
          if (!Externalizable.class.isAssignableFrom(cl)) {
              return null;
          }
+         if (cl.isValue()) {
+             throw new UnsupportedOperationException("newConstructorForExternalization does not support value classes");
+         }
          try {
              Constructor<?> cons = cl.getConstructor();
              cons.setAccessible(true);
              return cons;
          } catch (NoSuchMethodException ex) {

@@ -248,10 +251,13 @@
      {
          if (constructorToCall.getDeclaringClass() == cl) {
              constructorToCall.setAccessible(true);
              return constructorToCall;
          }
+         if (cl.isValue()) {
+             throw new UnsupportedOperationException("newConstructorForSerialization does not support value classes");
+         }
          return generateConstructor(cl, constructorToCall);
      }
  
      /**
       * Given a class, determines whether its superclass has

@@ -307,10 +313,14 @@
       *
       * @param cl the class for which a constructor is to be found
       * @return the generated constructor, or null if none is available
       */
      public final Constructor<?> newConstructorForSerialization(Class<?> cl) {
+         if (cl.isValue()) {
+             throw new UnsupportedOperationException("newConstructorForSerialization does not support value classes: " + cl);
+         }
+ 
          Class<?> initCl = cl;
          while (Serializable.class.isAssignableFrom(initCl)) {
              Class<?> prev = initCl;
              if ((initCl = initCl.getSuperclass()) == null ||
                  (!disableSerialConstructorChecks() && !superHasAccessibleConstructor(prev))) {
< prev index next >