Frage

Is it possible to turn off / override java.lang.SecurityException: Prohibited package name?

I need to extend AffineTransform class which was implemented with some lack of functionality, and I need to access members m00, m01, ... which are defined as package protected.

War es hilfreich?

Lösung

No you cant. It's hardcoded in java.lang.ClassLoader:

    if ((name != null) && name.startsWith("java.")) {
        throw new SecurityException
            ("Prohibited package name: " +
             name.substring(0, name.lastIndexOf('.')));

...

as you can see there is no option

Andere Tipps

You can read the values with the getMatrix(double[] flatmatrix). There is no corresponding setMatrix, but there is the AffineTransform(double[] flatmatrix) constructor.

Out of curiosity, what is the "lack of functionality" you refer to?

Update:

Ah, ok. The Java2D are really just for the basic 2D transforms. For anything the involves depth you may want to take a look at some of the Java / OpenGL bindings.

  • JOGL - Java Open GL bindings (JSR-231)
  • LWJGL - Lightweight Java Game Library
  • Jave 3D - The original 3d api from Sun.

Update 2:

One other library to check out would be the Java Advanced Imaging (JAI) API. The possible downside is it is not actively maintained; last updated in 2006. It's entirely focused on images, so you would need to:

  • render to a BufferedImage
  • create a NullOpImage from that
  • PerspectiveTransform the NullOpImage
  • and extract a final BufferedImage

As Evgeniy pointed out, the check is hard-coded in the ClassLoader, so circumventing this is no easy task. But there is always an option :-)

One could use the Java bootclasspath option on startup or implement a javaagent to slip in own improvements. The question is not whether it is doable, but whether this is the most sensible solution in terms of effort and overall maintenance.

Be aware, however, that since this introduces a potential security leak, both cannot be done for e.g. an Applet.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top