Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-6042

[classlib][luni] Classes can not be loaded correctly in sealed-packages

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 5.0M8
    • 5.0M9
    • Classlib
    • None
    • Moderate

    Description

      Given a test case [1], conduct it on HARMONY and RI.
      RI works well while HARMONY can not.

      In addition, to run this test, you need to deploy three new jars to [support]/src/test/java/tests/resources/Package.
      (1) hyts_d.jar: unsealed/no-manifest
      (2) hyts_d1.jar: unsealed/manifest
      (3) hyts_d2.jar: sealed/mainfest

      [1] Test Case
      public void test_SealedPackage_forName() throws Exception {
      Support_Resources.copyFile(resources, "Package", "hyts_c.jar");
      Support_Resources.copyFile(resources, "Package", "hyts_d.jar");
      Support_Resources.copyFile(resources, "Package", "hyts_d1.jar");
      Support_Resources.copyFile(resources, "Package", "hyts_d2.jar");
      URL resourceURL1 = new URL("file:/" + resPath + "/Package/hyts_c.jar");
      URL resourceURL2 = new URL("file:/" + resPath + "/Package/hyts_d.jar");
      URL resourceURL3 = new URL("file:/" + resPath + "/Package/hyts_d1.jar");
      URL resourceURL4 = new URL("file:/" + resPath + "/Package/hyts_d2.jar");
      URL resourceURL5 = new URL("file:/" + resPath + "/");
      URLClassLoader uclClassLoader;
      // load from the sealed jar, then an unsealed jar with no manifest
      uclClassLoader = new java.net.URLClassLoader(new URL[]

      { resourceURL1, resourceURL2 }, null);
      Class.forName("p.C", true, uclClassLoader);
      try { Class.forName("p.D", true, uclClassLoader); fail("should throw SecurityException"); } catch (SecurityException e) { // Expected }
      // setup for next test
      Support_Resources.copyFile(resources, "p", "");
      InputStream in = uclClassLoader.getResourceAsStream("p/D.class");
      Support_Resources.copyLocalFileto(new File(resources.toString(),
      "p/D.class"), in);
      // load from a sealed jar, then the directory
      uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1, resourceURL5 }, null);
      Class.forName("p.C", true, uclClassLoader);
      try { Class.forName("p.D", true, uclClassLoader); fail("should throw SecurityException"); } catch (SecurityException e) { // Expected }
      // load from a directory, then the sealed jar
      uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1, resourceURL5 }, null);
      Class.forName("p.D", true, uclClassLoader);
      try { Class.forName("p.C", true, uclClassLoader); fail("should throw SecurityException"); } catch (SecurityException e) { // Expected }
      // load from an unsealed jar with no manifest, then the sealed jar
      uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1, resourceURL2 }

      , null);
      Class.forName("p.D", true, uclClassLoader);
      try

      { Class.forName("p.C", true, uclClassLoader); fail("should throw SecurityException"); } catch (SecurityException e) { // Expected }
      // load from an unsealed jar with a manifest, then the sealed jar
      uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1, resourceURL3 }, null);
      Class.forName("p.C", true, uclClassLoader);
      try { Class.forName("p.D", true, uclClassLoader); fail("should throw SecurityException"); } catch (SecurityException e) { // Expected }
      // load from an sealed jar, then the unsealed jar with a manifest
      uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1, resourceURL3 }, null);
      Class.forName("p.D", true, uclClassLoader);
      try { Class.forName("p.C", true, uclClassLoader); fail("should throw SecurityException"); }

      catch (SecurityException e)

      { // Expected }
      // load from the sealed jar, then another sealed jar
      uclClassLoader = new java.net.URLClassLoader(new URL[] { resourceURL1, resourceURL4 }, null);
      Class.forName("p.C", true, uclClassLoader);
      try { Class.forName("p.D", true, uclClassLoader); fail("should throw SecurityException"); } catch (SecurityException e) { // Expected }

      }

      Attachments

        1. HARMONY-6042.diff
          7 kB
          Kevin Zhou
        2. hyts_d.jar
          0.6 kB
          Kevin Zhou
        3. hyts_d2.jar
          1 kB
          Kevin Zhou
        4. hyts_d1.jar
          1 kB
          Kevin Zhou

        Activity

          People

            qiuxiaox Sean Qiu
            zhoukevin Kevin Zhou
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified

                Slack

                  Issue deployment