< prev index next >

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

Print this page

 57 
 58     public boolean getBoolean(Object obj) throws IllegalArgumentException {
 59         throw newGetBooleanIllegalArgumentException();
 60     }
 61 
 62     public byte getByte(Object obj) throws IllegalArgumentException {
 63         throw newGetByteIllegalArgumentException();
 64     }
 65 
 66     public char getChar(Object obj) throws IllegalArgumentException {
 67         throw newGetCharIllegalArgumentException();
 68     }
 69 
 70     public short getShort(Object obj) throws IllegalArgumentException {
 71         try {
 72             if (isStatic()) {
 73                 return (short) getter.invokeExact();
 74             } else {
 75                 return (short) getter.invokeExact(obj);
 76             }
 77         } catch (IllegalArgumentException|NullPointerException e) {
 78             throw e;
 79         } catch (ClassCastException e) {
 80             throw newGetIllegalArgumentException(obj);
 81         } catch (Throwable e) {
 82             throw new InternalError(e);
 83         }
 84     }
 85 
 86     public int getInt(Object obj) throws IllegalArgumentException {
 87         return getShort(obj);
 88     }
 89 
 90     public long getLong(Object obj) throws IllegalArgumentException {
 91         return getShort(obj);
 92     }
 93 
 94     public float getFloat(Object obj) throws IllegalArgumentException {
 95         return getShort(obj);
 96     }
 97 

136 
137     public void setChar(Object obj, char c)
138         throws IllegalArgumentException, IllegalAccessException
139     {
140         throwSetIllegalArgumentException(c);
141     }
142 
143     public void setShort(Object obj, short s)
144         throws IllegalArgumentException, IllegalAccessException
145     {
146         if (isReadOnly()) {
147             ensureObj(obj);     // throw NPE if obj is null on instance field
148             throwFinalFieldIllegalAccessException(s);
149         }
150         try {
151             if (isStatic()) {
152                 setter.invokeExact(s);
153             } else {
154                 setter.invokeExact(obj, s);
155             }
156         } catch (IllegalArgumentException|NullPointerException e) {
157             throw e;
158         } catch (ClassCastException e) {
159             // receiver is of invalid type
160             throw newSetIllegalArgumentException(obj);
161         } catch (Throwable e) {
162             throw new InternalError(e);
163         }
164     }
165 
166     public void setInt(Object obj, int i)
167         throws IllegalArgumentException, IllegalAccessException
168     {
169         throwSetIllegalArgumentException(i);
170     }
171 
172     public void setLong(Object obj, long l)
173         throws IllegalArgumentException, IllegalAccessException
174     {
175         throwSetIllegalArgumentException(l);
176     }

 57 
 58     public boolean getBoolean(Object obj) throws IllegalArgumentException {
 59         throw newGetBooleanIllegalArgumentException();
 60     }
 61 
 62     public byte getByte(Object obj) throws IllegalArgumentException {
 63         throw newGetByteIllegalArgumentException();
 64     }
 65 
 66     public char getChar(Object obj) throws IllegalArgumentException {
 67         throw newGetCharIllegalArgumentException();
 68     }
 69 
 70     public short getShort(Object obj) throws IllegalArgumentException {
 71         try {
 72             if (isStatic()) {
 73                 return (short) getter.invokeExact();
 74             } else {
 75                 return (short) getter.invokeExact(obj);
 76             }
 77         } catch (IllegalArgumentException|IllegalStateException|NullPointerException e) {
 78             throw e;
 79         } catch (ClassCastException e) {
 80             throw newGetIllegalArgumentException(obj);
 81         } catch (Throwable e) {
 82             throw new InternalError(e);
 83         }
 84     }
 85 
 86     public int getInt(Object obj) throws IllegalArgumentException {
 87         return getShort(obj);
 88     }
 89 
 90     public long getLong(Object obj) throws IllegalArgumentException {
 91         return getShort(obj);
 92     }
 93 
 94     public float getFloat(Object obj) throws IllegalArgumentException {
 95         return getShort(obj);
 96     }
 97 

136 
137     public void setChar(Object obj, char c)
138         throws IllegalArgumentException, IllegalAccessException
139     {
140         throwSetIllegalArgumentException(c);
141     }
142 
143     public void setShort(Object obj, short s)
144         throws IllegalArgumentException, IllegalAccessException
145     {
146         if (isReadOnly()) {
147             ensureObj(obj);     // throw NPE if obj is null on instance field
148             throwFinalFieldIllegalAccessException(s);
149         }
150         try {
151             if (isStatic()) {
152                 setter.invokeExact(s);
153             } else {
154                 setter.invokeExact(obj, s);
155             }
156         } catch (IllegalArgumentException|IllegalStateException|NullPointerException e) {
157             throw e;
158         } catch (ClassCastException e) {
159             // receiver is of invalid type
160             throw newSetIllegalArgumentException(obj);
161         } catch (Throwable e) {
162             throw new InternalError(e);
163         }
164     }
165 
166     public void setInt(Object obj, int i)
167         throws IllegalArgumentException, IllegalAccessException
168     {
169         throwSetIllegalArgumentException(i);
170     }
171 
172     public void setLong(Object obj, long l)
173         throws IllegalArgumentException, IllegalAccessException
174     {
175         throwSetIllegalArgumentException(l);
176     }
< prev index next >