Name: skT88420 Date: 11/24/99
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
1. To reproduce the problem, compile and run the code below using 'javac
PythonPad.java' followed by 'java PythonPad'. Then, type a character. To fix
the problem, use 'java -Djava.compiler=NONE PythonPad' instead. Or, the code
may be modified in any number of ways that will avoid the problem. See the
source comments that begin with '//afl' for a few examples! (The source could
not possibly make any sense in its present state!)
2. The source is here.
import java.awt.*;
import java.awt.event.*;
//import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.util.*;
public class PythonPad extends JPanel {
private static HashSet pythonKeywords=new HashSet();
static {
pythonKeywords.add("and");
pythonKeywords.add("del");
pythonKeywords.add("for");
pythonKeywords.add("is");
pythonKeywords.add("raise");
pythonKeywords.add("assert");
pythonKeywords.add("elif");
pythonKeywords.add("from");
pythonKeywords.add("lambda");
pythonKeywords.add("return");
pythonKeywords.add("break");
pythonKeywords.add("else");
pythonKeywords.add("global");
pythonKeywords.add("not");
pythonKeywords.add("try");
pythonKeywords.add("class");
pythonKeywords.add("except");
pythonKeywords.add("if");
pythonKeywords.add("or");
pythonKeywords.add("while");
pythonKeywords.add("continue");
pythonKeywords.add("exec");
pythonKeywords.add("import");
pythonKeywords.add("pass");
pythonKeywords.add("def");
pythonKeywords.add("finally");
pythonKeywords.add("in");
pythonKeywords.add("print");
}
protected static final class AppCloser extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setBackground(Color.lightGray);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add("Center", new PythonPad());
frame.addWindowListener(new AppCloser());
frame.pack();
frame.setSize(600, 480);
frame.show();
}
public PythonPad() {
super(true);
setBorder(BorderFactory.createEtchedBorder());
setLayout(new BorderLayout());
editor = createEditor();
editor.setFont(new Font("monospaced", Font.PLAIN, 12));
JScrollPane scroller = new JScrollPane();
JViewport port = scroller.getViewport();
port.add(editor);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add("Center", scroller);
add("Center", panel);
}
/**
* Create an editor to represent the given document.
*/
protected JTextComponent createEditor() {
StyleContext sc = new StyleContext();
DefaultStyledDocument doc = new DefaultStyledDocument(sc);
doc.addDocumentListener(new MyDocumentListener());
JTextPane p = new JTextPane(doc);
return p;
}
protected JTextComponent getEditor() {
return editor;
}
// Highlight the Python keywords
private int processed;
private void processChild(Element elem) {
int i;
DefaultStyledDocument doc=null;
StringTokenizer theTokens=null;
if(elem.isLeaf()) {
int start=elem.getParentElement().getStartOffset();
try {
theTokens=new StringTokenizer(elem.getDocument
().getText(elem.getParentElement().getStartOffset(),elem.getParentElement
().getEndOffset()-elem.getParentElement().getStartOffset())," \t\n\r\f",true);
}
catch (BadLocationException ble) {
System.out.println("What do we do now?");
}
SimpleAttributeSet attrs=new SimpleAttributeSet();
String theToken="";
String thePreceding="";
int setBold=0,iSet=0;
int indent=4;
int indentMod=0;
indentMod=2*indent;
while(theTokens.hasMoreTokens()) {
theToken=theTokens.nextToken();
if(theToken.equals("xxxx")) {
setBold++;
}
else {
//afl Comment the following line
StyleConstants.setItalic(attrs,false);
//afl Avoid the '%' operator by using the line following this one:
if(setBold%indentMod==indent) {
// if((setBold-(setBold/indentMod)
*indentMod)==indent) {
}
else {
iSet=setBold%indentMod;
//afl Uncomment the following line
// iSet=setBold-(setBold/indentMod)
*indentMod;
if(iSet==0) {
StyleConstants.setBold
(attrs,false);
}
else {
}
}
}
start=start+theToken.length();
}
processed=start;
}
else { // !elem.isLeaf()
if(elem.getElementCount()>0) {
while(elem.getEndOffset()>processed) {
processChild(elem.getElement
(elem.getElementIndex(processed)));
}
}
}
}
class UpdateTextColors extends Thread {
int offset;
int length;
public UpdateTextColors(int offset, int length) {
this.offset=offset;
this.length=length;
}
public void run() {
processed=offset;
while(processed<offset+length) {
processChild(getEditor().getDocument
().getRootElements()[0].getElement(getEditor().getDocument().getRootElements()
[0].getElementIndex(processed)));
}
}
}
class MyDocumentListener implements DocumentListener {
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
int offset=e.getOffset();
int length=e.getLength();
DefaultStyledDocument doc=(DefaultStyledDocument)
e.getDocument();
Element root=doc.getDefaultRootElement();
int index=root.getElementIndex(offset);
Element elem=root.getElement(index);
DocumentEvent.EventType type=e.getType();
if(type==DocumentEvent.EventType.INSERT) {
length=getEditor().getDocument().getRootElements
()[0].getElement(getEditor().getDocument().getRootElements()[0].getElementIndex
(offset+length)).getEndOffset()
-getEditor().getDocument
().getRootElements()[0].getElement(getEditor().getDocument().getRootElements()
[0].getElementIndex(offset)).getStartOffset();
offset=getEditor().getDocument().getRootElements
()[0].getElement(getEditor().getDocument().getRootElements()[0].getElementIndex
(offset)).getStartOffset();
UpdateTextColors u=new UpdateTextColors
(offset,length);
SwingUtilities.invokeLater(u);
}
}
public void removeUpdate(DocumentEvent e) {
}
}
private JTextComponent editor;
} // PythonPad
3. The error that appears is:
"A nonfatal internal JIT (3.10.107(x)) error 'Verify user locks error' has
occurred in : 'PythonPad.processChild (Ljavax/swing/text/Element;)V':
Interpreting method. Please report this error in detail to
http://java.sun.com/cgi-bin/bugreport.cgi"
4. n/a
5. n/a
(Review ID: 98245)
======================================================================