#!/bin/java bsh.Interpreter source("TestHarness.bsh"); /** Make sure that scripts can catch all of the runtime exceptions that we might cause during the evaluation of script... This means that these must be caught by us and wrapped in TargetException. These haven't been done/checked yet: /pkg/java/src//java/lang/IllegalMonitorStateException.java /pkg/java/src//java/lang/InterruptedException.java */ // /pkg/java/src//java/lang/ArithmeticException.java try { int i=1/0; } catch ( ArithmeticException e ) { flag(); } // /pkg/java/src//java/lang/ClassCastException.java try { ((String)(new Object())); } catch ( ClassCastException e2 ) { flag(); } // Should *not* be able to catch ClassNotFoundException when class names are // used directly in the script. These indicate a structural or missing class // in the expected environment and should cause evaluation to stop. // /pkg/java/src//java/lang/ClassNotFoundException assert( isEvalError("try { new Booga123(); } catch ( ClassNotFoundException e2 ) { }") ); // // Should be able to catch real target ClassNotFoundException generated by // method calls that throw it. // Note: at time of writing Class.forName() doesn't see extended path and we'd // want getClass() instead. try { Class.forName("Booga123"); } catch ( ClassNotFoundException e2 ) { flag(); }; /* // Shouldn't catch class not found indicating structural problems with // the script (e.g. typed var declaration, direct useage etc.) assert( isEvalError("try { Booga123 booga; } catch ( ClassNotFoundException e2 ) { }") ); assert( isEvalError("try { Booga123.foo=5; } catch ( ClassNotFoundException e2 ) { }") ); */ // /pkg/java/src//java/lang/ArrayIndexOutOfBoundsException.java try { a=new String[5]; a[99]; } catch ( ArrayIndexOutOfBoundsException e3 ) { flag(); } // /pkg/java/src//java/lang/NegativeArraySizeException.java try { a=new String[-1]; } catch ( NegativeArraySizeException e4 ) { flag(); } // /pkg/java/src//java/lang/ArrayStoreException.java try { sa=new String[5]; sa[0] = new Integer(0); } catch ( ArrayStoreException e5 ) { flag(); } // /pkg/java/src//java/lang/NullPointerException.java try { foo = null; foo.bar; } catch ( NullPointerException e6 ) { flag(); } // /pkg/java/src//java/lang/NullPointerException.java try { foo = null; foo.bar(); } catch ( NullPointerException e7) { flag(); } assert( flag() == 8 ); complete();