[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] make non-standard Font constructor package-private
From: |
Thomas Fitzsimmons |
Subject: |
Re: [cp-patches] make non-standard Font constructor package-private |
Date: |
Thu, 25 Aug 2005 02:35:29 -0400 |
On Wed, 2005-08-24 at 23:00 +0200, Mark Wielaard wrote:
> Hi,
>
> On Thu, 2005-08-18 at 22:18 -0400, Thomas Fitzsimmons wrote:
> > I made this non-standard Font constructor package-private and modified
> > ClasspathToolkit to access it through reflection.
> >
> > + // Circumvent the package-privateness of the
> > + // java.awt.Font.Font(String,Map) constructor.
> > + try
> > + {
> > + Constructor fontConstructor = Component.class.getConstructor
> > + (new Class[] { String.class, Map.class });
> > + AccessController.doPrivileged
> > + (new SetAccessibleAction(fontConstructor));
> > + f = (Font) fontConstructor.newInstance(new Object[] { name,
> > attrs });
> > + }
> > + catch (IllegalAccessException e)
> > + {
> > + // This should never happen.
> > + }
> > + catch (NoSuchMethodException e)
> > + {
> > + // This should never happen.
> > + }
> > + catch (InstantiationException e)
> > + {
> > + // This should never happen.
> > + }
> > + catch (InvocationTargetException e)
> > + {
> > + // This should never happen.
> > + }
> > + return f;
> > }
>
> In the places where you say "This should never happen." you can better
> throw a real Exception/Error. Since you won't be able to see the failure
> during compile time when someone accidentally breaks the reflection
> framework or the Font constructor in java.awt.
OK, I committed this:
2005-08-25 Thomas Fitzsimmons <address@hidden>
* gnu/java/awt/ClasspathToolkit.java (getFont): Throw
RuntimeException in case of error.
* gnu/java/awt/EmbeddedWindow.java (addNotify): Likewise.
Index: gnu/java/awt/ClasspathToolkit.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/ClasspathToolkit.java,v
retrieving revision 1.16
diff -u -r1.16 ClasspathToolkit.java
--- gnu/java/awt/ClasspathToolkit.java 19 Aug 2005 02:16:09 -0000 1.16
+++ gnu/java/awt/ClasspathToolkit.java 25 Aug 2005 06:26:46 -0000
@@ -139,28 +139,32 @@
// Circumvent the package-privateness of the
// java.awt.Font.Font(String,Map) constructor.
try
- {
- Constructor fontConstructor = Component.class.getConstructor
- (new Class[] { String.class, Map.class });
- AccessController.doPrivileged
- (new SetAccessibleAction(fontConstructor));
- f = (Font) fontConstructor.newInstance(new Object[] { name, attrs });
- }
+ {
+ Constructor fontConstructor = Component.class.getConstructor
+ (new Class[] { String.class, Map.class });
+ AccessController.doPrivileged
+ (new SetAccessibleAction(fontConstructor));
+ f = (Font) fontConstructor.newInstance(new Object[] { name, attrs });
+ }
catch (IllegalAccessException e)
- {
- // This should never happen.
- }
+ {
+ throw new RuntimeException
+ ("couldn't call java.awt.Font.Font(String,Map) constructor");
+ }
catch (NoSuchMethodException e)
- {
- // This should never happen.
- }
+ {
+ throw new RuntimeException
+ ("couldn't call java.awt.Font.Font(String,Map) constructor");
+ }
catch (InstantiationException e)
{
- // This should never happen.
+ throw new RuntimeException
+ ("couldn't call java.awt.Font.Font(String,Map) constructor");
}
catch (InvocationTargetException e)
{
- // This should never happen.
+ throw new RuntimeException
+ ("couldn't call java.awt.Font.Font(String,Map) constructor");
}
return f;
}
Index: gnu/java/awt/EmbeddedWindow.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/EmbeddedWindow.java,v
retrieving revision 1.7
diff -u -r1.7 EmbeddedWindow.java
--- gnu/java/awt/EmbeddedWindow.java 4 Jul 2005 22:31:41 -0000 1.7
+++ gnu/java/awt/EmbeddedWindow.java 25 Aug 2005 06:26:46 -0000
@@ -98,11 +98,13 @@
}
catch (IllegalAccessException e)
{
- // This should never happen.
+ throw new RuntimeException
+ ("couldn't set java.awt.Component.peer field");
}
catch (NoSuchFieldException e)
{
- // This should never happen.
+ throw new RuntimeException
+ ("couldn't set java.awt.Component.peer field");
}
super.addNotify();