--- old/jdk/src/java.desktop/windows/native/libawt/windows/awt_TextComponent.h 2015-09-18 17:00:22.640399000 +0530 +++ new/jdk/src/java.desktop/windows/native/libawt/windows/awt_TextComponent.h 2015-09-18 17:00:22.488323000 +0530 @@ -53,6 +53,7 @@ LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); int RemoveCR(WCHAR *pStr); + INLINE virtual int RemoveEOL(WCHAR *pStr) { return 0; } virtual LONG getJavaSelPos(LONG orgPos); virtual LONG getWin32SelPos(LONG orgPos); --- old/jdk/src/java.desktop/windows/native/libawt/windows/awt_TextComponent.cpp 2015-09-18 17:00:23.084620999 +0530 +++ new/jdk/src/java.desktop/windows/native/libawt/windows/awt_TextComponent.cpp 2015-09-18 17:00:22.900528999 +0530 @@ -511,7 +511,6 @@ m_isLFonly = TRUE; } m_EOLchecked = TRUE; - return; } } } @@ -590,6 +589,7 @@ buffer[length] = 0; c->CheckLineSeparator(buffer); c->RemoveCR(buffer); + c->RemoveEOL(buffer); c->SetText(buffer); delete[] buffer; } --- old/jdk/src/java.desktop/windows/native/libawt/windows/awt_TextField.h 2015-09-18 17:00:23.584870999 +0530 +++ new/jdk/src/java.desktop/windows/native/libawt/windows/awt_TextField.h 2015-09-18 17:00:23.408783000 +0530 @@ -53,6 +53,7 @@ virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); // invoked on Toolkit thread static void _SetEchoChar(void *param); + int RemoveEOL(WCHAR *pStr); protected: --- old/jdk/src/java.desktop/windows/native/libawt/windows/awt_TextField.cpp 2015-09-18 17:00:24.157156999 +0530 +++ new/jdk/src/java.desktop/windows/native/libawt/windows/awt_TextField.cpp 2015-09-18 17:00:23.917037000 +0530 @@ -283,6 +283,38 @@ delete secs; } +/* +Remove any LF, CRLF i.e. EOL characters from pStr +*/ +int AwtTextField::RemoveEOL(WCHAR *pStr) +{ + int i, nLen = 0; + if (pStr) { + /* check to see if there are any LF's */ + if (wcschr(pStr, L'\n') == NULL) { + return static_cast(wcslen(pStr)); + } + + for (i = 0; pStr[i] != 0; i++) { + if (m_isLFonly == TRUE) { + if (pStr[i] == L'\n') { + pStr[nLen++] = ' '; + continue; + } + } + else { + if (pStr[i] == L'\r' && pStr[i + 1] == L'\n') { + pStr[nLen++] = ' '; + ++i; + continue; + } + } + pStr[nLen++] = pStr[i]; + } + pStr[nLen] = 0; + } + return nLen; +} /************************************************************************ * WTextFieldPeer native methods --- old/jdk/src/java.desktop/share/classes/java/awt/TextField.java 2015-09-18 17:00:24.801478999 +0530 +++ new/jdk/src/java.desktop/share/classes/java/awt/TextField.java 2015-09-18 17:00:24.477317000 +0530 @@ -36,6 +36,8 @@ /** * A TextField object is a text component * that allows for the editing of a single line of text. + * If the input text contains new line character, + * it will be replaced by a space character. *

* For example, the following image depicts a frame with four * text fields of varying widths. Two of these text fields --- /dev/null 2015-09-18 10:10:44.971223000 +0530 +++ new/jdk/test/java/awt/TextField/EOLTest/EOLTest.java 2015-09-18 17:00:25.069613000 +0530 @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, 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 8055197 + @summary TextField should replace new line with space character + @run main EOLTest + */ +import java.awt.Frame; +import java.awt.TextField; + +public class EOLTest { + + private Frame mainFrame; + private TextField textField; + private String testStrEOL; + private boolean isTestFail; + private int testFailCount; + StringBuilder testFailMessage; + private String expectedString = "Row1 Row2"; + + public EOLTest() { + mainFrame = new Frame(); + mainFrame.setSize(200, 200); + mainFrame.setVisible(true); + testFailMessage = new StringBuilder(); + testStrEOL = "Row1" + System.getProperty("line.separator") + "Row2"; + } + + private void testConstructor1() { + textField = new TextField(testStrEOL); + textField.setSize(200, 100); + mainFrame.add(textField); + checkTest(); + mainFrame.remove(textField); + textField = null; + } + + private void testConstructor2() { + textField = new TextField(30); + textField.setSize(200, 100); + mainFrame.add(textField); + textField.setText(testStrEOL); + checkTest(); + mainFrame.remove(textField); + textField = null; + } + + private void testConstructor3() { + textField = new TextField(testStrEOL, 30); + textField.setSize(200, 100); + mainFrame.add(textField); + checkTest(); + mainFrame.remove(textField); + textField = null; + } + + private void testSetText() { + textField = new TextField(); + textField.setSize(200, 100); + textField.setText(testStrEOL); + mainFrame.add(textField); + checkTest(); + mainFrame.remove(textField); + textField = null; + } + + private void checkTest() { + if (!textField.getText().equals(expectedString)) { + testFailMessage.append("TestFail line : "); + testFailMessage.append(Thread.currentThread().getStackTrace()[2]. + getLineNumber()); + testFailMessage.append(" TextArea string : \""); + testFailMessage.append(textField.getText()); + testFailMessage.append("\" does not match expected string : \""); + testFailMessage.append(expectedString).append("\""); + testFailMessage.append(System.getProperty("line.separator")); + testFailCount++; + isTestFail = true; + } + } + + private void checkFailures() { + if (isTestFail) { + testFailMessage.insert(0, "Test Fail count : " + testFailCount + + System.getProperty("line.separator")); + dispose(); + throw new RuntimeException(testFailMessage.toString()); + } + } + + private void dispose() { + if (mainFrame != null) { + mainFrame.dispose(); + } + } + + public static void main(String[] args) { + EOLTest testEOL = new EOLTest(); + testEOL.testConstructor1(); + testEOL.testConstructor2(); + testEOL.testConstructor3(); + testEOL.testSetText(); + testEOL.checkFailures(); + testEOL.dispose(); + } +}