1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.harmony.jpda.tests.jdwp.ObjectReference; 20 21 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 22 import org.apache.harmony.jpda.tests.share.SyncDebuggee; 23 24 public class InvokeMethodDefaultDebuggee extends SyncDebuggee { 25 26 /** 27 * Interface defining the default method to be invoked. 28 */ 29 public static interface TestInterface { 30 public static final int RETURN_VALUE = 123; 31 /** 32 * Method invoked for test 33 * @param shouldThrow throws if the value is true. 34 * @return the value 123 35 */ 36 public default int testDefaultMethod(boolean shouldThrow) throws Throwable { 37 if (shouldThrow) { 38 throw new Throwable("testDefaultMethod"); 39 } 40 return TestInterface.RETURN_VALUE; 41 } 42 } 43 44 /** 45 * The empty class we will initialize to call the default method. 46 */ 47 public static class TestClass implements TestInterface { 48 } 49 50 // The instance used to invoke "TestClass.testMethod". 51 static TestClass invokeReceiver = new TestClass(); 52 53 void execMethod() { 54 logWriter.println("InvokeMethodDefaultDebuggee.execMethod()"); 55 } 56 57 @Override 58 public void run() { 59 // Preload TestClass so it is available during the test. 60 @SuppressWarnings("unused") 61 Class<?> c = null; 62 String packageName = "org.apache.harmony.jpda.tests.jdwp."; 63 try { 64 c = Class.forName( 65 packageName + "ObjectReference.InvokeMethodDefaultDebuggee$TestClass"); 66 } catch (ClassNotFoundException e) { 67 e.printStackTrace(); 68 } 69 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 70 logWriter.println("InvokeMethodDefaultDebuggee"); 71 synchronizer.receiveMessageWithoutException( 72 packageName + "ObjectReference.InvokeMethodDefaultDebuggee(#1)"); 73 execMethod(); 74 synchronizer.receiveMessageWithoutException( 75 packageName + "ObjectReference.InvokeMethodDefaultDebuggee(#2)"); 76 } 77 78 public static void main(String[] args) { 79 runDebuggee(InvokeMethodDefaultDebuggee.class); 80 } 81 } 82 83