< prev index next >

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

Print this page

 53 
 54     public Object get(Object obj) throws IllegalArgumentException {
 55         return Character.valueOf(getChar(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         throw newGetByteIllegalArgumentException();
 64     }
 65 
 66     public char getChar(Object obj) throws IllegalArgumentException {
 67         try {
 68             if (isStatic()) {
 69                 return (char) getter.invokeExact();
 70             } else {
 71                 return (char) getter.invokeExact(obj);
 72             }
 73         } catch (IllegalArgumentException|NullPointerException e) {
 74             throw e;
 75         } catch (ClassCastException e) {
 76             throw newGetIllegalArgumentException(obj);
 77         } catch (Throwable e) {
 78             throw new InternalError(e);
 79         }
 80     }
 81 
 82     public short getShort(Object obj) throws IllegalArgumentException {
 83         throw newGetShortIllegalArgumentException();
 84     }
 85 
 86     public int getInt(Object obj) throws IllegalArgumentException {
 87         return getChar(obj);
 88     }
 89 
 90     public long getLong(Object obj) throws IllegalArgumentException {
 91         return getChar(obj);
 92     }
 93 

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

 53 
 54     public Object get(Object obj) throws IllegalArgumentException {
 55         return Character.valueOf(getChar(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         throw newGetByteIllegalArgumentException();
 64     }
 65 
 66     public char getChar(Object obj) throws IllegalArgumentException {
 67         try {
 68             if (isStatic()) {
 69                 return (char) getter.invokeExact();
 70             } else {
 71                 return (char) getter.invokeExact(obj);
 72             }
 73         } catch (IllegalArgumentException|IllegalStateException|NullPointerException e) {
 74             throw e;
 75         } catch (ClassCastException e) {
 76             throw newGetIllegalArgumentException(obj);
 77         } catch (Throwable e) {
 78             throw new InternalError(e);
 79         }
 80     }
 81 
 82     public short getShort(Object obj) throws IllegalArgumentException {
 83         throw newGetShortIllegalArgumentException();
 84     }
 85 
 86     public int getInt(Object obj) throws IllegalArgumentException {
 87         return getChar(obj);
 88     }
 89 
 90     public long getLong(Object obj) throws IllegalArgumentException {
 91         return getChar(obj);
 92     }
 93 

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