Path: blob/master/test/jdk/com/sun/jdi/EvalInterfaceStatic.java
41149 views
/*1* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 803119526* @summary JDB allows evaluation of calls to static interface methods27* @comment converted from test/jdk/com/sun/jdi/EvalInterfaceStatic.sh28*29* @library /test/lib30* @build EvalInterfaceStatic31* @run main/othervm EvalInterfaceStatic32*/3334import lib.jdb.JdbCommand;35import lib.jdb.JdbTest;3637/*38* The test exercises the ability to invoke static methods on interfaces.39* Static interface methods are a new feature added in JDK8.40*41* The test makes sure that it is possible to invoke an interface42* static method and that the static methods are not inherited by extending43* interfaces.44*/45interface EvalStaticInterfaces {46static String staticMethod1() {47return "base:staticMethod1";48}4950static String staticMethod2() {51return "base:staticMethod2";52}5354public static void main(String[] args) {55// prove that these work56System.out.println("base staticMethod1(): " + EvalStaticInterfaces.staticMethod1());57System.out.println("base staticMethod2(): " + EvalStaticInterfaces.staticMethod2());58System.out.println("overridden staticMethod2(): " + ExtendedEvalStaticInterfaces.staticMethod2());59System.out.println("base staticMethod3(): " + ExtendedEvalStaticInterfaces.staticMethod3());6061gus();62}6364static void gus() {65int x = 0; // @1 breakpoint66}67}6869interface ExtendedEvalStaticInterfaces extends EvalStaticInterfaces {70static String staticMethod2() {71return "extended:staticMethod2";72}7374static String staticMethod3() {75return "extended:staticMethod3";76}77}787980public class EvalInterfaceStatic extends JdbTest {81public static void main(String argv[]) {82new EvalInterfaceStatic().run();83}8485private EvalInterfaceStatic() {86super(DEBUGGEE_CLASS);87}8889private static final String DEBUGGEE_CLASS = EvalStaticInterfaces.class.getName();9091@Override92protected void runCases() {93setBreakpointsFromTestSource("EvalInterfaceStatic.java", 1);94// Run to breakpoint #195jdb.command(JdbCommand.run());9697evalShouldContain("EvalStaticInterfaces.staticMethod1()", "base:staticMethod1");9899evalShouldContain("EvalStaticInterfaces.staticMethod2()", "base:staticMethod2");100101evalShouldNotContain("ExtendedEvalStaticInterfaces.staticMethod1()", "base:staticMethod1");102103evalShouldContain("ExtendedEvalStaticInterfaces.staticMethod2()", "extended:staticMethod2");104105evalShouldContain("ExtendedEvalStaticInterfaces.staticMethod3()", "extended:staticMethod3");106107jdb.contToExit(1);108}109110}111112113