Path: blob/master/src/java.base/share/classes/jdk/internal/reflect/UnsafeCharacterFieldAccessorImpl.java
41159 views
/*1* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.reflect;2627import java.lang.reflect.Field;2829class UnsafeCharacterFieldAccessorImpl extends UnsafeFieldAccessorImpl {30UnsafeCharacterFieldAccessorImpl(Field field) {31super(field);32}3334public Object get(Object obj) throws IllegalArgumentException {35return Character.valueOf(getChar(obj));36}3738public boolean getBoolean(Object obj) throws IllegalArgumentException {39throw newGetBooleanIllegalArgumentException();40}4142public byte getByte(Object obj) throws IllegalArgumentException {43throw newGetByteIllegalArgumentException();44}4546public char getChar(Object obj) throws IllegalArgumentException {47ensureObj(obj);48return unsafe.getChar(obj, fieldOffset);49}5051public short getShort(Object obj) throws IllegalArgumentException {52throw newGetShortIllegalArgumentException();53}5455public int getInt(Object obj) throws IllegalArgumentException {56return getChar(obj);57}5859public long getLong(Object obj) throws IllegalArgumentException {60return getChar(obj);61}6263public float getFloat(Object obj) throws IllegalArgumentException {64return getChar(obj);65}6667public double getDouble(Object obj) throws IllegalArgumentException {68return getChar(obj);69}7071public void set(Object obj, Object value)72throws IllegalArgumentException, IllegalAccessException73{74ensureObj(obj);75if (isFinal) {76throwFinalFieldIllegalAccessException(value);77}78if (value == null) {79throwSetIllegalArgumentException(value);80}81if (value instanceof Character) {82unsafe.putChar(obj, fieldOffset, ((Character) value).charValue());83return;84}85throwSetIllegalArgumentException(value);86}8788public void setBoolean(Object obj, boolean z)89throws IllegalArgumentException, IllegalAccessException90{91throwSetIllegalArgumentException(z);92}9394public void setByte(Object obj, byte b)95throws IllegalArgumentException, IllegalAccessException96{97throwSetIllegalArgumentException(b);98}99100public void setChar(Object obj, char c)101throws IllegalArgumentException, IllegalAccessException102{103ensureObj(obj);104if (isFinal) {105throwFinalFieldIllegalAccessException(c);106}107unsafe.putChar(obj, fieldOffset, c);108}109110public void setShort(Object obj, short s)111throws IllegalArgumentException, IllegalAccessException112{113throwSetIllegalArgumentException(s);114}115116public void setInt(Object obj, int i)117throws IllegalArgumentException, IllegalAccessException118{119throwSetIllegalArgumentException(i);120}121122public void setLong(Object obj, long l)123throws IllegalArgumentException, IllegalAccessException124{125throwSetIllegalArgumentException(l);126}127128public void setFloat(Object obj, float f)129throws IllegalArgumentException, IllegalAccessException130{131throwSetIllegalArgumentException(f);132}133134public void setDouble(Object obj, double d)135throws IllegalArgumentException, IllegalAccessException136{137throwSetIllegalArgumentException(d);138}139}140141142