< prev index next >

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

Print this page

 49 
 50     MethodHandleByteFieldAccessorImpl(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly, boolean isStatic) {
 51         super(field, getter, setter, isReadOnly, isStatic);
 52     }
 53 
 54     public Object get(Object obj) throws IllegalArgumentException {
 55         return Byte.valueOf(getByte(obj));
 56     }
 57 
 58     public boolean getBoolean(Object obj) throws IllegalArgumentException {
 59         throw newGetBooleanIllegalArgumentException();
 60     }
 61 
 62     public byte getByte(Object obj) throws IllegalArgumentException {
 63         try {
 64             if (isStatic()) {
 65                 return (byte) getter.invokeExact();
 66             } else {
 67                 return (byte) getter.invokeExact(obj);
 68             }
 69         } catch (IllegalArgumentException|NullPointerException e) {
 70             throw e;
 71         } catch (ClassCastException e) {
 72             throw newGetIllegalArgumentException(obj);
 73         } catch (Throwable e) {
 74             throw new InternalError(e);
 75         }
 76     }
 77 
 78     public char getChar(Object obj) throws IllegalArgumentException {
 79         throw newGetCharIllegalArgumentException();
 80     }
 81 
 82     public short getShort(Object obj) throws IllegalArgumentException {
 83         return getByte(obj);
 84     }
 85 
 86     public int getInt(Object obj) throws IllegalArgumentException {
 87         return getByte(obj);
 88     }
 89 

120 
121     public void setBoolean(Object obj, boolean z)
122         throws IllegalArgumentException, IllegalAccessException
123     {
124         throwSetIllegalArgumentException(z);
125     }
126 
127     public void setByte(Object obj, byte b)
128         throws IllegalArgumentException, IllegalAccessException
129     {
130         if (isReadOnly()) {
131             ensureObj(obj);     // throw NPE if obj is null on instance field
132             throwFinalFieldIllegalAccessException(b);
133         }
134         try {
135             if (isStatic()) {
136                 setter.invokeExact(b);
137             } else {
138                 setter.invokeExact(obj, b);
139             }
140         } catch (IllegalArgumentException|NullPointerException e) {
141             throw e;
142         } catch (ClassCastException e) {
143             // receiver is of invalid type
144             throw newSetIllegalArgumentException(obj);
145         } catch (Throwable e) {
146             throw new InternalError(e);
147         }
148     }
149 
150     public void setChar(Object obj, char c)
151         throws IllegalArgumentException, IllegalAccessException
152     {
153         throwSetIllegalArgumentException(c);
154     }
155 
156     public void setShort(Object obj, short s)
157         throws IllegalArgumentException, IllegalAccessException
158     {
159         throwSetIllegalArgumentException(s);
160     }

 49 
 50     MethodHandleByteFieldAccessorImpl(Field field, MethodHandle getter, MethodHandle setter, boolean isReadOnly, boolean isStatic) {
 51         super(field, getter, setter, isReadOnly, isStatic);
 52     }
 53 
 54     public Object get(Object obj) throws IllegalArgumentException {
 55         return Byte.valueOf(getByte(obj));
 56     }
 57 
 58     public boolean getBoolean(Object obj) throws IllegalArgumentException {
 59         throw newGetBooleanIllegalArgumentException();
 60     }
 61 
 62     public byte getByte(Object obj) throws IllegalArgumentException {
 63         try {
 64             if (isStatic()) {
 65                 return (byte) getter.invokeExact();
 66             } else {
 67                 return (byte) getter.invokeExact(obj);
 68             }
 69         } catch (IllegalArgumentException|IllegalStateException|NullPointerException e) {
 70             throw e;
 71         } catch (ClassCastException e) {
 72             throw newGetIllegalArgumentException(obj);
 73         } catch (Throwable e) {
 74             throw new InternalError(e);
 75         }
 76     }
 77 
 78     public char getChar(Object obj) throws IllegalArgumentException {
 79         throw newGetCharIllegalArgumentException();
 80     }
 81 
 82     public short getShort(Object obj) throws IllegalArgumentException {
 83         return getByte(obj);
 84     }
 85 
 86     public int getInt(Object obj) throws IllegalArgumentException {
 87         return getByte(obj);
 88     }
 89 

120 
121     public void setBoolean(Object obj, boolean z)
122         throws IllegalArgumentException, IllegalAccessException
123     {
124         throwSetIllegalArgumentException(z);
125     }
126 
127     public void setByte(Object obj, byte b)
128         throws IllegalArgumentException, IllegalAccessException
129     {
130         if (isReadOnly()) {
131             ensureObj(obj);     // throw NPE if obj is null on instance field
132             throwFinalFieldIllegalAccessException(b);
133         }
134         try {
135             if (isStatic()) {
136                 setter.invokeExact(b);
137             } else {
138                 setter.invokeExact(obj, b);
139             }
140         } catch (IllegalArgumentException|IllegalStateException|NullPointerException e) {
141             throw e;
142         } catch (ClassCastException e) {
143             // receiver is of invalid type
144             throw newSetIllegalArgumentException(obj);
145         } catch (Throwable e) {
146             throw new InternalError(e);
147         }
148     }
149 
150     public void setChar(Object obj, char c)
151         throws IllegalArgumentException, IllegalAccessException
152     {
153         throwSetIllegalArgumentException(c);
154     }
155 
156     public void setShort(Object obj, short s)
157         throws IllegalArgumentException, IllegalAccessException
158     {
159         throwSetIllegalArgumentException(s);
160     }
< prev index next >