2

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.

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

3 Answers3

5

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

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
1

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
Devon_C_Miller
  • 16,248
  • 3
  • 45
  • 71
  • I mean rational linear transform (including perspective transform). I took `PerspectiveTransform` from `JAI` and made it `extends AffineTransform` in order to code more wide range of transforms in standard `PathIterator`. – Suzan Cioc Nov 14 '13 at 05:38
  • Thanks! But I want namely 2D. Also I would like to tie with AWT because I use `Piccolo2D` library which is also tied with it. – Suzan Cioc Nov 14 '13 at 22:50
0

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.

Community
  • 1
  • 1
roesslerj
  • 2,611
  • 5
  • 30
  • 44