Mon, 28 Feb 2011 11:48:53 +0000
7015430: Incorrect thrown type determined for unchecked invocations
Summary: Thrown types do not get updated after 15.12.2.8, and do not get erased as per 15.12.2.6
Reviewed-by: jjg, dlsmith
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javac.util; |
duke@1 | 27 | |
duke@1 | 28 | import java.io.*; |
duke@1 | 29 | |
duke@1 | 30 | /** A byte buffer is a flexible array which grows when elements are |
duke@1 | 31 | * appended. There are also methods to append names to byte buffers |
duke@1 | 32 | * and to convert byte buffers to names. |
duke@1 | 33 | * |
jjg@581 | 34 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 35 | * If you write code that depends on this, you do so at your own risk. |
duke@1 | 36 | * This code and its internal interfaces are subject to change or |
duke@1 | 37 | * deletion without notice.</b> |
duke@1 | 38 | */ |
duke@1 | 39 | public class ByteBuffer { |
duke@1 | 40 | |
duke@1 | 41 | /** An array holding the bytes in this buffer; can be grown. |
duke@1 | 42 | */ |
duke@1 | 43 | public byte[] elems; |
duke@1 | 44 | |
duke@1 | 45 | /** The current number of defined bytes in this buffer. |
duke@1 | 46 | */ |
duke@1 | 47 | public int length; |
duke@1 | 48 | |
duke@1 | 49 | /** Create a new byte buffer. |
duke@1 | 50 | */ |
duke@1 | 51 | public ByteBuffer() { |
duke@1 | 52 | this(64); |
duke@1 | 53 | } |
duke@1 | 54 | |
duke@1 | 55 | /** Create a new byte buffer with an initial elements array |
duke@1 | 56 | * of given size. |
duke@1 | 57 | */ |
duke@1 | 58 | public ByteBuffer(int initialSize) { |
duke@1 | 59 | elems = new byte[initialSize]; |
duke@1 | 60 | length = 0; |
duke@1 | 61 | } |
duke@1 | 62 | |
duke@1 | 63 | private void copy(int size) { |
duke@1 | 64 | byte[] newelems = new byte[size]; |
duke@1 | 65 | System.arraycopy(elems, 0, newelems, 0, elems.length); |
duke@1 | 66 | elems = newelems; |
duke@1 | 67 | } |
duke@1 | 68 | |
duke@1 | 69 | /** Append byte to this buffer. |
duke@1 | 70 | */ |
duke@1 | 71 | public void appendByte(int b) { |
duke@1 | 72 | if (length >= elems.length) copy(elems.length * 2); |
duke@1 | 73 | elems[length++] = (byte)b; |
duke@1 | 74 | } |
duke@1 | 75 | |
duke@1 | 76 | /** Append `len' bytes from byte array, |
duke@1 | 77 | * starting at given `start' offset. |
duke@1 | 78 | */ |
duke@1 | 79 | public void appendBytes(byte[] bs, int start, int len) { |
duke@1 | 80 | while (length + len > elems.length) copy(elems.length * 2); |
duke@1 | 81 | System.arraycopy(bs, start, elems, length, len); |
duke@1 | 82 | length += len; |
duke@1 | 83 | } |
duke@1 | 84 | |
duke@1 | 85 | /** Append all bytes from given byte array. |
duke@1 | 86 | */ |
duke@1 | 87 | public void appendBytes(byte[] bs) { |
duke@1 | 88 | appendBytes(bs, 0, bs.length); |
duke@1 | 89 | } |
duke@1 | 90 | |
duke@1 | 91 | /** Append a character as a two byte number. |
duke@1 | 92 | */ |
duke@1 | 93 | public void appendChar(int x) { |
duke@1 | 94 | while (length + 1 >= elems.length) copy(elems.length * 2); |
duke@1 | 95 | elems[length ] = (byte)((x >> 8) & 0xFF); |
duke@1 | 96 | elems[length+1] = (byte)((x ) & 0xFF); |
duke@1 | 97 | length = length + 2; |
duke@1 | 98 | } |
duke@1 | 99 | |
duke@1 | 100 | /** Append an integer as a four byte number. |
duke@1 | 101 | */ |
duke@1 | 102 | public void appendInt(int x) { |
duke@1 | 103 | while (length + 3 >= elems.length) copy(elems.length * 2); |
duke@1 | 104 | elems[length ] = (byte)((x >> 24) & 0xFF); |
duke@1 | 105 | elems[length+1] = (byte)((x >> 16) & 0xFF); |
duke@1 | 106 | elems[length+2] = (byte)((x >> 8) & 0xFF); |
duke@1 | 107 | elems[length+3] = (byte)((x ) & 0xFF); |
duke@1 | 108 | length = length + 4; |
duke@1 | 109 | } |
duke@1 | 110 | |
duke@1 | 111 | /** Append a long as an eight byte number. |
duke@1 | 112 | */ |
duke@1 | 113 | public void appendLong(long x) { |
duke@1 | 114 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(8); |
duke@1 | 115 | DataOutputStream bufout = new DataOutputStream(buffer); |
duke@1 | 116 | try { |
duke@1 | 117 | bufout.writeLong(x); |
duke@1 | 118 | appendBytes(buffer.toByteArray(), 0, 8); |
duke@1 | 119 | } catch (IOException e) { |
duke@1 | 120 | throw new AssertionError("write"); |
duke@1 | 121 | } |
duke@1 | 122 | } |
duke@1 | 123 | |
duke@1 | 124 | /** Append a float as a four byte number. |
duke@1 | 125 | */ |
duke@1 | 126 | public void appendFloat(float x) { |
duke@1 | 127 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(4); |
duke@1 | 128 | DataOutputStream bufout = new DataOutputStream(buffer); |
duke@1 | 129 | try { |
duke@1 | 130 | bufout.writeFloat(x); |
duke@1 | 131 | appendBytes(buffer.toByteArray(), 0, 4); |
duke@1 | 132 | } catch (IOException e) { |
duke@1 | 133 | throw new AssertionError("write"); |
duke@1 | 134 | } |
duke@1 | 135 | } |
duke@1 | 136 | |
duke@1 | 137 | /** Append a double as a eight byte number. |
duke@1 | 138 | */ |
duke@1 | 139 | public void appendDouble(double x) { |
duke@1 | 140 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(8); |
duke@1 | 141 | DataOutputStream bufout = new DataOutputStream(buffer); |
duke@1 | 142 | try { |
duke@1 | 143 | bufout.writeDouble(x); |
duke@1 | 144 | appendBytes(buffer.toByteArray(), 0, 8); |
duke@1 | 145 | } catch (IOException e) { |
duke@1 | 146 | throw new AssertionError("write"); |
duke@1 | 147 | } |
duke@1 | 148 | } |
duke@1 | 149 | |
duke@1 | 150 | /** Append a name. |
duke@1 | 151 | */ |
duke@1 | 152 | public void appendName(Name name) { |
jjg@113 | 153 | appendBytes(name.getByteArray(), name.getByteOffset(), name.getByteLength()); |
duke@1 | 154 | } |
duke@1 | 155 | |
duke@1 | 156 | /** Reset to zero length. |
duke@1 | 157 | */ |
duke@1 | 158 | public void reset() { |
duke@1 | 159 | length = 0; |
duke@1 | 160 | } |
duke@1 | 161 | |
duke@1 | 162 | /** Convert contents to name. |
duke@1 | 163 | */ |
jjg@113 | 164 | public Name toName(Names names) { |
duke@1 | 165 | return names.fromUtf(elems, 0, length); |
duke@1 | 166 | } |
duke@1 | 167 | } |