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 InvokeMethodDefault002Debuggee extends SyncDebuggee { 25 26 /** 27 * Interface defining the default method to be invoked. 28 */ 29 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 overriding class we will initialize to call the default method. 46 */ 47 static class TestClass implements TestInterface { 48 public static final int RETURN_VALUE = 456; 49 @Override 50 public int testDefaultMethod(boolean shouldThrow) throws Throwable { 51 if (shouldThrow) { 52 throw new Throwable("testDefaultMethod"); 53 } 54 return TestClass.RETURN_VALUE; 55 } 56 } 57 58 // The instance used to invoke "TestClass.testMethod". 59 static TestClass invokeReceiver = new TestClass(); 60 61 void execMethod() { 62 logWriter.println("InvokeMethodDefault002Debuggee.execMethod()"); 63 } 64 65 @Override 66 public void run() { 67 // Preload TestClass so it is available during the test. 68 @SuppressWarnings("unused") 69 Class<?> c = null; 70 String packageName = "org.apache.harmony.jpda.tests.jdwp."; 71 try { 72 c = Class.forName( 73 packageName + "ObjectReference.InvokeMethodDefault002Debuggee$TestClass"); 74 } catch (ClassNotFoundException e) { 75 e.printStackTrace(); 76 } 77 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 78 logWriter.println("InvokeMethodDefault002Debuggee"); 79 synchronizer.receiveMessageWithoutException( 80 packageName + "ObjectReference.InvokeMethodDefault002Debuggee(#1)"); 81 execMethod(); 82 synchronizer.receiveMessageWithoutException( 83 packageName + "ObjectReference.InvokeMethodDefault002Debuggee(#2)"); 84 } 85 86 public static void main(String[] args) { 87 runDebuggee(InvokeMethodDefault002Debuggee.class); 88 } 89 } 90 91