classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] fix crash/NPE in GdkGraphics2D


From: Thomas Fitzsimmons
Subject: [cp-patches] fix crash/NPE in GdkGraphics2D
Date: Fri, 09 Sep 2005 21:19:18 -0400

Hi,

I committed this fix for PR23692.  It prints an error message and exits
if an attempt is made to instantiate a GdkGraphics2D when
gnu.java.awt.peer.gtk.Graphics != Graphics2D.  The abrupt System.exit
(1) was necessary because GdkGraphics2D's static initializer is invoked
due to a JNI call and exceptions weren't being thrown as a result.  This
is just a temporary hack until
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20630 is fixed, so I didn't
investigate deeply.  The patch also protects against a null component
field when setting a GdkGraphics2D's clip region to null.

Tom

2005-09-09  Thomas Fitzsimmons  <address@hidden>

        PR awt/23692
        * gnu/java/awt/peer/gtk/GdkGraphics2D.java (static): Only call
        initStaticState if using Graphics2D.  Otherwise print error and
        exit.
        (setClip(Shape)): If clip == null and component == null, do
        nothing.

2005-09-09  Thomas Fitzsimmons  <address@hidden>

        * gnu/java/awt/peer/gtk/GdkGraphics2D.java (static): Reindent
        second error message.

Index: gnu/java/awt/peer/gtk/GdkGraphics2D.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java,v
retrieving revision 1.45
diff -u -r1.45 GdkGraphics2D.java
--- gnu/java/awt/peer/gtk/GdkGraphics2D.java    8 Sep 2005 23:13:23 -0000       
1.45
+++ gnu/java/awt/peer/gtk/GdkGraphics2D.java    10 Sep 2005 00:59:06 -0000
@@ -107,7 +107,13 @@
     if (Configuration.INIT_LOAD_LIBRARY)
       System.loadLibrary("gtkpeer");
 
-    initStaticState();
+    if (GtkToolkit.useGraphics2D ())
+      initStaticState();
+    else
+      {
+        System.err.println ("Attempted to instantiate GdkGraphics2D but 
Graphics2D not enabled.  Try again with 
-Dgnu.java.awt.peer.gtk.Graphics=Graphics2D");
+        System.exit (1);
+      }
   }
   
   static native void initStaticState();
@@ -992,8 +998,11 @@
     if (clip == null)
       {
        // Reset clipping.
-       Dimension d = component.awtComponent.getSize();
-       setClip(0, 0, d.width, d.height);
+        if (component != null)
+          {
+            Dimension d = component.awtComponent.getSize();
+            setClip(0, 0, d.width, d.height);
+          }
       }
     else
       {
Index: gnu/java/awt/peer/gtk/GdkGraphics2D.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java,v
retrieving revision 1.46
diff -u -r1.46 GdkGraphics2D.java
--- gnu/java/awt/peer/gtk/GdkGraphics2D.java    10 Sep 2005 01:01:54 -0000      
1.46
+++ gnu/java/awt/peer/gtk/GdkGraphics2D.java    10 Sep 2005 01:06:59 -0000
@@ -111,7 +111,9 @@
       initStaticState();
     else
       {
-        System.err.println ("Attempted to instantiate GdkGraphics2D but 
Graphics2D not enabled.  Try again with 
-Dgnu.java.awt.peer.gtk.Graphics=Graphics2D");
+        System.err.println ("Attempted to instantiate GdkGraphics2D"
+                            + " but Graphics2D not enabled.  Try again with"
+                            + " -Dgnu.java.awt.peer.gtk.Graphics=Graphics2D");
         System.exit (1);
       }
   }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]