0

we've an issue with a long-running Java process suddenly spitting out java.lang.SecurityException: sealing violation: package .. is sealed after overwriting a sealed jar while the JVM is running.

I kind of understand this exception, but in order to reproduce this (and what follows), I'm trying to artificially create a sealed exception and it's not working.

There's a jar file named 'seal.jar' with a META-INF/MANIFEST.MF file like this:

Manifest-Version: 1.0
Sealed: true

This package contains classes A1, A2, A3 like this:

package sealed;

public class A1
{
  public A1()
  {
    System.err.println("Created version 1.0 of " + this.getClass());
  }
}

There's a second jar seal-2.0.jar with the same three classes but printing "version 2.0" Now a third jar file (run.jar) has this content:

import sealed.A1;
import sealed.A2;
import sealed.A3;

public class SealingTest
{
  public static void main(String[] args) {

    int cnt=0;

    try {

      while(true) {

        if( cnt%3==0 ) {
          new A1();
        }
        else if( cnt%3==1 ) {
          new A2();
        }
        else if( cnt%3==2 ) {
          new A3();
        }

        Thread.sleep(5000);
        cnt++;
      }
    }
    catch (Throwable t) {
      t.printStackTrace();
    }
  }
}

And I thought the this code would then create a sealed exception when I do the following:

C:\CodeStreet\FTP>java -cp run.jar;seal-1.0.jar SealingTest
Created 1.0 of class sealed.A1     # now executing:  copy seal-2.0.jar seal-1.0.jar
Created 2.0 of class sealed.A2
Created 2.0 of class sealed.A3
Created 1.0 of class sealed.A1

So it looks like A1 is loaded from seal-1.0.jar, but A2 is loaded from the overwritten seal-1.0.jar.

Shouldn't there be a sealing violation because the first class (A1) is loaded from seal-1.0.jar and the second class (A2) from the overwritten file ?

Axel Podehl
  • 4,034
  • 29
  • 41
  • Read this simple tutorial on jar package sealing and how to get `SecurityException` in a simple program. http://www.journaldev.com/1347/java-jar-sealing-packages – Pankaj Jan 31 '13 at 22:48

1 Answers1

0

Please try the following:

  • remove A3.java from seal-1.0.jar, but keep it in seal-2.0.jar;
  • have both sealed jars in the classpath and run the test program.

That should give you the desired "SecurityException: sealing violation".