1 #!/bin/sh
   2 
   3 #
   4 # Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6 #
   7 # This code is free software; you can redistribute it and/or modify it
   8 # under the terms of the GNU General Public License version 2 only, as
   9 # published by the Free Software Foundation.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 # @test
  27 # @bug 8031195
  28 # @summary JDB allows evaluation of calls to static interface methods
  29 # @author Jaroslav Bachorik
  30 #
  31 # @run shell/timeout=300 EvalInterfaceStatic.sh
  32 
  33 #  The test exercises the ability to invoke static methods on interfaces.
  34 #  Static interface methods are a new feature added in JDK8.
  35 #
  36 #  The test makes sure that it is, at all, possible to invoke an interface
  37 #  static method and that the static methods are not inherited by extending
  38 #  interfaces.
  39 
  40 classname=EvalStaticInterfaces
  41 
  42 createJavaFile()
  43 {
  44     cat <<EOF > $classname.java.1
  45 public interface $classname {
  46     static String staticMethod1() {
  47         return "base:staticMethod1";
  48     }
  49 
  50     static String staticMethod2() {
  51         return "base:staticMethod2";
  52     }
  53 
  54     public static void main(String[] args) {
  55         // prove that these work
  56         System.out.println("base staticMethod1(): " + $classname.staticMethod1());
  57         System.out.println("base staticMethod2(): " + $classname.staticMethod2());
  58         System.out.println("overridden staticMethod2(): " + Extended$classname.staticMethod2());
  59         System.out.println("base staticMethod3(): " + Extended$classname.staticMethod3());
  60 
  61         gus();
  62     }
  63 
  64     static void gus() {
  65         int x = 0;             // @1 breakpoint
  66     }
  67 }
  68 
  69 interface Extended$classname extends $classname {
  70     static String staticMethod2() {
  71         return "extended:staticMethod2";
  72     }
  73 
  74     static String staticMethod3() {
  75         return "extended:staticMethod3";
  76     }
  77 }
  78 
  79 
  80 
  81 EOF
  82 }
  83 
  84 # drive jdb by sending cmds to it and examining its output
  85 dojdbCmds()
  86 {
  87     setBkpts @1
  88     runToBkpt @1
  89 
  90     cmd eval "$classname.staticMethod1()"
  91     jdbFailIfNotPresent "base:staticMethod1" 2
  92 
  93     cmd eval "$classname.staticMethod2()"
  94     jdbFailIfNotPresent "base:staticMethod2" 2
  95 
  96     cmd eval "Extended$classname.staticMethod1()"
  97     jdbFailIfPresent "base:staticMethod1" 2
  98 
  99     cmd eval "Extended$classname.staticMethod2()"
 100     jdbFailIfNotPresent "extended:staticMethod2" 2
 101 
 102     cmd eval "Extended$classname.staticMethod3()"
 103     jdbFailIfNotPresent "extended:staticMethod3" 2
 104 }
 105 
 106 
 107 mysetup()
 108 {
 109     if [ -z "$TESTSRC" ] ; then
 110         TESTSRC=.
 111     fi
 112 
 113     for ii in . $TESTSRC $TESTSRC/.. ; do
 114         if [ -r "$ii/ShellScaffold.sh" ] ; then
 115             . $ii/ShellScaffold.sh
 116             break
 117         fi
 118     done
 119 }
 120 
 121 # You could replace this next line with the contents
 122 # of ShellScaffold.sh and this script will run just the same.
 123 mysetup
 124 
 125 runit
 126 pass