/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4990346
* @summary Verify autoboxed values are cached as required.
* @author Joseph D. Darcy
*/
public class BoxingCaching {
static boolean verifyBooleanCaching() {
boolean cached = true;
results[0] = false;
results[1] = true;
Boolean B;
B = false;
if (B != results[0]) {
cached = false;
" is not cached appropriately.");
}
B = true;
if (B != results[1]) {
cached = false;
" is not cached appropriately.");
}
return cached;
}
static boolean verifyByteCaching() {
boolean cached = true;
results[i] = (byte)(i-128);
Byte B = (byte)(i-128);
if (B != results[i]) {
cached = false;
" is not cached appropriately.");
}
}
Byte B;
B = (byte)i;
if (B.byteValue() != i) {
cached = false;
"byte value " + i + " .");
}
}
return cached;
}
static boolean verifyCharacterCaching() {
boolean cached = true;
results[i] = (char)i;
Character C = (char)i;
if (C != results[i]) {
cached = false;
" is not cached appropriately.");
}
}
Character C;
C = (char)i;
if (C.charValue() != i) {
cached = false;
"char value " + i + " .");
}
}
return cached;
}
static boolean verifyIntegerCaching() {
boolean cached = true;
results[i] = (i-128);
Integer I = (i-128);
if (I != results[i]) {
cached = false;
" is not cached appropriately.");
}
}
for(int i = -256; i < 255; i++) {
Integer I;
I = i;
if (I.intValue() != i) {
cached = false;
"int value " + i + " .");
}
}
return cached;
}
static boolean verifyLongCaching() {
boolean cached = true;
results[i] = (long)(i-128);
Long L = (long)(i-128);
if (L != results[i]) {
cached = false;
" is not cached appropriately.");
}
}
for(int i = -256; i < 255; i++) {
Integer L;
L = i;
if (L.longValue() != i) {
cached = false;
"int value " + i + " .");
}
}
return cached;
}
static boolean verifyShortCaching() {
boolean cached = true;
results[i] = (short)(i-128);
Short S = (short)(i-128);
if (S != results[i]) {
cached = false;
" is not cached appropriately.");
}
}
Short S;
S = (short)i;
if (S.shortValue() != i) {
cached = false;
"short value " + i + " .");
}
}
return cached;
}
boolean cached = true;
cached &= verifyBooleanCaching();
cached &= verifyByteCaching();
cached &= verifyCharacterCaching();
cached &= verifyIntegerCaching();
cached &= verifyLongCaching();
cached &= verifyShortCaching();
if (!cached)
throw new RuntimeException("Values not cached appropriately.");
}
}