Sorry. I think I have a blackout here... I am accustomed to get ClassCastExceptions from several of my test apps, but I always assumed these were due to Graphics2D not being properly implemented. However, some testing reveals that GtkComponent.paintComponent() actually casts to GdkGraphics, with GdkGraphics2D not a subclass of GdkGraphics. Please tell me I am doing something stupid! I just won't believe that classpath could have run my apps for ages, if not for this particular way of designing the type hierarchy. It seems that my custom component returns a valid Graphics2D, but GtkComponent refuses to use that... See attached testcase. - Norman
Created attachment 11007 [details] testcase
I've played some more with this. The typecasts to GdkGraphics in gnu.java.awt.peer.gtk.GtkComponentPeer.paintComponent() gnu.java.awt.peer.gtk.GtkComponentPeer.updateComponent() are definitely broken when running in Java2D-mode, because the GdkGraphics2D object returned from getGraphics() cannot be cast to a GdkGraphics. I changed those lines to cast to a (Graphics) instead. (I still have no idea why those typecasts were required at all.) The next problem is a NullPointerException in RepaintManager.commitBuffer() because GdkGraphics2D.getClipBounds() sometimes returns null. For testing, I added a simple extra null-check to RepaintManager, but we probably want to change Graphics2D.getClipBounds() to never return null instead. Afterwards, my test application starts up, but it paints garbage only, probably because the Graphics2D draw/fill operations are rather broken.
I introduced these methods in my not-yet-committed AWT performance patch. I'll fix these issues before committing. Thanks for pointing them out. *** This bug has been marked as a duplicate of 26486 ***
> I introduced these methods in my not-yet-committed AWT performance patch. I'll > fix these issues before committing. Thanks for pointing them out. Oops. It just didn't occur to me that your PR26486 patch could be related to this, because I got similar ClassCastExceptions when I last tested Graphics2D (about three months ago, I don't remember the details). I guess I should start reading patches more thoroughly...