-
Notifications
You must be signed in to change notification settings - Fork 563
8373452: DataFormat threading and API issues #2006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
8373452: DataFormat threading and API issues #2006
Conversation
|
👋 Welcome back angorya! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
@andy-goryachev-oracle |
|
@andy-goryachev-oracle has indicated that a compatibility and specification (CSR) request is needed for this pull request. @andy-goryachev-oracle please create a CSR request for issue JDK-8373452 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
Webrevs
|
kevinrushforth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the constructor is an incompatible change.
| @Deprecated(since = "27") | ||
| private DataFormat(@NamedArg("ids") String... ids) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an incompatible change. You will need to go through the usual process for such changes where it is deprecated for removal in one release and removed in a subsequent release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also print a warning to stderr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved offline: no, since stderr will likely be noticed by the user rather than the developer.
Summary
This PR makes deprecates the
DataFormatconstructor (for removal):and replaces it with
Problem
There seems to be several issues with DataFormat API and implementation discovered during a Clipboard-related code review:
static DataFormat::lookupMimeType(String)is not thread safe: while iterating over previously registered entries in theDATA_FORMAT_LISTanother thread might create a new instance (DataFormat L227)public DataFormat(String...)constructor might throw anIllegalArgumentExceptionif one of the given mime types is already assigned to anotherDataFormat. The origin of this requirement is unclear, but one possible issue I can see is if the application has two libraries that both attempt to create aDataFormatfor let's say"text/css". Then, depending on the timing or the exact code path, an exception will be thrown for which the library(-ies) might not be prepared. The constructor is also not thread safe.To avoid a situation mentioned in bullet 2, a developer would is typically call
lookupMimeType()to obtain an already registered instance, followed by a constructor call if such an instance has not been found. An example of such code can be seen in webkit/UIClientImpl:299 - but even then, despite that two-step process being synchronized, the code might still fail if some other library or the application attempts to create a new instance of DataFormat, since the constructor itself is not synchronized.DataFormat(new String[] { null })is allowed but makes no sense!Why do we need to have the registry of previously created instances? Unclear. My theory is that the DataFormat allows to have multiple mime-types (ids) - example being
DataFormat.FILES = new DataFormat("application/x-java-file-list", "java.file-list");- and the registry was added to prevent creation of aDataFormatwith just one id for some reason.What should be done?
DataFormat::of(String ...)which is properly synchronized. This method will be called by the constructor to retain the backward compatibility.DataFormat::lookupMimeType(String), or keep it but have it properly synchronizedDangers
DataFormat.class.Alternatives
We could possibly prevent the application code creating
DataFormats with multiple ids bypublic DataFormat(String)constructorDataFormats with multiple ids/reviewers 2
/csr
Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/2006/head:pull/2006$ git checkout pull/2006Update a local copy of the PR:
$ git checkout pull/2006$ git pull https://git.openjdk.org/jfx.git pull/2006/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 2006View PR using the GUI difftool:
$ git pr show -t 2006Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/2006.diff
Using Webrev
Link to Webrev Comment