test/java/lang/reflect/Method/InterfaceStatic/StaticInterfaceMethodInWayOfDefault.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 25,43 **** * @test * @bug 8009411 * @summary Test that a static method on an interface doesn't hide a default * method with the same name and signature in a separate compilation * scenario. */ import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.concurrent.Callable; ! import sun.misc.IOUtils; public class StaticInterfaceMethodInWayOfDefault { public interface A_v1 { } --- 25,46 ---- * @test * @bug 8009411 * @summary Test that a static method on an interface doesn't hide a default * method with the same name and signature in a separate compilation * scenario. + * @library /lib/testlibrary + * @build jdk.testlibrary.IOUtils + * @run main StaticInterfaceMethodInWayOfDefault */ import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.concurrent.Callable; ! import jdk.testlibrary.IOUtils; public class StaticInterfaceMethodInWayOfDefault { public interface A_v1 { }
*** 142,152 **** if (name.endsWith("_v1")) { String altName = name.substring(0, name.length() - 3) + "_v2"; String altPath = altName.replace('.', '/').concat(".class"); try (InputStream is = getResourceAsStream(altPath)) { if (is != null) { ! byte[] bytes = IOUtils.readFully(is, -1, true); // patch class bytes to contain original name for (int i = 0; i < bytes.length - 2; i++) { if (bytes[i] == '_' && bytes[i + 1] == 'v' && bytes[i + 2] == '2') { --- 145,155 ---- if (name.endsWith("_v1")) { String altName = name.substring(0, name.length() - 3) + "_v2"; String altPath = altName.replace('.', '/').concat(".class"); try (InputStream is = getResourceAsStream(altPath)) { if (is != null) { ! byte[] bytes = IOUtils.readFully(is); // patch class bytes to contain original name for (int i = 0; i < bytes.length - 2; i++) { if (bytes[i] == '_' && bytes[i + 1] == 'v' && bytes[i + 2] == '2') {
*** 165,175 **** } else { // not special class name -> just load the class String path = name.replace('.', '/').concat(".class"); try (InputStream is = getResourceAsStream(path)) { if (is != null) { ! byte[] bytes = IOUtils.readFully(is, -1, true); return defineClass(name, bytes, 0, bytes.length); } else { throw new ClassNotFoundException(name); } --- 168,178 ---- } else { // not special class name -> just load the class String path = name.replace('.', '/').concat(".class"); try (InputStream is = getResourceAsStream(path)) { if (is != null) { ! byte[] bytes = IOUtils.readFully(is); return defineClass(name, bytes, 0, bytes.length); } else { throw new ClassNotFoundException(name); }