jdk/src/share/classes/com/sun/java/util/jar/pack/ClassWriter.java
author ksrini
Tue, 14 Dec 2010 07:42:11 -0800
changeset 7795 98021fc612af
parent 7192 445c518364c4
child 7816 55a18147b4bf
permissions -rw-r--r--
6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.* Reviewed-by: mduigou, briangoetz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
     2
 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.util.jar.pack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
7192
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    28
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    29
import com.sun.java.util.jar.pack.ConstantPool.Entry;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    30
import com.sun.java.util.jar.pack.ConstantPool.Index;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    31
import com.sun.java.util.jar.pack.ConstantPool.NumberEntry;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.java.util.jar.pack.Package.Class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.java.util.jar.pack.Package.InnerClass;
7192
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    34
import java.io.BufferedOutputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    35
import java.io.ByteArrayOutputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    36
import java.io.DataOutputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    37
import java.io.IOException;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    38
import java.io.OutputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    39
import java.util.Iterator;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    40
import java.util.List;
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
    41
import static com.sun.java.util.jar.pack.Constants.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Writer for a class file that is incorporated into a package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author John Rose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
    46
class ClassWriter {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    int verbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    Package pkg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    Class cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    DataOutputStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    Index cpIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    ClassWriter(Class cls, OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        this.pkg = cls.getPackage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        this.cls = cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        this.verbose = pkg.verbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.out = new DataOutputStream(new BufferedOutputStream(out));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.cpIndex = ConstantPool.makeIndex(cls.toString(), cls.getCPMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        this.cpIndex.flattenSigs = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (verbose > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            Utils.log.fine("local CP="+(verbose > 2 ? cpIndex.dumpString() : cpIndex.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private void writeShort(int x) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        out.writeShort(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private void writeInt(int x) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        out.writeInt(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /** Write a 2-byte int representing a CP entry, using the local cpIndex. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private void writeRef(Entry e) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        int i = (e == null) ? 0 : cpIndex.indexOf(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        writeShort(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    void write() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        boolean ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            if (verbose > 1)  Utils.log.fine("...writing "+cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            writeMagicNumbers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            writeConstantPool();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            writeHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            writeMembers(false);  // fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            writeMembers(true);   // methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            writeAttributes(ATTR_CONTEXT_CLASS, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            /* Closing here will cause all the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
               streams to close, Causing the jar stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
               to close prematurely, instead we just flush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
               out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (!ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                Utils.log.warning("Error on output of "+cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    void writeMagicNumbers() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        writeInt(cls.magic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        writeShort(cls.minver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        writeShort(cls.majver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    void writeConstantPool() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        Entry[] cpMap = cls.cpMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        writeShort(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            Entry e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            assert((e == null) == (i == 0 || cpMap[i-1] != null && cpMap[i-1].isDoubleWord()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            if (e == null)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            byte tag = e.getTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            if (verbose > 2)  Utils.log.fine("   CP["+i+"] = "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            out.write(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                case CONSTANT_Signature:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    assert(false);  // should not reach here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                case CONSTANT_Utf8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    out.writeUTF(e.stringValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    out.writeInt(((NumberEntry)e).numberValue().intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    float fval = ((NumberEntry)e).numberValue().floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    out.writeInt(Float.floatToRawIntBits(fval));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    out.writeLong(((NumberEntry)e).numberValue().longValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    double dval = ((NumberEntry)e).numberValue().doubleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    out.writeLong(Double.doubleToRawLongBits(dval));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                case CONSTANT_Class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                case CONSTANT_String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    writeRef(e.getRef(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                case CONSTANT_Fieldref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                case CONSTANT_Methodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                case CONSTANT_InterfaceMethodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                case CONSTANT_NameandType:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    writeRef(e.getRef(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    writeRef(e.getRef(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    throw new IOException("Bad constant pool tag "+tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    void writeHeader() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        writeShort(cls.flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        writeRef(cls.thisClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        writeRef(cls.superClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        writeShort(cls.interfaces.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        for (int i = 0; i < cls.interfaces.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            writeRef(cls.interfaces[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    void writeMembers(boolean doMethods) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        List mems;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (!doMethods)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            mems = cls.getFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            mems = cls.getMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        writeShort(mems.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        for (Iterator i = mems.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            Class.Member m = (Class.Member) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            writeMember(m, doMethods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    void writeMember(Class.Member m, boolean doMethod) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (verbose > 2)  Utils.log.fine("writeMember "+m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        writeShort(m.flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        writeRef(m.getDescriptor().nameRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        writeRef(m.getDescriptor().typeRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        writeAttributes(!doMethod ? ATTR_CONTEXT_FIELD : ATTR_CONTEXT_METHOD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    // handy buffer for collecting attrs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    ByteArrayOutputStream buf    = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    DataOutputStream      bufOut = new DataOutputStream(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    void writeAttributes(int ctype, Attribute.Holder h) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (h.attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            writeShort(0);  // attribute size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        writeShort(h.attributes.size());
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   199
        for (Attribute a : h.attributes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            a.finishRefs(cpIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            writeRef(a.getNameRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (a.layout() == Package.attrCodeEmpty ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                a.layout() == Package.attrInnerClassesEmpty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                // These are hardwired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                DataOutputStream savedOut = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                assert(out != bufOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                buf.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                out = bufOut;
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   209
                if ("Code".equals(a.name())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    Class.Method m = (Class.Method) h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    writeCode(m.code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    assert(h == cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    writeInnerClasses(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                out = savedOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                if (verbose > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    Utils.log.fine("Attribute "+a.name()+" ["+buf.size()+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                writeInt(buf.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                buf.writeTo(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                if (verbose > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    Utils.log.fine("Attribute "+a.name()+" ["+a.size()+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                writeInt(a.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                out.write(a.bytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    void writeCode(Code code) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        code.finishRefs(cpIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        writeShort(code.max_stack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        writeShort(code.max_locals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        writeInt(code.bytes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        out.write(code.bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        int nh = code.getHandlerCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        writeShort(nh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        for (int i = 0; i < nh; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
             writeShort(code.handler_start[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
             writeShort(code.handler_end[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
             writeShort(code.handler_catch[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
             writeRef(code.handler_class[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        writeAttributes(ATTR_CONTEXT_CODE, code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    void writeInnerClasses(Class cls) throws IOException {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   248
        List<InnerClass> ics = cls.getInnerClasses();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        writeShort(ics.size());
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   250
        for (InnerClass ic : ics) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            writeRef(ic.thisClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            writeRef(ic.outerClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            writeRef(ic.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            writeShort(ic.flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}