changeset 10830:d235efb32901

Merge
author ddehaven
date Tue, 14 Oct 2014 10:47:45 -0700
parents 963ef28a8224 01ed46d7846b
children 996134af077b 20fb01a5fa35 d28aff36d34d
files
diffstat 38 files changed, 871 insertions(+), 389 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	Tue Oct 14 10:47:45 2014 -0700
@@ -567,7 +567,10 @@
                     CWrapper.NSWindow.makeKeyWindow(nsWindowPtr);
                 }
             } else {
+                // immediately hide the window
                 CWrapper.NSWindow.orderOut(nsWindowPtr);
+                // process the close
+                CWrapper.NSWindow.close(nsWindowPtr);
             }
         } else {
             // otherwise, put it in a proper z-order
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CWrapper.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CWrapper.java	Tue Oct 14 10:47:45 2014 -0700
@@ -54,8 +54,26 @@
         static native void orderFront(long window);
         static native void orderFrontRegardless(long window);
         static native void orderWindow(long window, int ordered, long relativeTo);
+
+        /**
+         * Removes the window from the screen.
+         *
+         * @param window the pointer of the NSWindow
+         */
         static native void orderOut(long window);
 
+        /**
+         * Removes the window from the screen and releases it. According to
+         * documentation this method should be similar to {@link #orderOut},
+         * because we use ReleasedWhenClosed:NO, so the window shouldn't be
+         * released. But the close method works differently, for example it
+         * close the space if the window was in the full screen via
+         * {@link CPlatformWindow#toggleFullScreen()}.
+         *
+         * @param window the pointer of the NSWindow
+         */
+        static native void close(long window);
+
         static native void addChildWindow(long parent, long child, int ordered);
         static native void removeChildWindow(long parent, long child);
 
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CWrapper.m	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CWrapper.m	Tue Oct 14 10:47:45 2014 -0700
@@ -175,6 +175,23 @@
 
 /*
  * Class:     sun_lwawt_macosx_CWrapper$NSWindow
+ * Method:    close
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
+Java_sun_lwawt_macosx_CWrapper_00024NSWindow_close
+        (JNIEnv *env, jclass cls, jlong windowPtr)
+{
+JNF_COCOA_ENTER(env);
+    NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr);
+    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
+        [window close];
+    }];
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_lwawt_macosx_CWrapper$NSWindow
  * Method:    orderFrontRegardless
  * Signature: (J)V
  */
--- a/src/java.desktop/share/classes/com/sun/media/sound/AbstractMidiDeviceProvider.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/com/sun/media/sound/AbstractMidiDeviceProvider.java	Tue Oct 14 10:47:45 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2014, 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
@@ -117,7 +117,7 @@
         }
     }
 
-
+    @Override
     public final MidiDevice.Info[] getDeviceInfo() {
         readDeviceInfos();
         Info[] infos = getInfoCache();
@@ -126,7 +126,7 @@
         return localArray;
     }
 
-
+    @Override
     public final MidiDevice getDevice(MidiDevice.Info info) {
         if (info instanceof Info) {
             readDeviceInfos();
@@ -143,9 +143,7 @@
                 }
             }
         }
-
-        throw new IllegalArgumentException("MidiDevice " + info.toString()
-                                           + " not supported by this provider.");
+        throw MidiUtils.unsupportedDevice(info);
     }
 
 
--- a/src/java.desktop/share/classes/com/sun/media/sound/MidiUtils.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/com/sun/media/sound/MidiUtils.java	Tue Oct 14 10:47:45 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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
@@ -25,9 +25,15 @@
 
 package com.sun.media.sound;
 
-import javax.sound.midi.*;
 import java.util.ArrayList;
 
+import javax.sound.midi.MetaMessage;
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.MidiMessage;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Track;
+
 // TODO:
 // - define and use a global symbolic constant for 60000000 (see convertTempo)
 
@@ -48,6 +54,17 @@
     private MidiUtils() {
     }
 
+    /**
+     * Returns an exception which should be thrown if MidiDevice is unsupported.
+     *
+     * @param  info an info object that describes the desired device
+     * @return an exception instance
+     */
+    static RuntimeException unsupportedDevice(final MidiDevice.Info info) {
+        return new IllegalArgumentException(String.format(
+                "MidiDevice %s not supported by this provider", info));
+    }
+
     /** return true if the passed message is Meta End Of Track */
     public static boolean isMetaEndOfTrack(MidiMessage midiMsg) {
         // first check if it is a META message at all
--- a/src/java.desktop/share/classes/com/sun/media/sound/RealTimeSequencer.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/com/sun/media/sound/RealTimeSequencer.java	Tue Oct 14 10:47:45 2014 -0700
@@ -64,7 +64,7 @@
     /**
      * All RealTimeSequencers share this info object.
      */
-    static final RealTimeSequencerInfo info = new RealTimeSequencerInfo();
+    static final MidiDevice.Info info = new RealTimeSequencerInfo();
 
 
     private static final Sequencer.SyncMode[] masterSyncModes = { Sequencer.SyncMode.INTERNAL_CLOCK };
@@ -154,7 +154,7 @@
 
     /* ****************************** CONSTRUCTOR ****************************** */
 
-    RealTimeSequencer() throws MidiUnavailableException {
+    RealTimeSequencer(){
         super(info);
 
         if (Printer.trace) Printer.trace(">> RealTimeSequencer CONSTRUCTOR");
@@ -1088,7 +1088,7 @@
         private static final String description = "Software sequencer";
         private static final String version = "Version 1.0";
 
-        private RealTimeSequencerInfo() {
+        RealTimeSequencerInfo() {
             super(name, vendor, description, version);
         }
     } // class Info
--- a/src/java.desktop/share/classes/com/sun/media/sound/RealTimeSequencerProvider.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/com/sun/media/sound/RealTimeSequencerProvider.java	Tue Oct 14 10:47:45 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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
@@ -26,7 +26,6 @@
 package com.sun.media.sound;
 
 import javax.sound.midi.MidiDevice;
-import javax.sound.midi.MidiUnavailableException;
 import javax.sound.midi.spi.MidiDeviceProvider;
 
 /**
@@ -36,23 +35,16 @@
  */
 public final class RealTimeSequencerProvider extends MidiDeviceProvider {
 
-
+    @Override
     public MidiDevice.Info[] getDeviceInfo() {
-
-        MidiDevice.Info[] localArray = { RealTimeSequencer.info };
-        return localArray;
+        return new MidiDevice.Info[]{RealTimeSequencer.info};
     }
 
-
-    public MidiDevice getDevice(MidiDevice.Info info) {
-        if ((info != null) && (!info.equals(RealTimeSequencer.info))) {
-            return null;
+    @Override
+    public MidiDevice getDevice(final MidiDevice.Info info) {
+        if (RealTimeSequencer.info.equals(info)) {
+            return new RealTimeSequencer();
         }
-
-        try {
-            return new RealTimeSequencer();
-        } catch (MidiUnavailableException e) {
-            return null;
-        }
+        throw MidiUtils.unsupportedDevice(info);
     }
 }
--- a/src/java.desktop/share/classes/com/sun/media/sound/SoftProvider.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/com/sun/media/sound/SoftProvider.java	Tue Oct 14 10:47:45 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2014, 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
@@ -22,11 +22,10 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 package com.sun.media.sound;
 
-import java.util.Arrays;
 import javax.sound.midi.MidiDevice;
-import javax.sound.midi.MidiDevice.Info;
 import javax.sound.midi.spi.MidiDeviceProvider;
 
 /**
@@ -36,17 +35,16 @@
  */
 public final class SoftProvider extends MidiDeviceProvider {
 
-    static final Info softinfo = SoftSynthesizer.info;
-    private static final Info[] softinfos = {softinfo};
-
+    @Override
     public MidiDevice.Info[] getDeviceInfo() {
-        return Arrays.copyOf(softinfos, softinfos.length);
+        return new MidiDevice.Info[]{SoftSynthesizer.info};
     }
 
-    public MidiDevice getDevice(MidiDevice.Info info) {
-        if (info == softinfo) {
+    @Override
+    public MidiDevice getDevice(final MidiDevice.Info info) {
+        if (SoftSynthesizer.info.equals(info)) {
             return new SoftSynthesizer();
         }
-        return null;
+        throw MidiUtils.unsupportedDevice(info);
     }
 }
--- a/src/java.desktop/share/classes/java/awt/GraphicsEnvironment.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/java/awt/GraphicsEnvironment.java	Tue Oct 14 10:47:45 2014 -0700
@@ -182,7 +182,8 @@
                                                      "SunOS".equals(osName) ||
                                                      "FreeBSD".equals(osName) ||
                                                      "NetBSD".equals(osName) ||
-                                                     "OpenBSD".equals(osName)) &&
+                                                     "OpenBSD".equals(osName) ||
+                                                     "AIX".equals(osName)) &&
                                                      (System.getenv("DISPLAY") == null));
                             }
                         }
--- a/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java	Tue Oct 14 10:47:45 2014 -0700
@@ -245,7 +245,7 @@
 
     public static boolean registerService(PrintService service) {
         synchronized (PrintServiceLookup.class) {
-            if (service instanceof StreamPrintService) {
+            if (service == null || service instanceof StreamPrintService) {
                 return false;
             }
             ArrayList<PrintService> registeredServices = getRegisteredServices();
--- a/src/java.desktop/share/classes/javax/sound/midi/MidiSystem.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/javax/sound/midi/MidiSystem.java	Tue Oct 14 10:47:45 2014 -0700
@@ -31,6 +31,7 @@
 import java.io.OutputStream;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -162,18 +163,11 @@
      *         of length 0 is returned.
      */
     public static MidiDevice.Info[] getMidiDeviceInfo() {
-        List<MidiDevice.Info> allInfos = new ArrayList<>();
-        List<MidiDeviceProvider> providers = getMidiDeviceProviders();
-
-        for(int i = 0; i < providers.size(); i++) {
-            MidiDeviceProvider provider = providers.get(i);
-            MidiDevice.Info[] tmpinfo = provider.getDeviceInfo();
-            for (int j = 0; j < tmpinfo.length; j++) {
-                allInfos.add( tmpinfo[j] );
-            }
+        final List<MidiDevice.Info> allInfos = new ArrayList<>();
+        for (final MidiDeviceProvider provider : getMidiDeviceProviders()) {
+            Collections.addAll(allInfos, provider.getDeviceInfo());
         }
-        MidiDevice.Info[] infosArray = allInfos.toArray(new MidiDevice.Info[0]);
-        return infosArray;
+        return allInfos.toArray(new MidiDevice.Info[allInfos.size()]);
     }
 
     /**
@@ -187,17 +181,15 @@
      *         MIDI device installed on the system
      * @see #getMidiDeviceInfo
      */
-    public static MidiDevice getMidiDevice(MidiDevice.Info info) throws MidiUnavailableException {
-        List<MidiDeviceProvider> providers = getMidiDeviceProviders();
-
-        for(int i = 0; i < providers.size(); i++) {
-            MidiDeviceProvider provider = providers.get(i);
+    public static MidiDevice getMidiDevice(final MidiDevice.Info info)
+            throws MidiUnavailableException {
+        for (final MidiDeviceProvider provider : getMidiDeviceProviders()) {
             if (provider.isDeviceSupported(info)) {
-                MidiDevice device = provider.getDevice(info);
-                return device;
+                return provider.getDevice(info);
             }
         }
-        throw new IllegalArgumentException("Requested device not installed: " + info);
+        throw new IllegalArgumentException(String.format(
+                "Requested device not installed: %s", info));
     }
 
     /**
--- a/src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java	Tue Oct 14 10:47:45 2014 -0700
@@ -25,6 +25,8 @@
 
 package javax.sound.midi.spi;
 
+import java.util.Arrays;
+
 import javax.sound.midi.MidiDevice;
 
 /**
@@ -45,16 +47,8 @@
      * @return {@code true} if the specified device is supported, otherwise
      *         {@code false}
      */
-    public boolean isDeviceSupported(MidiDevice.Info info) {
-
-        MidiDevice.Info infos[] = getDeviceInfo();
-
-        for(int i=0; i<infos.length; i++) {
-            if( info.equals( infos[i] ) ) {
-                return true;
-            }
-        }
-        return false;
+    public boolean isDeviceSupported(final MidiDevice.Info info) {
+        return Arrays.asList(getDeviceInfo()).contains(info);
     }
 
     /**
--- a/src/java.desktop/share/classes/javax/swing/JComponent.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/javax/swing/JComponent.java	Tue Oct 14 10:47:45 2014 -0700
@@ -56,6 +56,7 @@
 import java.io.IOException;
 import java.io.ObjectInputValidation;
 import java.io.InvalidObjectException;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.swing.border.*;
 import javax.swing.event.*;
@@ -354,7 +355,8 @@
     private static final int AUTOSCROLLS_SET                          = 25;
     private static final int FOCUS_TRAVERSAL_KEYS_FORWARD_SET         = 26;
     private static final int FOCUS_TRAVERSAL_KEYS_BACKWARD_SET        = 27;
-    private static final int REVALIDATE_RUNNABLE_SCHEDULED            = 28;
+
+    private transient AtomicBoolean revalidateRunnableScheduled = new AtomicBoolean(false);
 
     /**
      * Temporary rectangles.
@@ -4901,16 +4903,11 @@
             // To avoid a flood of Runnables when constructing GUIs off
             // the EDT, a flag is maintained as to whether or not
             // a Runnable has been scheduled.
-            synchronized(this) {
-                if (getFlag(REVALIDATE_RUNNABLE_SCHEDULED)) {
-                    return;
-                }
-                setFlag(REVALIDATE_RUNNABLE_SCHEDULED, true);
+            if (revalidateRunnableScheduled.getAndSet(true)) {
+                return;
             }
             SunToolkit.executeOnEventHandlerThread(this, () -> {
-                synchronized(JComponent.this) {
-                    setFlag(REVALIDATE_RUNNABLE_SCHEDULED, false);
-                }
+                revalidateRunnableScheduled.set(false);
                 revalidate();
             });
         }
@@ -5567,6 +5564,7 @@
             ToolTipManager.sharedInstance().registerComponent(this);
         }
         setWriteObjCounter(this, (byte)0);
+        revalidateRunnableScheduled = new AtomicBoolean(false);
     }
 
 
--- a/src/java.desktop/share/classes/javax/swing/JTable.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/javax/swing/JTable.java	Tue Oct 14 10:47:45 2014 -0700
@@ -3688,17 +3688,17 @@
 //
 
     /**
-     * Sets the data model for this table to <code>newModel</code> and registers
+     * Sets the data model for this table to {@code dataModel} and registers
      * with it for listener notifications from the new data model.
      *
-     * @param   dataModel        the new data source for this table
-     * @exception IllegalArgumentException      if <code>newModel</code> is <code>null</code>
-     * @see     #getModel
+     * @param  dataModel the new data source for this table
+     * @throws IllegalArgumentException if {@code dataModel} is {@code null}
+     * @see #getModel
      * @beaninfo
      *  bound: true
      *  description: The model that is the source of the data for this view.
      */
-    public void setModel(TableModel dataModel) {
+    public void setModel(final TableModel dataModel) {
         if (dataModel == null) {
             throw new IllegalArgumentException("Cannot set a null TableModel");
         }
@@ -3721,29 +3721,30 @@
     }
 
     /**
-     * Returns the <code>TableModel</code> that provides the data displayed by this
-     * <code>JTable</code>.
-     *
-     * @return  the <code>TableModel</code> that provides the data displayed by this <code>JTable</code>
-     * @see     #setModel
+     * Returns the {@code TableModel} that provides the data displayed by this
+     * {@code JTable}.
+     *
+     * @return the {@code TableModel} that provides the data displayed by this
+     *         {@code JTable}
+     * @see #setModel
      */
     public TableModel getModel() {
         return dataModel;
     }
 
     /**
-     * Sets the column model for this table to <code>newModel</code> and registers
-     * for listener notifications from the new column model. Also sets
-     * the column model of the <code>JTableHeader</code> to <code>columnModel</code>.
-     *
-     * @param   columnModel        the new data source for this table
-     * @exception IllegalArgumentException      if <code>columnModel</code> is <code>null</code>
-     * @see     #getColumnModel
+     * Sets the column model for this table to {@code columnModel} and registers
+     * for listener notifications from the new column model. Also sets the
+     * column model of the {@code JTableHeader} to {@code columnModel}.
+     *
+     * @param  columnModel the new data source for this table
+     * @throws IllegalArgumentException if {@code columnModel} is {@code null}
+     * @see #getColumnModel
      * @beaninfo
      *  bound: true
      *  description: The object governing the way columns appear in the view.
      */
-    public void setColumnModel(TableColumnModel columnModel) {
+    public void setColumnModel(final TableColumnModel columnModel) {
         if (columnModel == null) {
             throw new IllegalArgumentException("Cannot set a null ColumnModel");
         }
@@ -3766,54 +3767,55 @@
     }
 
     /**
-     * Returns the <code>TableColumnModel</code> that contains all column information
+     * Returns the {@code TableColumnModel} that contains all column information
      * of this table.
      *
-     * @return  the object that provides the column state of the table
-     * @see     #setColumnModel
+     * @return the object that provides the column state of the table
+     * @see #setColumnModel
      */
     public TableColumnModel getColumnModel() {
         return columnModel;
     }
 
     /**
-     * Sets the row selection model for this table to <code>newModel</code>
+     * Sets the row selection model for this table to {@code selectionModel}
      * and registers for listener notifications from the new selection model.
      *
-     * @param   newModel        the new selection model
-     * @exception IllegalArgumentException      if <code>newModel</code> is <code>null</code>
-     * @see     #getSelectionModel
+     * @param  selectionModel the new selection model
+     * @throws IllegalArgumentException if {@code selectionModel} is
+     *         {@code null}
+     * @see #getSelectionModel
      * @beaninfo
      *      bound: true
      *      description: The selection model for rows.
      */
-    public void setSelectionModel(ListSelectionModel newModel) {
-        if (newModel == null) {
+    public void setSelectionModel(final ListSelectionModel selectionModel) {
+        if (selectionModel == null) {
             throw new IllegalArgumentException("Cannot set a null SelectionModel");
         }
 
-        ListSelectionModel oldModel = selectionModel;
-
-        if (newModel != oldModel) {
+        ListSelectionModel oldModel = this.selectionModel;
+
+        if (selectionModel != oldModel) {
             if (oldModel != null) {
                 oldModel.removeListSelectionListener(this);
             }
 
-            selectionModel = newModel;
-            newModel.addListSelectionListener(this);
-
-            firePropertyChange("selectionModel", oldModel, newModel);
+            this.selectionModel = selectionModel;
+            selectionModel.addListSelectionListener(this);
+
+            firePropertyChange("selectionModel", oldModel, selectionModel);
             repaint();
         }
     }
 
     /**
-     * Returns the <code>ListSelectionModel</code> that is used to maintain row
+     * Returns the {@code ListSelectionModel} that is used to maintain row
      * selection state.
      *
-     * @return  the object that provides row selection state, <code>null</code>
-     *          if row selection is not allowed
-     * @see     #setSelectionModel
+     * @return the object that provides row selection state, {@code null} if row
+     *         selection is not allowed
+     * @see #setSelectionModel
      */
     public ListSelectionModel getSelectionModel() {
         return selectionModel;
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextUI.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextUI.java	Tue Oct 14 10:47:45 2014 -0700
@@ -1122,6 +1122,11 @@
                     Position.Bias b, int direction, Position.Bias[] biasRet)
                     throws BadLocationException{
         Document doc = editor.getDocument();
+
+        if (pos < -1 || pos > doc.getLength()) {
+            throw new BadLocationException("Invalid position", pos);
+        }
+
         if (doc instanceof AbstractDocument) {
             ((AbstractDocument)doc).readLock();
         }
@@ -1594,7 +1599,7 @@
                                              int direction,
                                              Position.Bias[] biasRet)
             throws BadLocationException {
-            if (pos < -1) {
+            if (pos < -1 || pos > getDocument().getLength()) {
                 throw new BadLocationException("invalid position", pos);
             }
             if( view != null ) {
--- a/src/java.desktop/share/classes/javax/swing/text/AsyncBoxView.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/javax/swing/text/AsyncBoxView.java	Tue Oct 14 10:47:45 2014 -0700
@@ -854,7 +854,7 @@
                                          int direction,
                                          Position.Bias[] biasRet)
                                                   throws BadLocationException {
-        if (pos < -1) {
+        if (pos < -1 || pos > getDocument().getLength()) {
             throw new BadLocationException("invalid position", pos);
         }
         return Utilities.getNextVisualPositionFrom(
--- a/src/java.desktop/share/classes/javax/swing/text/CompositeView.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/javax/swing/text/CompositeView.java	Tue Oct 14 10:47:45 2014 -0700
@@ -463,7 +463,7 @@
     public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
                                          int direction, Position.Bias[] biasRet)
       throws BadLocationException {
-        if (pos < -1) {
+        if (pos < -1 || pos > getDocument().getLength()) {
             throw new BadLocationException("invalid position", pos);
         }
         Rectangle alloc = getInsideAllocation(a);
@@ -723,6 +723,9 @@
                                                       Shape a, int direction,
                                                       Position.Bias[] biasRet)
                                                 throws BadLocationException {
+        if (pos < -1 || pos > getDocument().getLength()) {
+            throw new BadLocationException("invalid position", pos);
+        }
         return Utilities.getNextVisualPositionFrom(
                             this, pos, b, a, direction, biasRet);
     }
@@ -754,6 +757,9 @@
                                                     int direction,
                                                     Position.Bias[] biasRet)
                                                 throws BadLocationException {
+        if (pos < -1 || pos > getDocument().getLength()) {
+            throw new BadLocationException("invalid position", pos);
+        }
         return Utilities.getNextVisualPositionFrom(
                             this, pos, b, a, direction, biasRet);
     }
--- a/src/java.desktop/share/classes/javax/swing/text/GlyphView.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/javax/swing/text/GlyphView.java	Tue Oct 14 10:47:45 2014 -0700
@@ -900,7 +900,7 @@
                                          Position.Bias[] biasRet)
         throws BadLocationException {
 
-        if (pos < -1) {
+        if (pos < -1 || pos > getDocument().getLength()) {
             throw new BadLocationException("invalid position", pos);
         }
         return painter.getNextVisualPositionFrom(this, pos, b, a, direction, biasRet);
--- a/src/java.desktop/share/classes/javax/swing/text/View.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/javax/swing/text/View.java	Tue Oct 14 10:47:45 2014 -0700
@@ -500,7 +500,7 @@
     public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
                                          int direction, Position.Bias[] biasRet)
       throws BadLocationException {
-        if (pos < -1) {
+        if (pos < -1 || pos > getDocument().getLength()) {
             // -1 is a reserved value, see the code below
             throw new BadLocationException("Invalid position", pos);
         }
--- a/src/java.desktop/share/classes/sun/datatransfer/DataFlavorUtil.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/classes/sun/datatransfer/DataFlavorUtil.java	Tue Oct 14 10:47:45 2014 -0700
@@ -581,6 +581,15 @@
                     return comp;
                 }
 
+                // Next prefer text types
+                if (flavor1.isFlavorTextType()) {
+                    return 1;
+                }
+
+                if (flavor2.isFlavorTextType()) {
+                    return -1;
+                }
+
                 // Next, look for application/x-java-* types. Prefer unknown
                 // MIME types because if the user provides his own data flavor,
                 // it will likely be the most descriptive one.
--- a/src/java.desktop/share/native/libfontmanager/freetypeScaler.c	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/share/native/libfontmanager/freetypeScaler.c	Tue Oct 14 10:47:45 2014 -0700
@@ -425,7 +425,6 @@
     jobject metrics;
     jfloat ax, ay, dx, dy, bx, by, lx, ly, mx, my;
     jfloat f0 = 0.0;
-    FT_Pos bmodifier = 0;
     FTScalerContext *context =
         (FTScalerContext*) jlong_to_ptr(pScalerContext);
     FTScalerInfo *scalerInfo =
@@ -458,43 +457,38 @@
        So, we have to do adust them explicitly and stay consistent with what
        freetype does to outlines. */
 
-    /* For bolding glyphs are not just widened. Height is also changed
-       (see ftsynth.c).
-
-       TODO: In vertical direction we could do better job and adjust metrics
-       proportionally to glyoh shape. */
-    if (context->doBold) {
-        bmodifier = FT_MulFix(
-                       scalerInfo->face->units_per_EM,
-                       scalerInfo->face->size->metrics.y_scale)/24;
-    }
-
 
     /**** Note: only some metrics are affected by styling ***/
 
+    /* See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=657854 */
+#define FT_MulFixFloatShift6(a, b) (((float) (a)) * ((float) (b)) / 65536.0 / 64.0)
+
+    /*
+     * See FreeType source code: src/base/ftobjs.c ft_recompute_scaled_metrics()
+     * http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=1659
+     */
     /* ascent */
     ax = 0;
-    ay = -(jfloat) FT26Dot6ToFloat(FT_MulFix(
-                       ((jlong) scalerInfo->face->ascender + bmodifier/2),
+    ay = -(jfloat) (FT_MulFixFloatShift6(
+                       ((jlong) scalerInfo->face->ascender),
                        (jlong) scalerInfo->face->size->metrics.y_scale));
     /* descent */
     dx = 0;
-    dy = -(jfloat) FT26Dot6ToFloat(FT_MulFix(
-                       ((jlong) scalerInfo->face->descender + bmodifier/2),
+    dy = -(jfloat) (FT_MulFixFloatShift6(
+                       ((jlong) scalerInfo->face->descender),
                        (jlong) scalerInfo->face->size->metrics.y_scale));
     /* baseline */
     bx = by = 0;
 
     /* leading */
     lx = 0;
-    ly = (jfloat) FT26Dot6ToFloat(FT_MulFix(
-                      (jlong) scalerInfo->face->height + bmodifier,
+    ly = (jfloat) (FT_MulFixFloatShift6(
+                      (jlong) scalerInfo->face->height,
                       (jlong) scalerInfo->face->size->metrics.y_scale))
                   + ay - dy;
     /* max advance */
     mx = (jfloat) FT26Dot6ToFloat(
                      scalerInfo->face->size->metrics.max_advance +
-                     2*bmodifier +
                      OBLIQUE_MODIFIER(scalerInfo->face->size->metrics.height));
     my = 0;
 
--- a/src/java.desktop/unix/native/common/awt/awt_util.h	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/unix/native/common/awt/awt_util.h	Tue Oct 14 10:47:45 2014 -0700
@@ -52,6 +52,8 @@
  */
 extern XErrorHandler current_native_xerror_handler;
 
+Window get_xawt_root_shell(JNIEnv *env);
+
 #endif /* !HEADLESS */
 
 #ifndef INTERSECTS
--- a/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c	Tue Oct 14 10:47:45 2014 -0700
@@ -2011,10 +2011,14 @@
  * Toolkit thread to process PropertyNotify or SelectionNotify events.
  */
 static Bool
-secondary_loop_event(Display* dpy, XEvent* event, char* arg) {
-    return (event->type == SelectionNotify ||
-            event->type == SelectionClear  ||
-            event->type == PropertyNotify) ? True : False;
+secondary_loop_event(Display* dpy, XEvent* event, XPointer xawt_root_window) {
+    return (
+                event->type == SelectionNotify ||
+                event->type == SelectionClear  ||
+                event->type == PropertyNotify  ||
+                (event->type == ConfigureNotify
+                    && event->xany.window == *(Window*) xawt_root_window)
+            ) ? True : False;
 }
 
 
@@ -2025,8 +2029,11 @@
 
     AWT_CHECK_HAVE_LOCK_RETURN(JNI_FALSE);
     exitSecondaryLoop = False;
+    Window xawt_root_window = get_xawt_root_shell(env);
+
     while (!exitSecondaryLoop) {
-        if (XCheckIfEvent((Display*) jlong_to_ptr(display), (XEvent*) jlong_to_ptr(ptr), secondary_loop_event, NULL)) {
+        if (XCheckIfEvent((Display*) jlong_to_ptr(display),
+                (XEvent*) jlong_to_ptr(ptr), secondary_loop_event, (XPointer) &xawt_root_window)) {
             return JNI_TRUE;
         }
         timeout = (timeout < AWT_SECONDARY_LOOP_TIMEOUT) ? (timeout << 1) : AWT_SECONDARY_LOOP_TIMEOUT;
--- a/src/java.desktop/windows/native/libawt/java2d/windows/GDIRenderer.cpp	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/windows/native/libawt/java2d/windows/GDIRenderer.cpp	Tue Oct 14 10:47:45 2014 -0700
@@ -670,7 +670,7 @@
         if (ypoints != NULL) {
             pPoints = TransformPoly(xpoints, ypoints, transx, transy,
                                 tmpPts, &npoints, FALSE, FALSE);
-            env->ReleasePrimitiveArrayCritical(ypointsarray, xpoints, JNI_ABORT);
+            env->ReleasePrimitiveArrayCritical(ypointsarray, ypoints, JNI_ABORT);
         }
         env->ReleasePrimitiveArrayCritical(xpointsarray, xpoints, JNI_ABORT);
     }
--- a/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp	Tue Oct 14 10:47:45 2014 -0700
@@ -3936,7 +3936,6 @@
         DASSERT(stringCls);
         CHECK_NULL(stringCls);
         clauseReading = env->NewObjectArray(cClause, stringCls, NULL);
-        env->DeleteLocalRef(stringCls);
         DASSERT(clauseReading);
         CHECK_NULL(clauseReading);
         for (int i=0; i<cClause; i++)   env->SetObjectArrayElement(clauseReading, i, rgClauseReading[i]);
--- a/src/java.desktop/windows/native/libawt/windows/awt_TextArea.cpp	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/windows/native/libawt/windows/awt_TextArea.cpp	Tue Oct 14 10:47:45 2014 -0700
@@ -47,16 +47,12 @@
 
 jfieldID AwtTextArea::scrollbarVisibilityID;
 
-WNDPROC AwtTextArea::sm_pDefWindowProc = NULL;
-
 /************************************************************************
  * AwtTextArea methods
  */
 
 AwtTextArea::AwtTextArea() {
-    m_bIgnoreEnChange = FALSE;
     m_bCanUndo        = FALSE;
-    m_hEditCtrl       = NULL;
     m_lHDeltaAccum    = 0;
     m_lVDeltaAccum    = 0;
 }
@@ -67,10 +63,6 @@
 
 void AwtTextArea::Dispose()
 {
-    if (m_hEditCtrl != NULL) {
-        VERIFY(::DestroyWindow(m_hEditCtrl));
-        m_hEditCtrl = NULL;
-    }
     AwtTextComponent::Dispose();
 }
 
@@ -91,10 +83,6 @@
     }
 }
 
-void AwtTextArea::EditGetSel(CHARRANGE &cr) {
-    SendMessage(EM_EXGETSEL, 0, reinterpret_cast<LPARAM>(&cr));
-}
-
 /* Count how many '\n's are there in jStr */
 size_t AwtTextArea::CountNewLines(JNIEnv *env, jstring jStr, size_t maxlen)
 {
@@ -149,159 +137,6 @@
     return retValue;
 }
 
-/*
- * This routine is a window procedure for the subclass of the standard edit control
- * used to generate context menu. RichEdit controls don't have built-in context menu.
- * To implement this functionality we have to create an invisible edit control and
- * forward WM_CONTEXTMENU messages from a RichEdit control to this helper edit control.
- * While the edit control context menu is active we intercept the message generated in
- * response to particular item selection and forward it back to the RichEdit control.
- * (See AwtTextArea::WmContextMenu for more details).
- */
-LRESULT
-AwtTextArea::EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
-
-    static BOOL bContextMenuActive = FALSE;
-
-    LRESULT retValue = 0;
-    MsgRouting mr = mrDoDefault;
-
-    DASSERT(::IsWindow(::GetParent(hWnd)));
-
-    switch (message) {
-    case WM_UNDO:
-    case WM_CUT:
-    case WM_COPY:
-    case WM_PASTE:
-    case WM_CLEAR:
-    case EM_SETSEL:
-        if (bContextMenuActive) {
-            ::SendMessage(::GetParent(hWnd), message, wParam, lParam);
-            mr = mrConsume;
-        }
-        break;
-    case WM_CONTEXTMENU:
-        bContextMenuActive = TRUE;
-        break;
-    }
-
-    if (mr == mrDoDefault) {
-        DASSERT(sm_pDefWindowProc != NULL);
-        retValue = ::CallWindowProc(sm_pDefWindowProc,
-                                    hWnd, message, wParam, lParam);
-    }
-
-    if (message == WM_CONTEXTMENU) {
-        bContextMenuActive = FALSE;
-    }
-
-    return retValue;
-}
-
-MsgRouting
-AwtTextArea::WmContextMenu(HWND hCtrl, UINT xPos, UINT yPos) {
-    /* Use the system provided edit control class to generate context menu. */
-    if (m_hEditCtrl == NULL) {
-        DWORD dwStyle = WS_CHILD;
-        DWORD dwExStyle = 0;
-        m_hEditCtrl = ::CreateWindowEx(dwExStyle,
-                                        L"EDIT",
-                                        L"TEXT",
-                                        dwStyle,
-                                        0, 0, 0, 0,
-                                        GetHWnd(),
-                                        reinterpret_cast<HMENU>(
-                                         static_cast<INT_PTR>(
-                                             CreateControlID())),
-                                        AwtToolkit::GetInstance().GetModuleHandle(),
-                                        NULL);
-        DASSERT(m_hEditCtrl != NULL);
-        if (sm_pDefWindowProc == NULL) {
-            sm_pDefWindowProc = (WNDPROC)::GetWindowLongPtr(m_hEditCtrl,
-                                                         GWLP_WNDPROC);
-        }
-        ::SetLastError(0);
-        INT_PTR ret = ::SetWindowLongPtr(m_hEditCtrl, GWLP_WNDPROC,
-                                   (INT_PTR)AwtTextArea::EditProc);
-        DASSERT(ret != 0 || ::GetLastError() == 0);
-    }
-
-    /*
-     * Tricks on the edit control to ensure that its context menu has
-     * the correct set of enabled items according to the RichEdit state.
-     */
-    ::SetWindowText(m_hEditCtrl, TEXT("TEXT"));
-
-    if (m_bCanUndo == TRUE && SendMessage(EM_CANUNDO)) {
-        /* Enable 'Undo' item. */
-        ::SendMessage(m_hEditCtrl, WM_CHAR, 'A', 0);
-    }
-
-    {
-        /*
-         * Initial selection for the edit control - (0,1).
-         * This enables 'Cut', 'Copy' and 'Delete' and 'Select All'.
-         */
-        INT nStart = 0;
-        INT nEnd = 1;
-        if (SendMessage(EM_SELECTIONTYPE) == SEL_EMPTY) {
-            /*
-             * RichEdit selection is empty - clear selection of the edit control.
-             * This disables 'Cut', 'Copy' and 'Delete'.
-             */
-            nStart = -1;
-            nEnd = 0;
-        } else {
-
-            CHARRANGE cr;
-            EditGetSel(cr);
-            /* Check if all the text is selected. */
-            if (cr.cpMin == 0) {
-
-                int len = ::GetWindowTextLength(GetHWnd());
-                if (cr.cpMin == 0 && cr.cpMax >= len) {
-                    /*
-                     * All the text is selected in RichEdit - select all the
-                     * text in the edit control. This disables 'Select All'.
-                     */
-                    nStart = 0;
-                    nEnd = -1;
-                }
-            }
-        }
-        ::SendMessage(m_hEditCtrl, EM_SETSEL, (WPARAM)nStart, (LPARAM)nEnd);
-    }
-
-    /* Disable 'Paste' item if the RichEdit control is read-only. */
-    ::SendMessage(m_hEditCtrl, EM_SETREADONLY,
-                  GetStyle() & ES_READONLY ? TRUE : FALSE, 0);
-
-    POINT p;
-    p.x = xPos;
-    p.y = yPos;
-
-    /*
-     * If the context menu is requested with SHIFT+F10 or VK_APPS key,
-     * we position its top left corner to the center of the RichEdit
-     * client rect.
-     */
-    if (p.x == -1 && p.y == -1) {
-        RECT r;
-        VERIFY(::GetClientRect(GetHWnd(), &r));
-        p.x = (r.left + r.right) / 2;
-        p.y = (r.top + r.bottom) / 2;
-        VERIFY(::ClientToScreen(GetHWnd(), &p));
-    }
-
-    // The context menu steals focus from the proxy.
-    // So, set the focus-restore flag up.
-    SetRestoreFocus(TRUE);
-    ::SendMessage(m_hEditCtrl, WM_CONTEXTMENU, (WPARAM)m_hEditCtrl, MAKELPARAM(p.x, p.y));
-    SetRestoreFocus(FALSE);
-
-    return mrConsume;
-}
-
 MsgRouting
 AwtTextArea::WmNcHitTest(UINT x, UINT y, LRESULT& retVal)
 {
@@ -314,27 +149,8 @@
 
 
 MsgRouting
-AwtTextArea::WmNotify(UINT notifyCode)
-{
-    if (notifyCode == EN_CHANGE) {
-        /*
-         * Ignore notifications if the text hasn't been changed.
-         * EN_CHANGE sent on character formatting changes as well.
-         */
-        if (m_bIgnoreEnChange == FALSE) {
-            m_bCanUndo = TRUE;
-            DoCallback("valueChanged", "()V");
-        } else {
-            m_bCanUndo = FALSE;
-        }
-    }
-    return mrDoDefault;
-}
-
-MsgRouting
 AwtTextArea::HandleEvent(MSG *msg, BOOL synthetic)
 {
-    MsgRouting returnVal;
     /*
      * RichEdit 1.0 control starts internal message loop if the
      * left mouse button is pressed while the cursor is not over
@@ -486,26 +302,6 @@
         }
         delete msg;
         return mrConsume;
-    } else if (msg->message == WM_RBUTTONUP ||
-               (msg->message == WM_SYSKEYDOWN && msg->wParam == VK_F10 &&
-                HIBYTE(::GetKeyState(VK_SHIFT)))) {
-        POINT p;
-        if (msg->message == WM_RBUTTONUP) {
-            VERIFY(::GetCursorPos(&p));
-        } else {
-            p.x = -1;
-            p.y = -1;
-        }
-
-        if (!::PostMessage(GetHWnd(), WM_CONTEXTMENU, (WPARAM)GetHWnd(),
-                           MAKELPARAM(p.x, p.y))) {
-            JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
-            JNU_ThrowInternalError(env, "Message not posted, native event queue may be full.");
-            env->ExceptionDescribe();
-            env->ExceptionClear();
-        }
-        delete msg;
-        return mrConsume;
     } else if (msg->message == WM_MOUSEWHEEL) {
         // 4417236: If there is an old version of RichEd32.dll which
         // does not provide the mouse wheel scrolling we have to
@@ -596,15 +392,7 @@
         // 4417236: end of fix
     }
 
-    /*
-     * Store the 'synthetic' parameter so that the WM_PASTE security check
-     * happens only for synthetic events.
-     */
-    m_synthetic = synthetic;
-    returnVal = AwtComponent::HandleEvent(msg, synthetic);
-    m_synthetic = FALSE;
-
-    return returnVal;
+    return AwtTextComponent::HandleEvent(msg, synthetic);
 }
 
 
--- a/src/java.desktop/windows/native/libawt/windows/awt_TextArea.h	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/windows/native/libawt/windows/awt_TextArea.h	Tue Oct 14 10:47:45 2014 -0700
@@ -57,17 +57,11 @@
     static size_t GetALength(JNIEnv* env, jstring jStr, size_t maxlen);
 
     LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
-    static LRESULT CALLBACK EditProc(HWND hWnd, UINT message,
-                                     WPARAM wParam, LPARAM lParam);
 
     MsgRouting WmEnable(BOOL fEnabled);
-    MsgRouting WmContextMenu(HWND hCtrl, UINT xPos, UINT yPos);
-    MsgRouting WmNotify(UINT notifyCode);
     MsgRouting WmNcHitTest(UINT x, UINT y, LRESULT &retVal);
     MsgRouting HandleEvent(MSG *msg, BOOL synthetic);
 
-    INLINE void SetIgnoreEnChange(BOOL b) { m_bIgnoreEnChange = b; }
-
     virtual BOOL InheritsNativeMouseWheelBehavior();
     virtual void Reshape(int x, int y, int w, int h);
 
@@ -81,22 +75,7 @@
 protected:
 
     void EditSetSel(CHARRANGE &cr);
-    void EditGetSel(CHARRANGE &cr);
   private:
-    // RichEdit 1.0 control generates EN_CHANGE notifications not only
-    // on text changes, but also on any character formatting change.
-    // This flag is true when the latter case is detected.
-    BOOL    m_bIgnoreEnChange;
-
-    // RichEdit 1.0 control undoes a character formatting change
-    // if it is the latest. We don't create our own undo buffer,
-    // but just prohibit undo in case if the latest operation
-    // is a formatting change.
-    BOOL    m_bCanUndo;
-
-    HWND    m_hEditCtrl;
-    static WNDPROC sm_pDefWindowProc;
-
     LONG    m_lHDeltaAccum;
     LONG    m_lVDeltaAccum;
 
--- a/src/java.desktop/windows/native/libawt/windows/awt_TextComponent.cpp	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/windows/native/libawt/windows/awt_TextComponent.cpp	Tue Oct 14 10:47:45 2014 -0700
@@ -66,6 +66,8 @@
     m_lLastPos  = -1;
     m_isLFonly        = FALSE;
     m_EOLchecked      = FALSE;
+    m_hEditCtrl       = NULL;
+    m_bIgnoreEnChange = FALSE;
 //    javaEventsMask = 0;    // accessibility support
 }
 
@@ -213,6 +215,16 @@
     return c;
 }
 
+void AwtTextComponent::Dispose()
+{
+    if (m_hEditCtrl != NULL) {
+        VERIFY(::DestroyWindow(m_hEditCtrl));
+        m_hEditCtrl = NULL;
+    }
+    AwtComponent::Dispose();
+}
+
+
 LRESULT
 AwtTextComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
 
@@ -322,7 +334,16 @@
 AwtTextComponent::WmNotify(UINT notifyCode)
 {
     if (notifyCode == EN_CHANGE) {
-      DoCallback("valueChanged", "()V");
+        /*
+         * Ignore notifications if the text hasn't been changed.
+         * EN_CHANGE sent on character formatting changes as well.
+         */
+        if (m_bIgnoreEnChange == FALSE) {
+            m_bCanUndo = TRUE;
+            DoCallback("valueChanged", "()V");
+        } else {
+            m_bCanUndo = FALSE;
+        }
     }
     return mrDoDefault;
 }
@@ -337,6 +358,28 @@
 {
     MsgRouting returnVal;
 
+    if (msg->message == WM_RBUTTONUP ||
+               (msg->message == WM_SYSKEYDOWN && msg->wParam == VK_F10 &&
+                HIBYTE(::GetKeyState(VK_SHIFT)))) {
+        POINT p;
+        if (msg->message == WM_RBUTTONUP) {
+            VERIFY(::GetCursorPos(&p));
+        } else {
+            p.x = -1;
+            p.y = -1;
+        }
+
+        if (!::PostMessage(GetHWnd(), WM_CONTEXTMENU, (WPARAM)GetHWnd(),
+                           MAKELPARAM(p.x, p.y))) {
+            JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
+            JNU_ThrowInternalError(env, "Message not posted, native event queue may be full.");
+            env->ExceptionDescribe();
+            env->ExceptionClear();
+        }
+        delete msg;
+        return mrConsume;
+    }
+
     /*
      * Store the 'synthetic' parameter so that the WM_PASTE security check
      * happens only for synthetic events.
@@ -701,6 +744,10 @@
     SendMessage(EM_SETBKGNDCOLOR, (WPARAM)FALSE, (LPARAM)GetBackgroundColor());
 }
 
+void AwtTextComponent::EditGetSel(CHARRANGE &cr) {
+    SendMessage(EM_EXGETSEL, 0, reinterpret_cast<LPARAM>(&cr));
+}
+
 
 /************************************************************************
  * WTextComponentPeer native methods
@@ -983,6 +1030,161 @@
 }
 
 
+/*
+ * This routine is a window procedure for the subclass of the standard edit control
+ * used to generate context menu. RichEdit controls don't have built-in context menu.
+ * To implement this functionality we have to create an invisible edit control and
+ * forward WM_CONTEXTMENU messages from a RichEdit control to this helper edit control.
+ * While the edit control context menu is active we intercept the message generated in
+ * response to particular item selection and forward it back to the RichEdit control.
+ * (See AwtTextArea::WmContextMenu for more details).
+ */
+
+WNDPROC AwtTextComponent::sm_pDefWindowProc = NULL;
+
+LRESULT
+AwtTextComponent::EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
+
+    static BOOL bContextMenuActive = FALSE;
+
+    LRESULT retValue = 0;
+    MsgRouting mr = mrDoDefault;
+
+    DASSERT(::IsWindow(::GetParent(hWnd)));
+
+    switch (message) {
+    case WM_UNDO:
+    case WM_CUT:
+    case WM_COPY:
+    case WM_PASTE:
+    case WM_CLEAR:
+    case EM_SETSEL:
+        if (bContextMenuActive) {
+            ::SendMessage(::GetParent(hWnd), message, wParam, lParam);
+            mr = mrConsume;
+        }
+        break;
+    case WM_CONTEXTMENU:
+        bContextMenuActive = TRUE;
+        break;
+    }
+
+    if (mr == mrDoDefault) {
+        DASSERT(sm_pDefWindowProc != NULL);
+        retValue = ::CallWindowProc(sm_pDefWindowProc,
+                                    hWnd, message, wParam, lParam);
+    }
+
+    if (message == WM_CONTEXTMENU) {
+        bContextMenuActive = FALSE;
+    }
+
+    return retValue;
+}
+
+MsgRouting
+AwtTextComponent::WmContextMenu(HWND hCtrl, UINT xPos, UINT yPos) {
+    /* Use the system provided edit control class to generate context menu. */
+    if (m_hEditCtrl == NULL) {
+        DWORD dwStyle = WS_CHILD;
+        DWORD dwExStyle = 0;
+        m_hEditCtrl = ::CreateWindowEx(dwExStyle,
+                                        L"EDIT",
+                                        L"TEXT",
+                                        dwStyle,
+                                        0, 0, 0, 0,
+                                        GetHWnd(),
+                                        reinterpret_cast<HMENU>(
+                                         static_cast<INT_PTR>(
+                                             CreateControlID())),
+                                        AwtToolkit::GetInstance().GetModuleHandle(),
+                                        NULL);
+        DASSERT(m_hEditCtrl != NULL);
+        if (sm_pDefWindowProc == NULL) {
+            sm_pDefWindowProc = (WNDPROC)::GetWindowLongPtr(m_hEditCtrl,
+                                                         GWLP_WNDPROC);
+        }
+        ::SetLastError(0);
+        INT_PTR ret = ::SetWindowLongPtr(m_hEditCtrl, GWLP_WNDPROC,
+                                   (INT_PTR)AwtTextArea::EditProc);
+        DASSERT(ret != 0 || ::GetLastError() == 0);
+    }
+
+    /*
+     * Tricks on the edit control to ensure that its context menu has
+     * the correct set of enabled items according to the RichEdit state.
+     */
+    ::SetWindowText(m_hEditCtrl, TEXT("TEXT"));
+
+    if (m_bCanUndo == TRUE && SendMessage(EM_CANUNDO)) {
+        /* Enable 'Undo' item. */
+        ::SendMessage(m_hEditCtrl, WM_CHAR, 'A', 0);
+    }
+
+    {
+        /*
+         * Initial selection for the edit control - (0,1).
+         * This enables 'Cut', 'Copy' and 'Delete' and 'Select All'.
+         */
+        INT nStart = 0;
+        INT nEnd = 1;
+        if (SendMessage(EM_SELECTIONTYPE) == SEL_EMPTY) {
+            /*
+             * RichEdit selection is empty - clear selection of the edit control.
+             * This disables 'Cut', 'Copy' and 'Delete'.
+             */
+            nStart = -1;
+            nEnd = 0;
+        } else {
+
+            CHARRANGE cr;
+            EditGetSel(cr);
+            /* Check if all the text is selected. */
+            if (cr.cpMin == 0) {
+
+                int len = ::GetWindowTextLength(GetHWnd());
+                if (cr.cpMin == 0 && cr.cpMax >= len) {
+                    /*
+                     * All the text is selected in RichEdit - select all the
+                     * text in the edit control. This disables 'Select All'.
+                     */
+                    nStart = 0;
+                    nEnd = -1;
+                }
+            }
+        }
+        ::SendMessage(m_hEditCtrl, EM_SETSEL, (WPARAM)nStart, (LPARAM)nEnd);
+    }
+
+    /* Disable 'Paste' item if the RichEdit control is read-only. */
+    ::SendMessage(m_hEditCtrl, EM_SETREADONLY,
+                  GetStyle() & ES_READONLY ? TRUE : FALSE, 0);
+
+    POINT p;
+    p.x = xPos;
+    p.y = yPos;
+
+    /*
+     * If the context menu is requested with SHIFT+F10 or VK_APPS key,
+     * we position its top left corner to the center of the RichEdit
+     * client rect.
+     */
+    if (p.x == -1 && p.y == -1) {
+        RECT r;
+        VERIFY(::GetClientRect(GetHWnd(), &r));
+        p.x = (r.left + r.right) / 2;
+        p.y = (r.top + r.bottom) / 2;
+        VERIFY(::ClientToScreen(GetHWnd(), &p));
+    }
+
+    // The context menu steals focus from the proxy.
+    // So, set the focus-restore flag up.
+    SetRestoreFocus(TRUE);
+    ::SendMessage(m_hEditCtrl, WM_CONTEXTMENU, (WPARAM)m_hEditCtrl, MAKELPARAM(p.x, p.y));
+    SetRestoreFocus(FALSE);
+
+    return mrConsume;
+}
 
 //
 // Accessibility support
--- a/src/java.desktop/windows/native/libawt/windows/awt_TextComponent.h	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/windows/native/libawt/windows/awt_TextComponent.h	Tue Oct 14 10:47:45 2014 -0700
@@ -47,6 +47,8 @@
 
     static AwtTextComponent* Create(jobject self, jobject parent, BOOL isMultiline);
 
+    virtual void Dispose();
+
     virtual LPCTSTR GetClassName();
     LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
 
@@ -83,6 +85,8 @@
     MsgRouting HandleEvent(MSG *msg, BOOL synthetic);
     MsgRouting WmPaste();
 
+    INLINE void SetIgnoreEnChange(BOOL b) { m_bIgnoreEnChange = b; }
+
     virtual BOOL IsFocusingMouseMessage(MSG *pMsg);
 
 /*  To be fully implemented in a future release
@@ -115,11 +119,24 @@
     INLINE VOID SetEndSelectionPos(LONG lPos) { m_lEndPos = lPos; }
     INLINE VOID SetLastSelectionPos(LONG lPos) { m_lLastPos = lPos; }
 
+    void EditGetSel(CHARRANGE &cr);
+
     // Used to prevent untrusted code from synthesizing a WM_PASTE message
     // by posting a <CTRL>-V KeyEvent
     BOOL    m_synthetic;
     LONG EditGetCharFromPos(POINT& pt);
 
+    // RichEdit 1.0 control generates EN_CHANGE notifications not only
+    // on text changes, but also on any character formatting change.
+    // This flag is true when the latter case is detected.
+    BOOL    m_bIgnoreEnChange;
+
+    // RichEdit 1.0 control undoes a character formatting change
+    // if it is the latest. We don't create our own undo buffer,
+    // but just prohibit undo in case if the latest operation
+    // is a formatting change.
+    BOOL    m_bCanUndo;
+
     /*****************************************************************
      * Inner class OleCallback declaration.
      */
@@ -166,6 +183,13 @@
 
     static OleCallback sm_oleCallback;
 
+    static WNDPROC sm_pDefWindowProc;
+    HWND    m_hEditCtrl;
+
+    static LRESULT CALLBACK EditProc(HWND hWnd, UINT message,
+                                     WPARAM wParam, LPARAM lParam);
+    MsgRouting WmContextMenu(HWND hCtrl, UINT xPos, UINT yPos);
+
     //
     // Accessibility support
     //
--- a/src/java.desktop/windows/native/libawt/windows/awt_TextField.cpp	Tue Oct 14 11:39:07 2014 -0700
+++ b/src/java.desktop/windows/native/libawt/windows/awt_TextField.cpp	Tue Oct 14 10:47:45 2014 -0700
@@ -249,13 +249,7 @@
         }
     }
 
-    /*
-     * Store the 'synthetic' parameter so that the WM_PASTE security check
-     * happens only for synthetic events.
-     */
-    m_synthetic = synthetic;
-    returnVal = AwtComponent::HandleEvent(msg, synthetic);
-    m_synthetic = FALSE;
+    returnVal = AwtTextComponent::HandleEvent(msg, synthetic);
 
     if(systemBeeperEnabled){
         SystemParametersInfo(SPI_SETBEEP, 1, NULL, 0);
--- a/test/java/awt/Focus/SortingFPT/JDK8048887.java	Tue Oct 14 11:39:07 2014 -0700
+++ b/test/java/awt/Focus/SortingFPT/JDK8048887.java	Tue Oct 14 10:47:45 2014 -0700
@@ -26,7 +26,7 @@
   @bug       8048887
   @summary   Tests SortingFTP for an exception caused by the tim-sort algo.
   @author    anton.tarasov: area=awt.focus
-  @run       main JDK8040632
+  @run       main JDK8048887
 */
 
 import javax.swing.JFrame;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.java	Tue Oct 14 10:47:45 2014 -0700
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+/*
+ * Portions Copyright (c) 2014 IBM Corporation
+ */
+
+public class TestDetectHeadless {
+    public static void main(String[] args) throws Exception {
+        Class.forName("javax.swing.plaf.basic.BasicInternalFrameTitlePane");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh	Tue Oct 14 10:47:45 2014 -0700
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2014, 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.
+#
+
+#
+# Portions Copyright (c) 2014 IBM Corporation
+#
+
+# @test
+# @bug 8058930
+# @summary java.awt.GraphicsEnvironment.getHeadlessProperty() does not work for AIX
+#
+# @build TestDetectHeadless
+# @run shell TestDetectHeadless.sh
+
+OS=`uname -s`
+case "$OS" in
+    Windows* | CYGWIN* )
+        echo "Passed"; exit 0 ;;
+    * ) unset DISPLAY ;;
+esac
+
+${TESTJAVA}/bin/java ${TESTVMOPTS} \
+    -cp ${TESTCLASSES} TestDetectHeadless
+
+exit $?
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/print/RegisterNullService.java	Tue Oct 14 10:47:45 2014 -0700
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014, 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 8059219
+ * @summary Should not be able to register null service.
+ * @run main RegisterNullService
+*/
+
+import javax.print.PrintService;
+import javax.print.PrintServiceLookup;
+
+public class RegisterNullService {
+    public static void main (String [] args) throws RuntimeException {
+
+        boolean registered = PrintServiceLookup.registerService(null);
+        if (registered) {
+           throw new RuntimeException("Null service was registered");
+        }
+        PrintService[] services =
+            PrintServiceLookup.lookupPrintServices(null, null);
+        for (int i = 0; i < services.length; i++) {
+            if (services[i] == null) {
+                throw new RuntimeException("Null service found.");
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MidiDeviceProvider/NullInfo.java	Tue Oct 14 10:47:45 2014 -0700
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.spi.MidiDeviceProvider;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 8058115
+ * @summary MidiDeviceProvider shouldn't returns incorrect results or throw NPE
+ *          in case of null MidiDevice.Info
+ * @author Sergey Bylokhov
+ */
+public final class NullInfo {
+
+    public static void main(final String[] args) {
+        // MidiSystem API
+        try {
+            MidiSystem.getMidiDevice(null);
+            throw new RuntimeException("IllegalArgumentException expected");
+        } catch (final MidiUnavailableException e) {
+            throw new RuntimeException("IllegalArgumentException expected", e);
+        } catch (final IllegalArgumentException ignored) {
+            // expected
+        }
+        // MidiDeviceProvider API
+        final Collection<String> errors = new HashSet<>();
+        for (final MidiDeviceProvider mdp : load(MidiDeviceProvider.class)) {
+            try {
+                if (mdp.isDeviceSupported(null)) {
+                    throw new RuntimeException("null is supported");
+                }
+                final MidiDevice device = mdp.getDevice(null);
+                System.err.println("MidiDevice: " + device);
+                throw new RuntimeException("IllegalArgumentException expected");
+            } catch (final IllegalArgumentException e) {
+                errors.add(e.getMessage());
+            }
+        }
+        if (errors.size() != 1) {
+            throw new RuntimeException("Wrong number of messages:" + errors);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/sound/midi/MidiDeviceProvider/UnsupportedInfo.java	Tue Oct 14 10:47:45 2014 -0700
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.spi.MidiDeviceProvider;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 8058115
+ * @summary MidiDeviceProvider shouldn't returns incorrect results in case of
+ *          unsupported MidiDevice.Info
+ * @author Sergey Bylokhov
+ */
+public final class UnsupportedInfo {
+
+    public static void main(final String[] args) {
+        final MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
+        for (final MidiDeviceProvider mdp : load(MidiDeviceProvider.class)) {
+            for (final MidiDevice.Info info : infos) {
+                if (mdp.isDeviceSupported(info)) {
+                    if (mdp.getDevice(info) == null) {
+                        throw new RuntimeException("MidiDevice is null");
+                    }
+                } else {
+                    try {
+                        mdp.getDevice(info);
+                        throw new RuntimeException(
+                                "IllegalArgumentException expected");
+                    } catch (final IllegalArgumentException ignored) {
+                        // expected
+                    }
+                }
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/text/NavigationFilter/8058305/bug8058305.java	Tue Oct 14 10:47:45 2014 -0700
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.NavigationFilter;
+import javax.swing.text.Position;
+
+/*
+ * @test
+ * @bug 8058305
+ * @summary BadLocationException is not thrown by
+ *   javax.swing.text.View.getNextVisualPositionFrom() for invalid positions
+ * @run main bug8058305
+ */
+public class bug8058305 {
+
+    public static void main(String[] args) throws Exception {
+        SwingUtilities.invokeAndWait(bug8058305::createAndShowGUI);
+    }
+
+    private static void createAndShowGUI() {
+        JFrame frame = new JFrame();
+
+        JFormattedTextField textField = new JFormattedTextField();
+        NavigationFilter navigationFilter = new NavigationFilter();
+        textField.setText("Test for Tests");
+        frame.getContentPane().add(textField);
+        frame.pack();
+
+        Position.Bias[] biasRet = {Position.Bias.Forward};
+        try {
+            navigationFilter.getNextVisualPositionFrom(textField, 100,
+                    Position.Bias.Backward, SwingConstants.EAST, biasRet);
+            throw new RuntimeException("BadLocationException is not thrown!");
+        } catch (BadLocationException expectedException) {
+        }
+
+        frame.setVisible(true);
+
+        try {
+            navigationFilter.getNextVisualPositionFrom(textField, 200,
+                    Position.Bias.Forward, SwingConstants.WEST, biasRet);
+            throw new RuntimeException("BadLocationException is not thrown!");
+        } catch (BadLocationException expectedException) {
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/awt/datatransfer/DataFlavorComparatorTest1.java	Tue Oct 14 10:47:45 2014 -0700
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2014, 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 8058473
+   @summary "Comparison method violates its general contract" when using Clipboard
+            Ensure that DataFlavorComparator conforms to Comparator contract
+   @author Anton Nashatyrev
+   @run main DataFlavorComparatorTest1
+*/
+import sun.datatransfer.DataFlavorUtil;
+
+import java.awt.datatransfer.DataFlavor;
+import java.util.Comparator;
+
+public class DataFlavorComparatorTest1 {
+
+    public static void main(String[] args) throws Exception {
+        String[] mimes = new String[] {
+                "text/plain",
+                "text/plain; charset=unicode",
+                "text/plain; charset=cp1251",
+                "text/plain; charset=unicode; class=java.io.InputStream",
+                "text/plain; charset=unicode; class=java.io.Serializable",
+                "text/plain; charset=unicode; class=java.lang.Object",
+                "text/plain; class=java.lang.String",
+                "text/plain; class=java.io.Reader",
+                "text/plain; class=java.lang.Object",
+                "text/html",
+                "text/html; charset=unicode",
+                "text/html; charset=cp1251",
+                "text/html; charset=unicode; class=java.io.InputStream",
+                "text/html; charset=unicode; class=java.io.Serializable",
+                "text/html; charset=unicode; class=java.lang.Object",
+                "text/html; class=java.lang.String",
+                "text/html; class=java.io.Reader",
+                "text/html; class=java.lang.Object",
+                "text/unknown",
+                "text/unknown; charset=unicode",
+                "text/unknown; charset=cp1251",
+                "text/unknown; charset=unicode; class=java.io.InputStream",
+                "text/unknown; charset=unicode; class=java.io.Serializable",
+                "text/unknown; charset=unicode; class=java.lang.Object",
+                "text/unknown; class=java.lang.String",
+                "text/unknown; class=java.io.Reader",
+                "text/unknown; class=java.lang.Object",
+                "application/unknown; class=java.io.InputStream",
+                "application/unknown; class=java.lang.Object",
+                "application/unknown",
+                "application/x-java-jvm-local-objectref; class=java.io.InputStream",
+                "application/x-java-jvm-local-objectref; class=java.lang.Object",
+                "application/x-java-jvm-local-objectref",
+                "unknown/flavor",
+                "unknown/flavor; class=java.io.InputStream",
+                "unknown/flavor; class=java.lang.Object",
+        };
+
+        DataFlavor[] flavors = new DataFlavor[mimes.length];
+        for (int i = 0; i < flavors.length; i++) {
+            flavors[i] = new DataFlavor(mimes[i]);
+        }
+
+        testComparator(DataFlavorUtil.getDataFlavorComparator(), flavors);
+
+        System.out.println("Passed.");
+    }
+
+    private static void testComparator(Comparator cmp, DataFlavor[] flavs)
+            throws ClassNotFoundException {
+
+        for (DataFlavor x: flavs) {
+            for (DataFlavor y: flavs) {
+                if (Math.signum(cmp.compare(x,y)) != -Math.signum(cmp.compare(y,x))) {
+                    throw new RuntimeException("Antisymmetry violated: " + x + ", " + y);
+                }
+                if (cmp.compare(x,y) == 0 && !x.equals(y)) {
+                    throw new RuntimeException("Equals rule violated: " + x + ", " + y);
+                }
+                for (DataFlavor z: flavs) {
+                    if (cmp.compare(x,y) == 0) {
+                        if (Math.signum(cmp.compare(x, z)) != Math.signum(cmp.compare(y, z))) {
+                            throw new RuntimeException("Transitivity (1) violated: " + x + ", " + y + ", " + z);
+                        }
+                    } else {
+                        if (Math.signum(cmp.compare(x, y)) == Math.signum(cmp.compare(y, z))) {
+                            if (Math.signum(cmp.compare(x, y)) != Math.signum(cmp.compare(x, z))) {
+                                throw new RuntimeException("Transitivity (2) violated: " + x + ", " + y + ", " + z);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}