553N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 553N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 0N/A/** A class and its patched constant pool. 0N/A * This class allow to modify (patch) a constant pool 0N/A * by changing the value of its entry. 0N/A * Entry are referenced using index that can be get * by parsing the constant pool using * {@link ConstantPoolParser#parse(ConstantPoolVisitor)}. * @see ConstantPoolVisitor * @see ConstantPoolParser#createPatch() /** Create a {@link ConstantPoolParser} and * a {@link ConstantPoolPatch} in one step. * Equivalent to {@code new ConstantPoolParser(classFile).createPatch()}. * @param classFile an array of bytes containing a class. * @see #ConstantPoolParser(Class) /** Create a {@link ConstantPoolParser} and * a {@link ConstantPoolPatch} in one step. * Equivalent to {@code new ConstantPoolParser(templateClass).createPatch()}. * @param templateClass the class to parse. * @see #ConstantPoolParser(Class) /** Creates a patch from an existing patch. * All changes are copied from that patch. * @see ConstantPoolParser#createPatch() /** Which parser built this patch? */ /** Report the tag at the given index in the constant pool. */ /** Report the current patch at the given index of the constant pool. * Null means no patch will be made. * To observe the unpatched entry at the given index, use * {@link #getParser()}{@code .}@link ConstantPoolParser#parse(ConstantPoolVisitor)} /** Clear all patches. */ /** Produce the patches as an array. */ /** Produce the original constant pool as an array. */ /** Walk the constant pool, applying patches using the given map. * @param utf8Map Utf8 strings to modify, if encountered * @param classMap Classes (or their names) to modify, if encountered * @param valueMap Constant values to modify, if encountered * @param deleteUsedEntries if true, delete map entries that are used /** Write the head (header plus constant pool) * of the patched class file to the indicated stream. /** Write the tail (everything after the constant pool) * of the patched class file to the indicated stream. "invalid null constant value");
/** Set the entry of the constant pool indexed by index to * @param index an index to a constant pool entry containing a * {@link ConstantPoolVisitor#CONSTANT_Utf8} value. * @see ConstantPoolVisitor#visitUTF8(int, byte, String) /** Set the entry of the constant pool indexed by index to * a new value, depending on its dynamic type. * @param index an index to a constant pool entry containing a * one of the following structures: * {@link ConstantPoolVisitor#CONSTANT_Integer}, * {@link ConstantPoolVisitor#CONSTANT_Float}, * {@link ConstantPoolVisitor#CONSTANT_Long}, * {@link ConstantPoolVisitor#CONSTANT_Double}, * {@link ConstantPoolVisitor#CONSTANT_String}, or * {@link ConstantPoolVisitor#CONSTANT_Class} * @param value a boxed int, float, long or double; or a string or class object * @throws IllegalArgumentException if the type of the constant does not * match the constant pool entry type, * as reported by {@link #getTag(int)} * @see #putConstantValue(int, byte, Object) * @see ConstantPoolVisitor#visitConstantValue(int, byte, Object) * @see ConstantPoolVisitor#visitConstantString(int, byte, String, int) /** Set the entry of the constant pool indexed by index to * @param index an index to a constant pool entry matching the given tag * @param tag one of the following values: * {@link ConstantPoolVisitor#CONSTANT_Integer}, * {@link ConstantPoolVisitor#CONSTANT_Float}, * {@link ConstantPoolVisitor#CONSTANT_Long}, * {@link ConstantPoolVisitor#CONSTANT_Double}, * {@link ConstantPoolVisitor#CONSTANT_String}, or * {@link ConstantPoolVisitor#CONSTANT_Class} * @param value a boxed number, string, or class object * @throws IllegalArgumentException if the type of the constant does not * match the constant pool entry type, or if a class name contains * @see #putConstantValue(int, Object) * @see ConstantPoolVisitor#visitConstantValue(int, byte, Object) * @see ConstantPoolVisitor#visitConstantString(int, byte, String, int) // the JVM accepts any object as a patch for a string // make sure the incoming value is the right type /** Set the entry of the constant pool indexed by index to * a new {@link ConstantPoolVisitor#CONSTANT_NameAndType} value. * @param index an index to a constant pool entry containing a * {@link ConstantPoolVisitor#CONSTANT_NameAndType} value. * @param memberName a memberName * @param signature a signature * @throws IllegalArgumentException if memberName contains the character ';' * @see ConstantPoolVisitor#visitDescriptor(int, byte, String, String, int, int) /** Set the entry of the constant pool indexed by index to * a new {@link ConstantPoolVisitor#CONSTANT_Fieldref}, * {@link ConstantPoolVisitor#CONSTANT_Methodref}, or * {@link ConstantPoolVisitor#CONSTANT_InterfaceMethodref} value. * @param index an index to a constant pool entry containing a member reference * @param className a class name * @param memberName a field or method name * @param signature a field or method signature * @throws IllegalArgumentException if memberName contains the character ';' * or signature is not a correct signature * @see ConstantPoolVisitor#visitMemberRef(int, byte, String, String, String, int, int) for (
int i =
0; i <
count; i++) {