Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

69
LINES

< > BotCompany Repo | #1017723 // Swing Freeze Bug with certain characters

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (1491L/11K).

!7

// https://bugs.openjdk.java.net/browse/JDK-8183385

static String s0 = "Hello World";
// (truncated) contents of jdk-headers-1.6.0/include/ibm/zos/jawt_md.h file encoding=IBM500/EBCDIC, read with UTF8

static String s1 = "a\\\u0015@\\@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u0015@\\@@\ufffd\ufffd\ufffd@\u00d6\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0015@\\@@\ufffd\ufffd\ufffd@\u25a4\ufffd\ufffd\ufffd@\u0501\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0015@\\\u0015@\\@@\ufffd\ufffd\ufffd@\ufffd\ufffd\ufffdk@\u0441\ufffd\ufffdM\ufffd\ufffd]@\u3143\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd@\u0144\ufffd\ufffd\ufffd\ufffd\ufffdk@\ufffd\ufffd\u0015@\\@@M\ufffd]@\u00d6\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd@\ufffd\ufffd\ufffd@\u00d6\ufffd\ufffdK@\ufffd\ufffd\ufffd\ufffdk@\ufffd\ufffd\ufffd\ufffdK@\ufffd\ufffd\ufffd@\u0649\ufffd\ufffd\ufffd\ufffd@\u0645\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0015@\\\u0015@\\";

p {
  swing { new main().go(); }
}

void go() {
  JFrame frame = new JFrame("BugRepro");
  frame.setBounds(100, 100, 800, 600);
  frame.setContentPane(foo());
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);
}

JCheckBox c;

JPanel foo() {
  JPanel panel = new JPanel(new BorderLayout());
  JButton b;
  final JTextArea area = new JTextArea();
  JPanel p = new JPanel(new FlowLayout());
  panel.add(p, BorderLayout.NORTH);
  p.add(b = new JButton("click me"));
  p.add(c = new JCheckBox("include strange chars", true));
  panel.add(new JLabel("Hello"), BorderLayout.SOUTH);
  panel.add(new JScrollPane(area), BorderLayout.CENTER);
  
  // need to set a new Document b/c setText() sets the text of the old document.
  b.addActionListener(actionListener { area.setDocument(makeDoc()); });
  return panel;
}

Document makeDoc() {
Document doc = new PlainDocument();
try {
doc.insertString(0, makeString(), new SimpleAttributeSet());
} catch (BadLocationException e) {
throw new Error(e);
}
return doc;
}

String makeString() {
int MAX = 1000;

StringBuilder buf = new StringBuilder();
extracted(MAX, buf);
System.out.println("Including strange chars: " + c.isSelected());
if (c.isSelected()) {
buf.append(s1); // XXX This line slows down the rendering noticeably since it contains strange chars
}
extracted(MAX, buf);

return buf.toString();
}

static void extracted(int MAX, StringBuilder buf) {
for (int i = 0; i < MAX; i++) {
buf.append(s0);
buf.append("\n");
}
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017723
Snippet name: Swing Freeze Bug with certain characters
Eternal ID of this version: #1017723/5
Text MD5: f65a56690fef26976c5c10e5bc7caced
Transpilation MD5: b85bef3a93f5544abbdfc04e58f001fb
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-08-04 18:23:29
Source code size: 2540 bytes / 69 lines
Pitched / IR pitched: No / No
Views / Downloads: 382 / 1062
Version history: 4 change(s)
Referenced in: [show references]