JDK-8087545 : Line separator is broken in the clipboard of WebView
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u45
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2015-05-22
  • Updated: 2017-04-14
  • Resolved: 2017-04-14
Related Reports
Duplicate :  
Description
In WebView, If you use the clipboard perform inter-process communication, it is broken line separator of multi-line text.

Input: 123 [LF] 456 [LF] 789

In the case of the same process: 123 [CR] [LF] 456 [CR] [LF] 789
In the case of different processes: 123 [CR] [CR] [LF] 456 [CR]  [CR] [LF] 789	


This problem makes it difficult to interoperability of the desktop application.
	
Start two following test applications at the same time, you can see the problem by using the clipboard.

test code: 

WebViewClipboardTest .java
-----------------------------------
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.input.Clipboard;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.util.Duration;


public class WebViewClipboardTest extends Application{
	
	@Override
	public void start(Stage stage) throws Exception {
		VBox pane = new VBox();
		WebView browser = new WebView();
		TextArea textArea = new TextArea();
		
		String html = "<html><body><h1>TEST-1: text</h1>123<br>456<br>789<h1>TEST-2: pre</h1><pre>123\n456\n789</pre><h1>TEST-3: textarea</h1><textarea rows=5>123\n456\n789</textarea></body></html>";
		browser.getEngine().loadContent(html);
		pane.getChildren().addAll(browser, new Label("Clipboard:"), textArea);
		Scene scene = new Scene(pane);
		stage.setScene(scene);
		stage.show();
		
		Timeline monitor = new Timeline(new KeyFrame(Duration.millis(200), new EventHandler<ActionEvent>() {
		    @Override
		    public void handle(ActionEvent event) {
		    	Clipboard clipboard = Clipboard.getSystemClipboard();
		    	if(clipboard.hasString()){
		    		final String text = clipboard.getString()
    					.replace("\r", "[CR]")
		    			.replace("\n", "[LF]");
			    	textArea.setText(text);
		    		//clipboard.clear();
		    	}
		    }
		}));
		monitor.setCycleCount(Timeline.INDEFINITE);
		monitor.play();
		
		stage.show();
	}

	public static void main(String[] args) {
		WebViewClipboardTest.launch(args);
	}
}
Comments
Even more to the point, the patch in the above webrev is wrong. By using replace rather than replaceAll you have effectively turned the statement into a noop (the effect is the same as if you had deleted the call to replace). So while it accidentally 'fixes' the bug, you have changed the behavior such that the replacement from "\n" to "\r\n" will never happen. It is a different argument (see the discussion in JDK-8172561) as to whether that replacement ever *should* happen, but this is not a change we would make in an update release for fear of regression. Anyway, the bug will be fixed by applying the patch from JDK-8172561 to 8u-dev.
14-04-2017

JDK-8172561 is already tracking this bug. It was fixed in JDK 9 and approved to backport to JDK 8u. Rather than fixing this issue in JDK 8u with a new bug ID, we need to closed this bug as a duplicate of that one for proper bookkeeping.
14-04-2017

Webrev : http://cr.openjdk.java.net/~asrivastava/dipak/8087545/webrev.00/ I have tested the fix on Win64 and Junit test case run was fine. This issue is not reproducible in JDK 9 and this change is already there in JDK 9.
14-04-2017