Merge
diff --git a/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java b/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java
index 95d15a8..94a74e5 100644
--- a/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java
+++ b/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java
@@ -41,10 +41,11 @@
     }
 
     public void enter() {
-        toolkit.startNativeNestedEventLoop();
+        // Execute the next AppKit event while we are waiting for system to
+        // finish our request - this will save us from biting our own tail
+        toolkit.executeNextAppKitEvent();
     }
 
     public void exit() {
-        toolkit.stopNativeNestedEventLoop();
     }
 }
diff --git a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
index fa13d0e..d3565b8 100644
--- a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
+++ b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
@@ -63,9 +63,7 @@
 
     private static native void initIDs();
 
-    static native void startNativeNestedEventLoop();
-
-    static native void stopNativeNestedEventLoop();
+    static native void executeNextAppKitEvent();
 
     private static CInputMethodDescriptor sInputMethodDescriptor;
 
@@ -361,9 +359,11 @@
             CWrapper.NSObject.release(screen);
         }
         // Convert between Cocoa's coordinate system and Java.
-        return new Insets(fullScreen.height - workArea.height - workArea.y,
-                          workArea.x, workArea.y,
-                          fullScreen.width - workArea.width - workArea.x);
+        int bottom = workArea.y - fullScreen.y;
+        int top = fullScreen.height - workArea.height - bottom;
+        int left = workArea.x - fullScreen.x;
+        int right = fullScreen.width - workArea.width - left;
+        return  new Insets(top, left, bottom, right);
     }
 
     @Override
diff --git a/src/macosx/native/sun/awt/LWCToolkit.m b/src/macosx/native/sun/awt/LWCToolkit.m
index 173154a..f9b17fc 100644
--- a/src/macosx/native/sun/awt/LWCToolkit.m
+++ b/src/macosx/native/sun/awt/LWCToolkit.m
@@ -42,7 +42,6 @@
 @implementation AWTToolkit
 
 static long eventCount;
-static bool shouldKeepRunningNestedLoop = NO;
 
 + (long) getEventCount{
     return eventCount;
@@ -460,33 +459,18 @@
 
 /*
  * Class:     sun_lwawt_macosx_LWCToolkit
- * Method:    startNativeNestedEventLoop
+ * Method:    executeNextAppKitEvent
  * Signature: ()V
  */
-JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_startNativeNestedEventLoop
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_executeNextAppKitEvent
 (JNIEnv *env, jclass cls)
 {
-    if(!shouldKeepRunningNestedLoop) {
-        NSRunLoop *theRL = [NSRunLoop currentRunLoop];
-        NSApplication * app = [NSApplication sharedApplication];
-        shouldKeepRunningNestedLoop = YES;
-        while (shouldKeepRunningNestedLoop && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]])
-        {
-            NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
-            if (event != nil) {
-                [app sendEvent: event];
-            }
-        }
+    // Simply get the next event in native loop and pass it to execution
+    // We'll be called repeatedly so there's no need to block here
+    NSRunLoop *theRL = [NSRunLoop currentRunLoop];
+    NSApplication * app = [NSApplication sharedApplication];
+    NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
+    if (event != nil) {
+        [app sendEvent: event];
     }
 }
-
-/*
- * Class:     sun_lwawt_macosx_LWCToolkit
- * Method:    stopNativeNestedEventLoop
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopNativeNestedEventLoop
-(JNIEnv *env, jclass cls)
-{
-    shouldKeepRunningNestedLoop = NO;
-}
diff --git a/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m b/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m
index ba1f2bc..bbe4251 100644
--- a/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m
+++ b/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m
@@ -63,12 +63,14 @@
 
         CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo;
         if (ctxinfo != NULL) {
+            NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];        
             [NSOpenGLContext clearCurrentContext];
             [ctxinfo->context clearDrawable];
             [ctxinfo->context release];
             if (ctxinfo->scratchSurface != 0) {
                 [ctxinfo->scratchSurface release];
             }
+            [pool drain];
             free(ctxinfo);
         }
     }
diff --git a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java
index 57a8169..4a1f429 100644
--- a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java
+++ b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java
@@ -926,9 +926,20 @@
                                      int x, int y, int w, int h) {
         // Text is odd in that it uses the TEXT_BACKGROUND vs BACKGROUND.
         JComponent c = context.getComponent();
+        Container container = c.getParent();
+        Container containerParent = null;
         GTKStyle style = (GTKStyle)context.getStyle();
         Region id = context.getRegion();
         int state = context.getComponentState();
+
+        if (c instanceof ListCellRenderer && container != null) {
+            containerParent = container.getParent();
+            if (containerParent instanceof JComboBox
+                    && containerParent.hasFocus()) {
+                state |= SynthConstants.FOCUSED;
+            }
+        }
+
         synchronized (UNIXToolkit.GTK_LOCK) {
             if (ENGINE.paintCachedImage(g, x, y, w, h, id, state)) {
                 return;
@@ -938,9 +949,10 @@
             int focusSize = 0;
             boolean interiorFocus = style.getClassSpecificBoolValue(
                     context, "interior-focus", true);
+
+            focusSize = style.getClassSpecificIntValue(context,
+                    "focus-line-width",1);
             if (!interiorFocus && (state & SynthConstants.FOCUSED) != 0) {
-                focusSize = style.getClassSpecificIntValue(context,
-                        "focus-line-width",1);
                 x += focusSize;
                 y += focusSize;
                 w -= 2 * focusSize;
@@ -961,11 +973,25 @@
                                 h - (2 * yThickness),
                                 ColorType.TEXT_BACKGROUND);
 
-            if (focusSize > 0) {
-                x -= focusSize;
-                y -= focusSize;
-                w += 2 * focusSize;
-                h += 2 * focusSize;
+            if (focusSize > 0 && (state & SynthConstants.FOCUSED) != 0) {
+                if (!interiorFocus) {
+                    x -=  focusSize;
+                    y -=  focusSize;
+                    w +=  2 * focusSize;
+                    h +=  2 * focusSize;
+                } else {
+                    if (containerParent instanceof JComboBox) {
+                        x += (focusSize + 2);
+                        y += (focusSize + 1);
+                        w -= (2 * focusSize + 1);
+                        h -= (2 * focusSize + 2);
+                    } else {
+                        x += focusSize;
+                        y += focusSize;
+                        w -= 2 * focusSize;
+                        h -= 2 * focusSize;
+                    }
+                }
                 ENGINE.paintFocus(g, context, id, gtkState,
                         "entry", x, y, w, h);
             }
diff --git a/src/share/classes/javax/swing/text/html/parser/Parser.java b/src/share/classes/javax/swing/text/html/parser/Parser.java
index 2638f05..eeb8329 100644
--- a/src/share/classes/javax/swing/text/html/parser/Parser.java
+++ b/src/share/classes/javax/swing/text/html/parser/Parser.java
@@ -1986,8 +1986,6 @@
             if (i == SCRIPT_END_TAG.length) {
 
                 /*  '</script>' tag detected */
-                /* Here, ch == '>' */
-                ch = readCh();
                 /* Here, ch == the first character after </script> */
                 return;
             } else {
@@ -2060,6 +2058,8 @@
                 handleComment(str.toCharArray());
                 endTag(false);
                 lastBlockStartPos = currentPosition;
+
+                continue;
             } else {
                 switch (c) {
                   case '<':
diff --git a/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java b/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java
index 360bb9a..302a6db 100644
--- a/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java
+++ b/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java
@@ -498,7 +498,7 @@
         postDropTargetEvent(component, x, y, dropAction, actions,
                             formats, nativeCtxt,
                             SunDropTargetEvent.MOUSE_DROPPED,
-                            !SunDropTargetContextPeer.DISPATCH_SYNC);
+                            SunDropTargetContextPeer.DISPATCH_SYNC);
     }
 
     /**
diff --git a/test/javax/swing/JCheckBox/4449413/bug4449413.html b/test/javax/swing/JCheckBox/4449413/bug4449413.html
new file mode 100644
index 0000000..cec2ce0
--- /dev/null
+++ b/test/javax/swing/JCheckBox/4449413/bug4449413.html
@@ -0,0 +1,17 @@
+<html>
+<body>
+When the applet starts, you'll see eight controls with black backgrounds.
+Four enabled (on the left side) and four disabled (on the right side)
+checkboxes and radiobuttons.
+
+1. If at least one of the controls' check marks is not visible:
+   the test fails.
+
+2. Uncheck the "Use Ocean Theme" check box. 
+   If now at least one of the controls' check marks is not visible:
+   the test fails.
+
+<applet  code="bug4449413.class" width=250 height=190></applet>
+
+</body>
+</html>
diff --git a/test/javax/swing/JCheckBox/4449413/bug4449413.java b/test/javax/swing/JCheckBox/4449413/bug4449413.java
new file mode 100644
index 0000000..4fd8efd
--- /dev/null
+++ b/test/javax/swing/JCheckBox/4449413/bug4449413.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 4449413
+ * @summary Tests that checkbox and radiobuttons' check marks are visible when background is black
+ * @author Ilya Boyandin
+ * @run applet/manual=yesno bug4449413.html
+ */
+
+import javax.swing.*;
+import javax.swing.plaf.metal.*;
+import java.awt.event.*;
+import java.awt.*;
+import sun.awt.OSInfo;
+
+public class bug4449413 extends JApplet {
+
+    @Override
+    public void init() {
+
+        try {
+
+            if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
+                UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
+            }
+
+            final MetalTheme oceanTheme = (MetalTheme) sun.awt.AppContext.getAppContext().get("currentMetalTheme");
+
+
+            SwingUtilities.invokeAndWait(new Runnable() {
+
+                @Override
+                public void run() {
+                    getContentPane().setLayout(new FlowLayout());
+                    final JPanel panel = new JPanel();
+
+                    JCheckBox box = new JCheckBox("Use Ocean theme", true);
+                    getContentPane().add(box);
+                    box.addItemListener(new ItemListener() {
+
+                        @Override
+                        public void itemStateChanged(ItemEvent e) {
+                            if (e.getStateChange() == ItemEvent.SELECTED) {
+                                MetalLookAndFeel.setCurrentTheme(oceanTheme);
+                            } else {
+                                MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
+                            }
+                            SwingUtilities.updateComponentTreeUI(panel);
+                        }
+                    });
+
+                    getContentPane().add(panel);
+                    panel.setLayout(new GridLayout(4, 6, 10, 15));
+                    for (int k = 0; k <= 3; k++) {
+                        for (int j = 1; j >= 0; j--) {
+                            AbstractButton b = createButton(j, k);
+                            panel.add(b);
+                        }
+                    }
+                }
+            });
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    static AbstractButton createButton(int enabled, int type) {
+        AbstractButton b = null;
+        switch (type) {
+            case 0:
+                b = new JRadioButton("RadioButton");
+                break;
+            case 1:
+                b = new JCheckBox("CheckBox");
+                break;
+            case 2:
+                b = new JRadioButtonMenuItem("RBMenuItem");
+                break;
+            case 3:
+                b = new JCheckBoxMenuItem("CBMenuItem");
+                break;
+        }
+        b.setBackground(Color.black);
+        b.setForeground(Color.white);
+        b.setEnabled(enabled == 1);
+        b.setSelected(true);
+        return b;
+    }
+}
diff --git a/test/javax/swing/text/html/parser/Parser/7165725/bug7165725.java b/test/javax/swing/text/html/parser/Parser/7165725/bug7165725.java
new file mode 100644
index 0000000..2c89050
--- /dev/null
+++ b/test/javax/swing/text/html/parser/Parser/7165725/bug7165725.java
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+   @bug 7165725
+   @summary  Tests if HTML parser can handle successive script tags in a line
+             and it does not call false text callback after script tags.
+   @run main bug7165725
+*/
+
+import sun.awt.SunToolkit;
+
+import java.awt.BorderLayout;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import javax.swing.*;
+import javax.swing.text.AbstractDocument.AbstractElement;
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.Document;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLDocument;
+import javax.swing.text.html.HTMLEditorKit;
+import javax.swing.text.html.parser.ParserDelegator;
+
+public class bug7165725 extends JFrame {
+    private static class GoldenElement {
+
+        private String goldenName;
+        private List<GoldenElement> goldenChildren;
+
+        GoldenElement(String goldenName, GoldenElement... goldenChildren){
+            this.goldenName = goldenName;
+            if (goldenChildren != null) {
+                this.goldenChildren = Arrays.asList(goldenChildren);
+            } else {
+                this.goldenChildren = new ArrayList<>();
+            }
+        }
+
+        // throws RuntimeException if not ok
+        public void checkStructureEquivalence(AbstractDocument.AbstractElement elem) {
+            String name = elem.getName();
+            if (!goldenName.equals(name)) {
+                throw new RuntimeException("Bad structure: expected element name is '" + goldenName + "' but the actual name was '" + name + "'.");
+            }
+            int goldenChildCount = goldenChildren.size();
+            int childCount = elem.getChildCount();
+            if (childCount != goldenChildCount) {
+                System.out.print("D: children: ");
+                for (int i = 0; i < childCount; i++) {
+                    System.out.print(" " + elem.getElement(i).getName());
+                }
+                System.out.println("");
+                System.out.print("D: goldenChildren: ");
+                for (GoldenElement ge : goldenChildren) {
+                    System.out.print(" " + ge.goldenName);
+                }
+                System.out.println("");
+
+                throw new RuntimeException("Bad structure: expected child count of element '" + goldenName + "' is '" + goldenChildCount + "' but the actual count was '" + childCount + "'.");
+            }
+            for (int i = 0; i < childCount; i++) {
+                AbstractDocument.AbstractElement nextElem = (AbstractDocument.AbstractElement) elem.getElement(i);
+                GoldenElement goldenElement = goldenChildren.get(i);
+                goldenElement.checkStructureEquivalence(nextElem);
+            }
+        }
+    }
+
+    private JEditorPane editorPane;
+    public void execute(final String urlStr, final GoldenElement goldenElement) throws Exception {
+        System.out.println();
+        System.out.println("***** TEST: " + urlStr + " *****");
+        System.out.println();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            public void run() {
+                try {
+                    editorPane = new JEditorPane();
+                    editorPane.setEditorKit(new HTMLEditorKit() {
+                        public Document createDefaultDocument() {
+                            AbstractDocument doc =
+                                    (AbstractDocument) super.createDefaultDocument();
+                            doc.setAsynchronousLoadPriority(-1);
+                            return doc;
+                        }
+                    });
+                    editorPane.setPage(new URL(urlStr));
+                } catch (IOException ex) {
+                    throw new RuntimeException("Test failed", ex);
+                }
+                editorPane.setEditable(false);
+                JScrollPane scroller = new JScrollPane();
+                JViewport vp = scroller.getViewport();
+                vp.add(editorPane);
+                add(scroller, BorderLayout.CENTER);
+                setDefaultCloseOperation(EXIT_ON_CLOSE);
+                setSize(400, 400);
+                setLocationRelativeTo(null);
+                setVisible(true);
+            }
+        });
+
+        ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            public void run() {
+                HTMLDocument doc = (HTMLDocument) editorPane.getDocument();
+                doc.dump(System.out);
+                goldenElement.checkStructureEquivalence((AbstractElement) doc.getDefaultRootElement());
+                dispose();
+            }
+        });
+
+        System.out.println();
+        System.out.println("*********************************");
+        System.out.println();
+    }
+
+    public static void main(String[] args) throws Exception {
+
+        String dirURL = getDirURL();
+
+        System.out.println("dirURL = " + dirURL);
+
+        new bug7165725().execute(dirURL + "successive-script-tag.html", createSuccessiveScriptTags());
+        new bug7165725().execute(dirURL + "false-text-after-script.html", createFalseTextAfterScript());
+
+        checkByCallbackForSuccessiveScript();
+        checkByCallbackForFalseTextAfterScript();
+
+        System.out.println();
+        System.out.println();
+        System.out.println("Test passed.");
+    }
+
+    static String getDirURL() {
+        return "file:///" +
+                new File(System.getProperty("test.src", ".")).getAbsolutePath() +
+                File.separator;
+    }
+
+    static String getParsedContentOneLine(String path) throws Exception {
+        File f = new File(path);
+        FileReader fr = new FileReader(f);
+        ParserDelegator pd = new ParserDelegator();
+        SBParserCallback sbcallback = new SBParserCallback();
+        pd.parse(fr, sbcallback, true);
+        fr.close();
+        return sbcallback.getStringOneLine();
+    }
+
+    static String getParsedContentOneLine(URL url) throws Exception {
+        return getParsedContentOneLine(url.getPath());
+    }
+
+    static void checkByCallbackForSuccessiveScript() throws Exception {
+        String content = getParsedContentOneLine(new URL(getDirURL() + "successive-script-tag.html"));
+        if (!content.matches(".*<script .*/js/js1\\.js.*<script .*/js/js2\\.js.*<script .*/js/js3\\.js.*"))
+            throw new RuntimeException("Failed to lookup script tags/attributes.");
+        if (!content.matches(".*<style .*stylesheets/base\\.css.*<style .*stylesheets/adv\\.css.*"))
+            throw new RuntimeException("Failed to lookup style tags.");
+    }
+
+    static void checkByCallbackForFalseTextAfterScript() throws Exception {
+        String content = getParsedContentOneLine(new URL(getDirURL() + "false-text-after-script.html"));
+        final int bodyIdx = content.indexOf("<body ");
+        if (bodyIdx > 0) {
+            String sbody = content.substring(bodyIdx);
+            // There should be no Text(...) in this html
+            if (sbody.indexOf("Text(") >= 0)
+                throw new RuntimeException("Unexpected text found.");
+        } else {
+            throw new RuntimeException("Failed to find body tag.");
+        }
+    }
+
+    private static GoldenElement createSuccessiveScriptTags() {
+        return new GoldenElement("html",
+                new GoldenElement("head",
+                        new GoldenElement("p-implied",
+                                new GoldenElement("title"),
+                                new GoldenElement("title"),
+                                new GoldenElement("script"),
+                                new GoldenElement("comment"),
+                                new GoldenElement("script"),
+                                new GoldenElement("script"),
+                                new GoldenElement("comment"),
+                                new GoldenElement("script"),
+                                new GoldenElement("script"),
+                                new GoldenElement("comment"),
+                                new GoldenElement("script"),
+                                new GoldenElement("content"))),
+                new GoldenElement("body",
+                        new GoldenElement("p-implied",
+                                new GoldenElement("content"))));
+    }
+
+    private static GoldenElement createFalseTextAfterScript() {
+        return new GoldenElement("html",
+                new GoldenElement("head",
+                        new GoldenElement("p-implied",
+                                new GoldenElement("title"),
+                                new GoldenElement("title"),
+                                new GoldenElement("content"))),
+                new GoldenElement("body",
+                        new GoldenElement("form",
+                                new GoldenElement("p-implied",
+                                        new GoldenElement("input"),
+                                        new GoldenElement("input"),
+                                        new GoldenElement("content"))),
+                        new GoldenElement("p-implied",
+                                new GoldenElement("script"),
+                                new GoldenElement("comment"),
+                                new GoldenElement("script"),
+                                new GoldenElement("script"),
+                                new GoldenElement("comment"),
+                                new GoldenElement("script"),
+                                new GoldenElement("content"))));
+    }
+
+    static class SBParserCallback extends HTMLEditorKit.ParserCallback
+    {
+        private int indentSize = 0;
+        private ArrayList<String> elist = new ArrayList<>();
+
+        public String getStringOneLine() {
+            StringBuilder sb = new StringBuilder();
+            for (String s : elist) sb.append(s);
+            return sb.toString();
+        }
+
+        public String toString() {
+            StringBuffer sb = new StringBuffer();
+            for (String s : elist) sb.append(s + "\n");
+            return sb.toString();
+        }
+
+        protected void indent() {
+            indentSize += 3;
+        }
+        protected void unIndent() {
+            indentSize -= 3; if (indentSize < 0) indentSize = 0;
+        }
+
+        protected String pIndent() {
+            StringBuilder sb = new StringBuilder();
+            for(int i = 0; i < indentSize; i++) sb.append(" ");
+            return sb.toString();
+        }
+
+        public void handleText(char[] data, int pos) {
+            elist.add(pIndent() + "Text(" + data.length + " chars) \"" + new String(data) + "\"");
+        }
+
+        public void handleComment(char[] data, int pos) {
+            elist.add(pIndent() + "Comment(" + data.length + " chars)");
+        }
+
+        public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
+            elist.add(pIndent() + "Tag start(<" + t.toString() + " " + a + ">, " +
+                    a.getAttributeCount() + " attrs)");
+            indent();
+        }
+
+        public void handleEndTag(HTML.Tag t, int pos) {
+            unIndent();
+            elist.add(pIndent() + "Tag end(</" + t.toString() + ">)");
+        }
+
+        public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
+            elist.add(pIndent() + "Tag(<" + t.toString() + ">, " +
+                    a.getAttributeCount() + " attrs)");
+        }
+
+        public void handleError(String errorMsg, int pos){
+        }
+    }
+}
diff --git a/test/javax/swing/text/html/parser/Parser/7165725/false-text-after-script.html b/test/javax/swing/text/html/parser/Parser/7165725/false-text-after-script.html
new file mode 100644
index 0000000..36abcdd
--- /dev/null
+++ b/test/javax/swing/text/html/parser/Parser/7165725/false-text-after-script.html
@@ -0,0 +1,20 @@
+<html>
+<head> <title> Testing </title> </head>
+<body>
+<form>
+
+  <input type="text" name="text1" >
+  <input type="button" name="button1" value="button" onclick="test1(this.form)">
+
+</form>
+
+<SCRIPT LANGUAGE="JavaScript">
+  function test1(form) {
+  alert(form.text1.value);
+  }
+</SCRIPT>
+<SCRIPT>
+  history.forward();
+</SCRIPT>
+</body>
+</html>
diff --git a/test/javax/swing/text/html/parser/Parser/7165725/successive-script-tag.html b/test/javax/swing/text/html/parser/Parser/7165725/successive-script-tag.html
new file mode 100644
index 0000000..a751fa2
--- /dev/null
+++ b/test/javax/swing/text/html/parser/Parser/7165725/successive-script-tag.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head><title>my title</title>
+  <script src="../../js/js1.js" language="JavaScript"></script><script src="../../js/js2.js" language="JavaScript"></script><script src="../../js/js3.js" language="JavaScript"></script><style type="text/css" media="screen">@import "stylesheets/base.css";</style><style type="text/css" media="screen">@import "stylesheets/adv.css";</style>
+</head>
+<body>
+</body>
+</html>