Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d0987113faa762d1eb8d901e8ac9d24522160c3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*******************************************************************************
 * Copyright (c) 2018 Red Hat and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.tests.gtk.snippets;


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.BitSet;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Bug291073_CrashWhenPrintingToConsole {
	public static void main(String[] args) throws IOException{
		Display display = new Display();
		Shell shell = new Shell (display);
		
		Font font1 = new Font(display, "Tahoma", 14, SWT.BOLD);
		Color blue = display.getSystemColor(SWT.COLOR_BLUE);
		Color yellow = display.getSystemColor(SWT.COLOR_YELLOW);
		
		final TextLayout layout = new TextLayout(display);
		TextStyle style1 = new TextStyle(font1, yellow, blue);
		
        BitSet bs = new BitSet();
        bs.set(2894298, true);
        bs.set(324832893, true);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(out);
        oos.writeObject(bs);

		layout.setText(out.toString());
		System.out.println("length:"+out.toString());
		layout.setStyle(style1, 2, out.toString().length() - 10000000);
		shell.addListener(SWT.Paint, new Listener() {
			@Override
			public void handleEvent (Event event) {
				Display display = event.display;
				GC gc = event.gc;
				
				Rectangle rect0 = layout.getBounds();
				rect0.x += 10;
				rect0.y += 10;
				gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
				gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
				gc.fillRectangle(rect0);
				layout.draw(gc, rect0.x, rect0.y);
				}
		});
		shell.open();	
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		font1.dispose();
		layout.dispose();
		display.dispose();
	}

}

Back to the top