test/hotspot/jtreg/vmTestbase/nsk/stress/except/except004.java
changeset 50735 2f2af62dfac7
parent 50169 dd501973095c
child 52640 3a7d49718852
equal deleted inserted replaced
50734:0828a0f6676b 50735:2f2af62dfac7
   209         // Prepare some items, which will be used by the test:
   209         // Prepare some items, which will be used by the test:
   210         Object stringArray[] = new String[1];
   210         Object stringArray[] = new String[1];
   211         Object integerValue = new Integer(0);
   211         Object integerValue = new Integer(0);
   212         Object doubleValue = new Double(0);
   212         Object doubleValue = new Double(0);
   213         Object trash = null;
   213         Object trash = null;
   214         Field abraPrivateField;
       
   215         Field abraIntegerField;
   214         Field abraIntegerField;
   216         Field abraBooleanField;
   215         Field abraBooleanField;
   217         try {
   216         Field extPrivateField;
   218             abraPrivateField = Abra.class.getDeclaredField("DONT_TOUCH_ME");
   217         try {
   219             abraIntegerField = Abra.class.getDeclaredField("MAIN_CYR_NUMBER");
   218             abraIntegerField = Abra.class.getDeclaredField("MAIN_CYR_NUMBER");
   220             abraBooleanField = Abra.class.getDeclaredField("NOT_AN_INTEGER");
   219             abraBooleanField = Abra.class.getDeclaredField("NOT_AN_INTEGER");
       
   220             extPrivateField = Ext.class.getDeclaredField("DONT_TOUCH_ME");
   221         } catch (NoSuchFieldException nsfe) {
   221         } catch (NoSuchFieldException nsfe) {
   222             out.println("Test initialisation failed: field not found in class Abra");
   222             out.println("Test initialisation failed: field not found: " + nsfe.getMessage());
   223             return 2;
   223             return 2;
   224         }
   224         }
   225 
   225 
   226         Abra abra = new Abra("via public constructor");
   226         Abra abra = new Abra("via public constructor");
   227         Abra.Cadabra cadabra = new Abra.Cadabra();
   227         Abra.Cadabra cadabra = new Abra.Cadabra();
   367         }
   367         }
   368 
   368 
   369         // Check IllegalAccessException (positive):
   369         // Check IllegalAccessException (positive):
   370         try {
   370         try {
   371             int junkIt = abraIntegerField.getInt(null); //   legal - should pass
   371             int junkIt = abraIntegerField.getInt(null); //   legal - should pass
   372 //          int junkIt = abraPrivateField.getInt(null); // illegal - should fail
       
   373             if (TRACE_ON)
   372             if (TRACE_ON)
   374                 log[messages++] = "Success: IllegalAccessException (positive)";
   373                 log[messages++] = "Success: IllegalAccessException (positive)";
   375         } catch (IllegalAccessException iae) {
   374         } catch (IllegalAccessException iae) {
   376             log[messages++] = "Failure: IllegalAccessException (positive)";
   375             log[messages++] = "Failure: IllegalAccessException (positive)";
   377             exitCode = 2;
   376             exitCode = 2;
   381             skipped++;
   380             skipped++;
   382         }
   381         }
   383 
   382 
   384         // Check IllegalAccessException (negative):
   383         // Check IllegalAccessException (negative):
   385         try {
   384         try {
   386 //          int junkIt = abraIntegerField.getInt(null); //   legal - should pass
   385             int junkIt = extPrivateField.getInt(null); // illegal - should fail
   387             int junkIt = abraPrivateField.getInt(null); // illegal - should fail
       
   388             log[messages++] = "Failure: IllegalAccessException (negative)";
   386             log[messages++] = "Failure: IllegalAccessException (negative)";
   389             exitCode = 2; // FAILED
   387             exitCode = 2; // FAILED
   390         } catch (IllegalAccessException iae) {
   388         } catch (IllegalAccessException iae) {
   391             if (TRACE_ON)
   389             if (TRACE_ON)
   392                 log[messages++] = "Success: IllegalAccessException (negative)";
   390                 log[messages++] = "Success: IllegalAccessException (negative)";
   510         // JCK-like exit status.
   508         // JCK-like exit status.
   511     }
   509     }
   512 
   510 
   513     /**
   511     /**
   514      * This class should be used to check <code>CloneNotSupportedException</code>,
   512      * This class should be used to check <code>CloneNotSupportedException</code>,
   515      * <code>IllegalAccessException</code>, and <code>IllegalArgumentException</code>.
   513      * and <code>IllegalArgumentException</code>.
   516      * The class extends <code>except004</code> in order that its (protected)
   514      * The class extends <code>except004</code> in order that its (protected)
   517      * method <code>clone()</code> be available from <code>except004</code>.
   515      * method <code>clone()</code> be available from <code>except004</code>.
   518      */
   516      */
   519     private static class Abra extends except004 {
   517     private static class Abra extends except004 {
   520         /**
   518         /**
   522          * instead of <code>Abra$Cadabra</code>.
   520          * instead of <code>Abra$Cadabra</code>.
   523          */
   521          */
   524         public static class Cadabra implements Cloneable {
   522         public static class Cadabra implements Cloneable {
   525         }
   523         }
   526 
   524 
   527         /**
       
   528          * Will try to incorrectly access to this field from outside this class.
       
   529          */
       
   530         private static final int DONT_TOUCH_ME = 666;
       
   531         /**
   525         /**
   532          * Will try to incorrectly access to this field from outside this class.
   526          * Will try to incorrectly access to this field from outside this class.
   533          */
   527          */
   534         public static final int MAIN_CYR_NUMBER = 47;
   528         public static final int MAIN_CYR_NUMBER = 47;
   535         /**
   529         /**
   549          */
   543          */
   550         public Abra(String nothingSpecial) {
   544         public Abra(String nothingSpecial) {
   551         }
   545         }
   552     }
   546     }
   553 }
   547 }
       
   548 
       
   549 /* Package accessible class that has non-accessible private member */
       
   550 class Ext {
       
   551     /**
       
   552      * Will try to incorrectly access to this field from outside this class.
       
   553      */
       
   554     private static final int DONT_TOUCH_ME = 666;
       
   555 }