Home | History | Annotate | Download | only in Events
      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.Events;
     20 
     21 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     22 import org.apache.harmony.jpda.tests.share.SyncDebuggee;
     23 
     24 /**
     25  * Debuggee for {@link EventWithExceptionTest} class.
     26  */
     27 public class EventWithExceptionDebuggee extends SyncDebuggee {
     28     // Field used to test FIELD_ACCESS and FIELD_WATCHPOINT events.
     29     public static int watchedField = 0;
     30 
     31     // Exception class for EXCEPTION event.
     32     static final class TestException extends Exception {
     33     }
     34 
     35     public int catchMethod() {
     36         try {
     37             syncAndThrow();
     38         } catch (TestException e) {
     39             logWriter.println("Expected exception: " + e);  // SINGLE-STEP & BREAKPOINT
     40         }
     41         watchedField = 10;                                  // FIELD_MODIFICATION
     42         int result = watchedField;                          // FIELD_ACCESS
     43         return result;                                      // METHOD_EXIT[WITH_RETURN_VALUE]
     44     }
     45 
     46     public void syncAndThrow() throws TestException {
     47         syncAndThrowImpl();
     48     }
     49 
     50     public void syncAndThrowImpl() throws TestException {
     51         sync();
     52         throw new TestException();
     53     }
     54 
     55     private void sync() {
     56         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     57         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     58     }
     59 
     60     @SuppressWarnings("DeadException")
     61     @Override
     62     public void run() {
     63         // Cause class loading so that it is visible from the test.
     64         new TestException();
     65 
     66         // First run to capture catch handler location (if necessary).
     67         catchMethod();
     68 
     69         // Second run for testing.
     70         catchMethod();
     71 
     72         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     73     }
     74 
     75     public static void main(String[] args) {
     76         runDebuggee(EventWithExceptionDebuggee.class);
     77     }
     78 }
     79