45 }
46 }
47 return new MethodHandleBooleanFieldAccessorImpl(field, getter, setter, isReadOnly, isStatic);
48 }
49
50 MethodHandleBooleanFieldAccessorImpl(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 Boolean.valueOf(getBoolean(obj));
56 }
57
58 public boolean getBoolean(Object obj) throws IllegalArgumentException {
59 try {
60 if (isStatic()) {
61 return (boolean) getter.invokeExact();
62 } else {
63 return (boolean) getter.invokeExact(obj);
64 }
65 } catch (IllegalArgumentException|NullPointerException e) {
66 throw e;
67 } catch (ClassCastException e) {
68 throw newGetIllegalArgumentException(obj);
69 } catch (Throwable e) {
70 throw new InternalError(e);
71 }
72 }
73
74 public byte getByte(Object obj) throws IllegalArgumentException {
75 throw newGetByteIllegalArgumentException();
76 }
77
78 public char getChar(Object obj) throws IllegalArgumentException {
79 throw newGetCharIllegalArgumentException();
80 }
81
82 public short getShort(Object obj) throws IllegalArgumentException {
83 throw newGetShortIllegalArgumentException();
84 }
85
114 if (value instanceof Boolean b) {
115 setBoolean(obj, b.booleanValue());
116 } else {
117 throwSetIllegalArgumentException(value);
118 }
119 }
120
121 public void setBoolean(Object obj, boolean z)
122 throws IllegalArgumentException, IllegalAccessException
123 {
124 if (isReadOnly()) {
125 ensureObj(obj); // throw NPE if obj is null on instance field
126 throwFinalFieldIllegalAccessException(z);
127 }
128 try {
129 if (isStatic()) {
130 setter.invokeExact(z);
131 } else {
132 setter.invokeExact(obj, z);
133 }
134 } catch (IllegalArgumentException|NullPointerException e) {
135 throw e;
136 } catch (ClassCastException e) {
137 // receiver is of invalid type
138 throw newSetIllegalArgumentException(obj);
139 } catch (Throwable e) {
140 throw new InternalError(e);
141 }
142 }
143
144 public void setByte(Object obj, byte b)
145 throws IllegalArgumentException, IllegalAccessException
146 {
147 throwSetIllegalArgumentException(b);
148 }
149
150 public void setChar(Object obj, char c)
151 throws IllegalArgumentException, IllegalAccessException
152 {
153 throwSetIllegalArgumentException(c);
154 }
|
45 }
46 }
47 return new MethodHandleBooleanFieldAccessorImpl(field, getter, setter, isReadOnly, isStatic);
48 }
49
50 MethodHandleBooleanFieldAccessorImpl(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 Boolean.valueOf(getBoolean(obj));
56 }
57
58 public boolean getBoolean(Object obj) throws IllegalArgumentException {
59 try {
60 if (isStatic()) {
61 return (boolean) getter.invokeExact();
62 } else {
63 return (boolean) getter.invokeExact(obj);
64 }
65 } catch (IllegalArgumentException|IllegalStateException|NullPointerException e) {
66 throw e;
67 } catch (ClassCastException e) {
68 throw newGetIllegalArgumentException(obj);
69 } catch (Throwable e) {
70 throw new InternalError(e);
71 }
72 }
73
74 public byte getByte(Object obj) throws IllegalArgumentException {
75 throw newGetByteIllegalArgumentException();
76 }
77
78 public char getChar(Object obj) throws IllegalArgumentException {
79 throw newGetCharIllegalArgumentException();
80 }
81
82 public short getShort(Object obj) throws IllegalArgumentException {
83 throw newGetShortIllegalArgumentException();
84 }
85
114 if (value instanceof Boolean b) {
115 setBoolean(obj, b.booleanValue());
116 } else {
117 throwSetIllegalArgumentException(value);
118 }
119 }
120
121 public void setBoolean(Object obj, boolean z)
122 throws IllegalArgumentException, IllegalAccessException
123 {
124 if (isReadOnly()) {
125 ensureObj(obj); // throw NPE if obj is null on instance field
126 throwFinalFieldIllegalAccessException(z);
127 }
128 try {
129 if (isStatic()) {
130 setter.invokeExact(z);
131 } else {
132 setter.invokeExact(obj, z);
133 }
134 } catch (IllegalArgumentException|IllegalStateException|NullPointerException e) {
135 throw e;
136 } catch (ClassCastException e) {
137 // receiver is of invalid type
138 throw newSetIllegalArgumentException(obj);
139 } catch (Throwable e) {
140 throw new InternalError(e);
141 }
142 }
143
144 public void setByte(Object obj, byte b)
145 throws IllegalArgumentException, IllegalAccessException
146 {
147 throwSetIllegalArgumentException(b);
148 }
149
150 public void setChar(Object obj, char c)
151 throws IllegalArgumentException, IllegalAccessException
152 {
153 throwSetIllegalArgumentException(c);
154 }
|