classpath-patches
[Top][All Lists]
Advanced

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

Re: [cp-patches] make non-standard Font constructor package-private


From: Mark Wielaard
Subject: Re: [cp-patches] make non-standard Font constructor package-private
Date: Wed, 24 Aug 2005 23:00:22 +0200

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.

Cheers,

Mark

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

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