24 */
25
26 package sun.reflect.annotation;
27
28 import java.io.ObjectInputStream;
29 import java.lang.annotation.*;
30 import java.lang.reflect.*;
31 import java.io.Serializable;
32 import java.util.*;
33 import java.util.stream.*;
34 import java.security.AccessController;
35 import java.security.PrivilegedAction;
36
37 /**
38 * InvocationHandler for dynamic proxy implementation of Annotation.
39 *
40 * @author Josh Bloch
41 * @since 1.5
42 */
43 class AnnotationInvocationHandler implements InvocationHandler, Serializable {
44 private static final long serialVersionUID = 6182022883658399397L;
45 private final Class<? extends Annotation> type;
46 private final Map<String, Object> memberValues;
47
48 AnnotationInvocationHandler(Class<? extends Annotation> type, Map<String, Object> memberValues) {
49 Class<?>[] superInterfaces = type.getInterfaces();
50 if (!type.isAnnotation() ||
51 superInterfaces.length != 1 ||
52 superInterfaces[0] != java.lang.annotation.Annotation.class)
53 throw new AnnotationFormatError("Attempt to create proxy for a non-annotation type.");
54 this.type = type;
55 this.memberValues = memberValues;
56 }
57
58 public Object invoke(Object proxy, Method method, Object[] args) {
59 String member = method.getName();
60 int parameterCount = method.getParameterCount();
61
62 // Handle Object and Annotation methods
63 if (parameterCount == 1 && member == "equals" &&
586
587 if (type == byte[].class)
588 return Arrays.hashCode((byte[]) value);
589 if (type == char[].class)
590 return Arrays.hashCode((char[]) value);
591 if (type == double[].class)
592 return Arrays.hashCode((double[]) value);
593 if (type == float[].class)
594 return Arrays.hashCode((float[]) value);
595 if (type == int[].class)
596 return Arrays.hashCode((int[]) value);
597 if (type == long[].class)
598 return Arrays.hashCode((long[]) value);
599 if (type == short[].class)
600 return Arrays.hashCode((short[]) value);
601 if (type == boolean[].class)
602 return Arrays.hashCode((boolean[]) value);
603 return Arrays.hashCode((Object[]) value);
604 }
605
606 private void readObject(java.io.ObjectInputStream s)
607 throws java.io.IOException, ClassNotFoundException {
608 ObjectInputStream.GetField fields = s.readFields();
609
610 @SuppressWarnings("unchecked")
611 Class<? extends Annotation> t = (Class<? extends Annotation>)fields.get("type", null);
612 @SuppressWarnings("unchecked")
613 Map<String, Object> streamVals = (Map<String, Object>)fields.get("memberValues", null);
614
615 // Check to make sure that types have not evolved incompatibly
616
617 AnnotationType annotationType = null;
618 try {
619 annotationType = AnnotationType.getInstance(t);
620 } catch(IllegalArgumentException e) {
621 // Class is no longer an annotation type; time to punch out
622 throw new java.io.InvalidObjectException("Non-annotation type in annotation serial stream");
623 }
624
625 Map<String, Class<?>> memberTypes = annotationType.memberTypes();
|
24 */
25
26 package sun.reflect.annotation;
27
28 import java.io.ObjectInputStream;
29 import java.lang.annotation.*;
30 import java.lang.reflect.*;
31 import java.io.Serializable;
32 import java.util.*;
33 import java.util.stream.*;
34 import java.security.AccessController;
35 import java.security.PrivilegedAction;
36
37 /**
38 * InvocationHandler for dynamic proxy implementation of Annotation.
39 *
40 * @author Josh Bloch
41 * @since 1.5
42 */
43 class AnnotationInvocationHandler implements InvocationHandler, Serializable {
44 @java.io.Serial
45 private static final long serialVersionUID = 6182022883658399397L;
46 private final Class<? extends Annotation> type;
47 private final Map<String, Object> memberValues;
48
49 AnnotationInvocationHandler(Class<? extends Annotation> type, Map<String, Object> memberValues) {
50 Class<?>[] superInterfaces = type.getInterfaces();
51 if (!type.isAnnotation() ||
52 superInterfaces.length != 1 ||
53 superInterfaces[0] != java.lang.annotation.Annotation.class)
54 throw new AnnotationFormatError("Attempt to create proxy for a non-annotation type.");
55 this.type = type;
56 this.memberValues = memberValues;
57 }
58
59 public Object invoke(Object proxy, Method method, Object[] args) {
60 String member = method.getName();
61 int parameterCount = method.getParameterCount();
62
63 // Handle Object and Annotation methods
64 if (parameterCount == 1 && member == "equals" &&
587
588 if (type == byte[].class)
589 return Arrays.hashCode((byte[]) value);
590 if (type == char[].class)
591 return Arrays.hashCode((char[]) value);
592 if (type == double[].class)
593 return Arrays.hashCode((double[]) value);
594 if (type == float[].class)
595 return Arrays.hashCode((float[]) value);
596 if (type == int[].class)
597 return Arrays.hashCode((int[]) value);
598 if (type == long[].class)
599 return Arrays.hashCode((long[]) value);
600 if (type == short[].class)
601 return Arrays.hashCode((short[]) value);
602 if (type == boolean[].class)
603 return Arrays.hashCode((boolean[]) value);
604 return Arrays.hashCode((Object[]) value);
605 }
606
607 @java.io.Serial
608 private void readObject(java.io.ObjectInputStream s)
609 throws java.io.IOException, ClassNotFoundException {
610 ObjectInputStream.GetField fields = s.readFields();
611
612 @SuppressWarnings("unchecked")
613 Class<? extends Annotation> t = (Class<? extends Annotation>)fields.get("type", null);
614 @SuppressWarnings("unchecked")
615 Map<String, Object> streamVals = (Map<String, Object>)fields.get("memberValues", null);
616
617 // Check to make sure that types have not evolved incompatibly
618
619 AnnotationType annotationType = null;
620 try {
621 annotationType = AnnotationType.getInstance(t);
622 } catch(IllegalArgumentException e) {
623 // Class is no longer an annotation type; time to punch out
624 throw new java.io.InvalidObjectException("Non-annotation type in annotation serial stream");
625 }
626
627 Map<String, Class<?>> memberTypes = annotationType.memberTypes();
|