< prev index next >

test/java/awt/Focus/RequestOnCompWithNullParent/RequestOnCompWithNullParent1.java

Print this page

        

@@ -25,11 +25,10 @@
   @test
   @bug 6418028
   @author oleg.sukhodolsky: area=awt.focus
   @library ../../regtesthelpers
   @modules java.desktop/java.awt.peer
-           java.desktop/sun.awt
   @build Util
   @run main RequestOnCompWithNullParent1
 */
 
 import java.awt.*;

@@ -40,14 +39,14 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 
-import sun.awt.AWTAccessor;
-
 public class RequestOnCompWithNullParent1 {
 
+    static Field peer_field;
+
     public static void main(final String[] args) throws Exception {
         Frame frame = new Frame("test for 6418028");
         try {
             test(frame);
         } finally {

@@ -70,10 +69,13 @@
         });
         frame.setVisible(true);
 
         new Robot().waitForIdle();
 
+        peer_field = Component.class.getDeclaredField("peer");
+        peer_field.setAccessible(true);
+
         btn2.instrumentPeer();
         btn2.requestFocusInWindow();
         btn2.restorePeer();
     }
 }

@@ -86,11 +88,11 @@
     TestButton(String text) {
         super(text);
     }
 
     public void instrumentPeer() {
-        origPeer = AWTAccessor.getComponentAccessor().getPeer(this);
+        origPeer = getPeer();
 
         InvocationHandler handler = new InvocationHandler() {
             public Object invoke(Object proxy, Method method, Object[] args) {
                 if (method.getName().equals("requestFocus")) {
                     Container parent = getParent();

@@ -115,22 +117,31 @@
                                     ButtonPeer.class.getClassLoader(),
                                     new Class[] {ButtonPeer.class}, handler);
         setPeer(proxiedPeer);
     }
 
-    private void setPeer(final ComponentPeer newPeer) {
+    private ButtonPeer getPeer() {
         try {
-            Field peer_field = Component.class.getDeclaredField("peer");
-            peer_field.setAccessible(true);
-            peer_field.set(this, newPeer);
+            return (ButtonPeer)
+                    RequestOnCompWithNullParent1.peer_field.get(this);
         } catch (IllegalArgumentException ex) {
             throw new Error("Test error.", ex);
         } catch (SecurityException ex) {
             throw new Error("Test error.", ex);
         } catch (IllegalAccessException ex) {
             throw new Error("Test error.", ex);
-        } catch (NoSuchFieldException ex) {
+        }
+    }
+
+    private void setPeer(final ComponentPeer newPeer) {
+        try {
+            RequestOnCompWithNullParent1.peer_field.set(this, newPeer);
+        } catch (IllegalArgumentException ex) {
+            throw new Error("Test error.", ex);
+        } catch (SecurityException ex) {
+            throw new Error("Test error.", ex);
+        } catch (IllegalAccessException ex) {
             throw new Error("Test error.", ex);
         }
     }
 
     public void restorePeer() {
< prev index next >