Skip to main content

PrintService in an unsigned jar

5 replies [Last post]
pietblok
Offline
Joined: 2003-07-17

I am trying to use javax.print.PrintService from an unsigned jar.

Of course, the user is asked permission to access a printer. But then, when granted, a SecurityException is thrown because java tries to access the JRE's lib/fonts directory to initialize the print job.

The problem occurs in webstarted applications and in applets.

I prepared a demonstration (including source code) of this on http://www.pbjar.org/PrintService/index.html

My questions:

Is this expected behavior and if so, why?

Is there a workaround?

Thanks,
Piet

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pietblok
Offline
Joined: 2003-07-17

Hi Phil,

Thanks again.

About the workarounds that you suggest:

Number 2 is obvious. No questions.

Number 1 fails for me. When I retry, by pressing the print button again, I get a java.lang.NoClassDefFoundError: Could not initialize class sun.awt.windows.WPrinterJob.

Is just executing the code again what you really meant by swallowing the exception?

Number 3. Do you mean something like: before attempting to print, force some file read (to trigger file read permission from the user) and after that attempt to print?

Thanks
Piet

philrace
Offline
Joined: 2003-06-09

>Number 1 fails for me. When I retry, by pressing the print button again, I get a java.lang.NoClassDefFoundError

I didn't see that but I can imagine if the class failed to initialise the first time something
I can't fathom with classloaders may be going on

A variation might be to not use PrinterJob but to invoke it to get the font files read.

> Number 3. Do you mean something like: before attempting to print, force some file read

No, this meant if your application/applet is signed, then give it file read permission too.

Anyway I'm trying to get this fixed in jdk 6 u10. Hopefully it will be in b13 available in
a few weeks.

-phil.

pietblok
Offline
Joined: 2003-07-17

OK Phil,

Thanks again,

Piet

philrace
Offline
Joined: 2003-06-09

Its a bug. I filed :
6664915 SecurityException using javax.print APIs when queuePrintJob permission is granted.

it should be on bugs.sun.com in a couple of days

There are workarounds :
1. The exception occurs only the first time. The app can swallow it and re-try
2. This is specific to javax.print APIs, PrinterJob can be used instead.
3. Since to encounter this queuePrintJob permission must be granted, then it
may be possible to grant file read too.

-phil.

pietblok
Offline
Joined: 2003-07-17

Thanks,

I will experiment with the workaround that you suggest,

Piet