1 /* 2 * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 @test 26 @bug 6255653 27 @summary REGRESSION: Override isLightweight() causes access violation in awt.dll 28 @author Andrei Dmitriev: area=awt-component 29 @run main StubPeerCrash 30 */ 31 32 /* 33 * The test may not crash for several times so iteratively continue up to some limit. 34 */ 35 36 import java.awt.*; 37 import java.awt.peer.*; 38 import java.awt.event.PaintEvent; 39 import java.awt.image.ImageProducer; 40 import java.awt.image.ImageObserver; 41 import java.awt.image.ColorModel; 42 import java.awt.image.VolatileImage; 43 import java.awt.GraphicsConfiguration; 44 import sun.awt.CausedFocusEvent; 45 import sun.java2d.pipe.Region; 46 47 public class StubPeerCrash { 48 public static int ITERATIONS = 20; 49 50 public static void main(String []s) 51 { 52 for (int i = 0; i < ITERATIONS; i++){ 53 showFrame(i); 54 } 55 } 56 57 private static void showFrame(int i){ 58 System.out.println("iteration = "+i); 59 Frame f = new Frame(); 60 f.add(new AHeavyweightComponent()); 61 f.setVisible(true); 62 f.setVisible(false); 63 } 64 } 65 66 class AHeavyweightComponent extends Component { 67 private ComponentPeer peer = new StubComponentPeer(); 68 69 public AHeavyweightComponent(){ 70 } 71 72 public boolean isLightweight() { 73 return false; 74 } 75 76 public ComponentPeer getPeer(){ 77 return peer; 78 } 79 } 80 81 class StubComponentPeer implements ComponentPeer { 82 public boolean isObscured(){return true;}; 83 public boolean canDetermineObscurity(){return true;}; 84 public void setVisible(boolean b){}; 85 public void setEnabled(boolean b){}; 86 public void paint(Graphics g){}; 87 public void repaint(long tm, int x, int y, int width, int height){}; 88 public void print(Graphics g){}; 89 public void setBounds(int x, int y, int width, int height, int op){}; 90 public void handleEvent(AWTEvent e){}; 91 public void coalescePaintEvent(PaintEvent e){}; 92 public Point getLocationOnScreen(){return null;}; 93 public Dimension getPreferredSize(){return null;}; 94 public Dimension getMinimumSize(){return null;}; 95 public ColorModel getColorModel(){return null;}; 96 public Toolkit getToolkit(){return null;}; 97 public Graphics getGraphics(){return null;}; 98 public FontMetrics getFontMetrics(Font font){return null;}; 99 public void dispose(){}; 100 public void setForeground(Color c){}; 101 public void setBackground(Color c){}; 102 public void setFont(Font f){}; 103 public void updateCursorImmediately(){}; 104 public boolean requestFocus(Component lightweightChild, 105 boolean temporary, 106 boolean focusedWindowChangeAllowed, 107 long time, CausedFocusEvent.Cause cause){ 108 return true; 109 }; 110 public boolean isFocusable(){return true;}; 111 112 public Image createImage(ImageProducer producer){return null;}; 113 public Image createImage(int width, int height){return null;}; 114 public VolatileImage createVolatileImage(int width, int height){return null;}; 115 public boolean prepareImage(Image img, int w, int h, ImageObserver o){return true;}; 116 public int checkImage(Image img, int w, int h, ImageObserver o){return 0;}; 117 public GraphicsConfiguration getGraphicsConfiguration(){return null;}; 118 public boolean handlesWheelScrolling(){return true;}; 119 public void createBuffers(int numBuffers, BufferCapabilities caps) throws AWTException{}; 120 public Image getBackBuffer(){return null;}; 121 public void flip(int x1, int y1, int x2, int y2, BufferCapabilities.FlipContents flipAction){}; 122 public void destroyBuffers(){}; 123 124 /** 125 * Reparents this peer to the new parent referenced by <code>newContainer</code> peer 126 * Implementation depends on toolkit and container. 127 * @param newContainer peer of the new parent container 128 * @since 1.5 129 */ 130 public void reparent(ContainerPeer newContainer){}; 131 /** 132 * Returns whether this peer supports reparenting to another parent withour destroying the peer 133 * @return true if appropriate reparent is supported, false otherwise 134 * @since 1.5 135 */ 136 public boolean isReparentSupported(){return true;}; 137 138 /** 139 * Used by lightweight implementations to tell a ComponentPeer to layout 140 * its sub-elements. For instance, a lightweight Checkbox needs to layout 141 * the box, as well as the text label. 142 */ 143 public void layout(){}; 144 145 146 public Rectangle getBounds(){return null;}; 147 148 /** 149 * Applies the shape to the native component window. 150 * @since 1.7 151 */ 152 public void applyShape(Region shape){}; 153 154 /** 155 * DEPRECATED: Replaced by getPreferredSize(). 156 */ 157 public Dimension preferredSize(){return null;}; 158 159 /** 160 * DEPRECATED: Replaced by getMinimumSize(). 161 */ 162 public Dimension minimumSize(){return null;}; 163 164 /** 165 * DEPRECATED: Replaced by setVisible(boolean). 166 */ 167 public void show(){}; 168 169 /** 170 * DEPRECATED: Replaced by setVisible(boolean). 171 */ 172 public void hide(){}; 173 174 /** 175 * DEPRECATED: Replaced by setEnabled(boolean). 176 */ 177 public void enable(){}; 178 179 /** 180 * DEPRECATED: Replaced by setEnabled(boolean). 181 */ 182 public void disable(){}; 183 184 /** 185 * DEPRECATED: Replaced by setBounds(int, int, int, int). 186 */ 187 public void reshape(int x, int y, int width, int height){}; 188 }