Repository navigation
PrinterJob.getPrinterJob(): use the java.awt.printerjob property - #67
duncanmcqueen wants to merge 1 commit into
Conversation
15b5dbe to
ecadc92
Compare
|
I have some concerns here. The fact that the class is loaded using the boot class loader means that this would not be useful for any out-of-tree AWT toolkit, unless the toolkit is put in the boot class path. Classpath makes it especially easy to have out-of-tree toolkits (unlike the JDK), so this seems like an arbitrary limitation. I know the JDK does the same, but I don't think this is a good model. In the JDK, Also, setting the property in the toolkit itself is fragile, since applications could create a PrinterJob before the toolkit has a chance to run. So they would get the custom PrinterJob or the standard I think the approach is fine as long as:
With those changes the test should also pass without |
Upstream review of ingelabs/classpath#67: the user sets java.awt.printerjob, not the toolkit. Give -Djava.awt.printerjob=gnu.java.awt.peer.haiku.HaikuPrinterJob in run.sh and run-jamvm.sh, and say so in the README. The current patches still set it in HaikuToolkit, so this changes nothing until the patches are regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As in the JDK, the system property java.awt.printerjob names the PrinterJob class. The user sets it, for example next to awt.toolkit. Load the class through the system class loader, as Toolkit.getDefaultToolkit() loads awt.toolkit, so that a class on the class path also works. Without the property, use JavaPrinterJob as before. If the class cannot be loaded or made (also for a LinkageError, for example NoClassDefFoundError), print a warning and use JavaPrinterJob. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: duncanmcqueen <dwmcqueen@gmail.com>
ecadc92 to
0170d42
Compare
|
Thank you. I agree with all three points, and I changed the commit:
The test now runs without |
Split from #58.
Problem and fix
PrinterJob.getPrinterJob()always returnsgnu.java.awt.print.JavaPrinterJob.In JDK 8,
getPrinterJob()makes an instance of the class that the system propertyjava.awt.printerjobnames. With this change, Classpath does the same. The user sets the property, for example next to-Dawt.toolkit=....Classpath loads the class through the system class loader, in a
doPrivilegedblock, asToolkit.getDefaultToolkit()loadsawt.toolkit. The system class loader asks the boot class loader first, so a class on the boot class path also works. Thus a toolkit that is not in the boot class path can supply its own printer job. (JDK 8 uses the boot class loader.)If the class cannot be loaded or made, this change prints a warning and returns
JavaPrinterJob. It also does this for aLinkageError, for exampleNoClassDefFoundErrorwhen a dependency of the class is missing. (JDK 8 throwsAWTError.) Without the property, the behavior does not change.Note: OpenJDK 17 and later ignore the property.
How to reproduce
The test sets the property to a class on the class path, to a class that does not exist, and to a class whose initializer throws
NoClassDefFoundError(BrokenPrinterJob, below). It does not need-Xbootclasspath.PrinterJobProperty.javaBrokenPrinterJob.javaResults
Haiku R1/beta6 x86_64 (hrev60228), JamVM with the Haiku port (#25 in ingelabs/jamvm), and ingelabs/classpath built on Haiku. I compiled each version of the changed classes with
javacfrom OpenJDK 8 and put them first on the boot class path (-Xbootclasspath/p). "Before" ismaster. "Previous" is the first version of this pull request (boot class loader, no warning). "After" is this version.With the test classes also on the boot class path (
-Xbootclasspath/a), the previous version stopped withjava.lang.NoClassDefFoundError: MissingDependencyat the third test. This version gives the same output as above.Platforms
Not specific to Haiku. It is a general extension point that all toolkits can use. The Haiku toolkit (#61) supplies printing through the Haiku print system with
-Djava.awt.printerjob=gnu.java.awt.peer.haiku.HaikuPrinterJob.AI assistance
An AI model (Claude Code, by Anthropic) wrote this change, the test and this text. The repository owner directed the work and checked the results. Please review it as you review other contributions.
🤖 Generated with Claude Code