Patch: embedded window extension

Eric Blake ebb9@byu.net
Tue Jul 20 14:33:00 GMT 2004


This patch seems a little too simple for me.  By default, reflection is 
supposed to follow the same accessibility rules the compiler would follow, 
meaning that the reflection should throw an IllegalAccessException unless you 
call setAccessible() on peerField to change the default.  And calling 
setAccessible requires a security check, so you will have to set up a 
PrivelegedAction so that your call will always succeed.  Did you just expose a 
bug in the reflection implementation?

Michael Koch wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi list,
> 
> 
> I just commited the attached patch to remove some native code and 
> replace it by java code using reflection. It was really simple. It 
> was tested by gcjwebplugin running in galeon.
> 
> 
> Michael
> 
> 
> 2004-07-17  Michael Koch  <konqueror@gmx.de>
> 
> 	* gnu/java/awt/EmbeddedWindow.java
> 	(static): Removed.
> 	(addNotify): Set peer via reflection.
> 	(setWindowPeer): Removed.
> 	* gnu/java/awt/natEmbeddedWindow.cc: Removed.
> 	* Makefile.am (nat_source_files):
> 	Removed gnu/java/awt/natEmbeddedWindow.cc.
> 	* Makefile.in: Regenerated.
> - -- 
> @@ -93,13 +90,24 @@
>        throw new UnsupportedOperationException
>          ("Embedded windows are not supported by the current peers: " + tk.getClass());
>  
> -    setWindowPeer (((EmbeddedWindowSupport) tk).createEmbeddedWindow (this));
> -    super.addNotify();
> +    // Circumvent the package-privateness of the AWT internal
> +    // java.awt.Component.peer member variable.
> +    try
> +      {
> +	Field peerField = Component.class.getDeclaredField("peer");
> +	peerField.set(this, ((EmbeddedWindowSupport) tk).createEmbeddedWindow (this));
> +      }
> +    catch (IllegalAccessException e)
> +      {
> +	// This should never happen.
> +      }
> +    catch (NoSuchFieldException e)
> +      {
> +	// This should never happen.
>    }
>  
> -  // This method is only made native to circumvent the package-privateness of
> -  // an AWT internal java.awt.Component.peer member variable.
> -  native void setWindowPeer (EmbeddedWindowPeer peer);
> +    super.addNotify();
> +  }
>  
-- 
Someday, I might put a cute statement here.

Eric Blake             ebb9@byu.net



More information about the Java-patches mailing list