Esempio n. 1
0
  /*
   * Validate that readObject returns the correct value when a Struct is
   * next on the stream
   */
  @Test()
  public void test11() throws Exception {
    Object[] attributes = new Object[] {"Bruce", "Wayne", 1939, "Batman"};
    map.put(sqlType, Class.forName("util.SuperHero"));
    Struct struct = new StubStruct(sqlType, attributes);
    Object[] values = {struct};
    SQLInputImpl sqli = new SQLInputImpl(values, map);
    Object o = sqli.readObject();

    assertTrue(hero.equals(o));
  }
  // Test to ensure that the inference verifier accepts older classfiles
  // with classes that implement interfaces with defaults.
  @Test(groups = "vm")
  public void testInferenceVerifier() {
    // interface I { int m() default { return 99; } }
    byte I_bytes[] = {
      (byte) 0xca,
      (byte) 0xfe,
      (byte) 0xba,
      (byte) 0xbe,
      0x00,
      0x00,
      0x00,
      0x34,
      0x00,
      0x08,
      0x07,
      0x00,
      0x06,
      0x07,
      0x00,
      0x07,
      0x01,
      0x00,
      0x03,
      0x66,
      0x6f,
      0x6f,
      0x01,
      0x00,
      0x03,
      0x28,
      0x29,
      0x49,
      0x01,
      0x00,
      0x04,
      0x43,
      0x6f,
      0x64,
      0x65,
      0x01,
      0x00,
      0x01,
      0x49,
      0x01,
      0x00,
      0x10,
      0x6a,
      0x61,
      0x76,
      0x61,
      0x2f,
      0x6c,
      0x61,
      0x6e,
      0x67,
      0x2f,
      0x4f,
      0x62,
      0x6a,
      0x65,
      0x63,
      0x74,
      0x06,
      0x00,
      0x00,
      0x01,
      0x00,
      0x02,
      0x00,
      0x00,
      0x00,
      0x00,
      0x00,
      0x01,
      0x02,
      0x01,
      0x00,
      0x03,
      0x00,
      0x04,
      0x00,
      0x01,
      0x00,
      0x05,
      0x00,
      0x00,
      0x00,
      0x0f,
      0x00,
      0x01,
      0x00,
      0x01,
      0x00,
      0x00,
      0x00,
      0x03,
      0x10,
      0x63,
      (byte) 0xac,
      0x00,
      0x00,
      0x00,
      0x00,
      0x00,
      0x00
    };
    // public class C implements I {}  /* -target 1.5 */
    byte C_bytes[] = {
      (byte) 0xca,
      (byte) 0xfe,
      (byte) 0xba,
      (byte) 0xbe,
      0x00,
      0x00,
      0x00,
      0x31,
      0x00,
      0x0c,
      0x0a,
      0x00,
      0x03,
      0x00,
      0x08,
      0x07,
      0x00,
      0x09,
      0x07,
      0x00,
      0x0a,
      0x07,
      0x00,
      0x0b,
      0x01,
      0x00,
      0x06,
      0x3c,
      0x69,
      0x6e,
      0x69,
      0x74,
      0x3e,
      0x01,
      0x00,
      0x03,
      0x28,
      0x29,
      0x56,
      0x01,
      0x00,
      0x04,
      0x43,
      0x6f,
      0x64,
      0x65,
      0x0c,
      0x00,
      0x05,
      0x00,
      0x06,
      0x01,
      0x00,
      0x01,
      0x43,
      0x01,
      0x00,
      0x10,
      0x6a,
      0x61,
      0x76,
      0x61,
      0x2f,
      0x6c,
      0x61,
      0x6e,
      0x67,
      0x2f,
      0x4f,
      0x62,
      0x6a,
      0x65,
      0x63,
      0x74,
      0x01,
      0x00,
      0x01,
      0x49,
      0x00,
      0x21,
      0x00,
      0x02,
      0x00,
      0x03,
      0x00,
      0x01,
      0x00,
      0x04,
      0x00,
      0x00,
      0x00,
      0x01,
      0x00,
      0x01,
      0x00,
      0x05,
      0x00,
      0x06,
      0x00,
      0x01,
      0x00,
      0x07,
      0x00,
      0x00,
      0x00,
      0x11,
      0x00,
      0x01,
      0x00,
      0x01,
      0x00,
      0x00,
      0x00,
      0x05,
      0x2a,
      (byte) 0xb7,
      0x00,
      0x01,
      (byte) 0xb1,
      0x00,
      0x00,
      0x00,
      0x00,
      0x00,
      0x00
    };

    ClassLoader cl =
        new ClassLoader() {
          protected Class<?> findClass(String name) {
            if (name.equals("I")) {
              return defineClass("I", I_bytes, 0, I_bytes.length);
            } else if (name.equals("C")) {
              return defineClass("C", C_bytes, 0, C_bytes.length);
            } else {
              return null;
            }
          }
        };
    try {
      Class.forName("C", true, cl);
    } catch (Exception e) {
      // unmodified verifier will throw VerifyError
      fail("No exception should be thrown");
    }
  }