Java Code Examples for sun.invoke.util.Wrapper#zero()
The following examples show how to use
sun.invoke.util.Wrapper#zero() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueConversionsTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 2
Source File: ValueConversionsTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 3
Source File: ValueConversionsTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 4
Source File: ValueConversionsTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 5
Source File: ValueConversionsTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 6
Source File: ValueConversionsTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 7
Source File: ValueConversionsTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 8
Source File: ValueConversionsTest.java From hottub with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 9
Source File: ValueConversionsTest.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst.primitiveType()); else unboxer = ValueConversions.unbox(dst.primitiveType()); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case OBJECT: result = (Object) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; case VOID: result = null; unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 10
Source File: ValueConversionsTest.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst.primitiveType()); else unboxer = ValueConversions.unbox(dst.primitiveType()); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case OBJECT: result = (Object) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; case VOID: result = null; unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 11
Source File: ValueConversionsTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 12
Source File: ValueConversionsTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }
Example 13
Source File: ValueConversionsTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable { boolean expectThrow = !doCast && !dst.isConvertibleFrom(src); if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT) return; // must have prims if (dst == Wrapper.VOID || src == Wrapper.VOID ) return; // must have values if (dst == Wrapper.OBJECT) expectThrow = false; // everything (even VOID==null here) converts to OBJECT try { for (int n = -5; n < 10; n++) { Object box = src.wrap(n); switch (src) { case VOID: assertEquals(box, null); break; case OBJECT: box = box.toString(); break; case SHORT: assertEquals(box.getClass(), Short.class); break; default: assertEquals(box.getClass(), src.wrapperType()); break; } MethodHandle unboxer; if (doCast) unboxer = ValueConversions.unboxCast(dst); else unboxer = ValueConversions.unboxWiden(dst); Object expResult = (box == null) ? dst.zero() : dst.wrap(box); Object result = null; switch (dst) { case INT: result = (int) unboxer.invokeExact(box); break; case LONG: result = (long) unboxer.invokeExact(box); break; case FLOAT: result = (float) unboxer.invokeExact(box); break; case DOUBLE: result = (double) unboxer.invokeExact(box); break; case CHAR: result = (char) unboxer.invokeExact(box); break; case BYTE: result = (byte) unboxer.invokeExact(box); break; case SHORT: result = (short) unboxer.invokeExact(box); break; case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break; } if (expectThrow) { expResult = "(need an exception)"; } assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box), expResult, result); } } catch (RuntimeException ex) { if (expectThrow) return; System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src)); throw ex; } }