<html><head>
<style id="css_styles">
blockquote.cite { margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc }
blockquote.cite2 {margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc; margin-top: 3px; padding-top: 0px; }
a img { border: 0px; }
li[style='text-align: center;'], li[style='text-align: center; '], li[style='text-align: right;'], li[style='text-align: right; '] { list-style-position: inside;}
body { font-family: Helvetica; font-size: 9pt; }
.quote { margin-left: 1em; margin-right: 1em; border-left: 5px #ebebeb solid; padding-left: 0.3em; }
</style>
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div id="xe028096a99174bb1b2fe4d093cfcfdbb">If I call Graphics2D#drawImage(customImage, 0, 0, null) on a custom java.awt.Image subclass: the drawImage(..) method returns false and nothing renders.<div><br /></div><div>Is this something I can write up as an openJDK ticket and propose a fix/PR for? (That is: is anyone with more authority willing to sponsor me if I try to approach this?)</div><div><br /></div><div>I made a simple test case <a href="https://drive.google.com/file/d/1kMlRZ3SPp7FkGTsA1vdnn--tINGQRmp4/view?usp=sharing">here</a>. (about 230 lines)</div><div><br /></div><div>I think the problem is coming from <a href="https://drive.google.com/file/d/13v7jqv-XpDTIeYoC2uU0Rck4w3iI-u1I/view?usp=sharing">this line</a> in SurfaceManager.java, where we cast an Image to a BufferedImage (after already ruling out the possibility that it’s a ToolkitImage).</div><div><br /></div><div>In my case ‘img’ is not a BufferedImage, so this triggers a ClassCastException. (Which is responsibly caught and eventually translates into “the drawImage method returns false and nothing renders”).</div><div><br /></div><div>In my case a viable solution might be to add code like this somewhere in SunGraphics2D or a supporting class:</div><div><br /></div><div>try {</div><div> if (! (img instanceof BufferedImage || img instanceof ToolkitImage)) {</div><div> img = newTempImage = Toolkit.getDefaultToolkit().createImage( img.getSource() );</div><div> }</div><div> paintAsUsual(img)</div><div>} finally {</div><div> if (newTempImage != null)</div><div> newTempImage.flush()</div><div>}</div><div><br /></div><div>That solution could in some cases be wasteful regarding memory (if we constantly create and flush a ToolkitImage), but I’d suggest that seeing inefficient results is better than seeing no results. Thoughts?</div><div><br /></div><div>Regards,</div><div> - Jeremy</div></div>
</body></html>