Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
fc6f83bc
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fc6f83bc
编写于
4月 03, 2014
作者:
P
pchelko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8038999: In Java 8 java.awt.datatransfer.DataFlavor.equals is no longer symmetric
Reviewed-by: anthony, serb
上级
fbdbc9ed
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
150 addition
and
48 deletion
+150
-48
src/share/classes/java/awt/datatransfer/DataFlavor.java
src/share/classes/java/awt/datatransfer/DataFlavor.java
+62
-48
test/java/awt/datatransfer/DataFlavor/EqualsHashCodeSymmetryTest/EqualsHashCodeSymmetryTest.java
...qualsHashCodeSymmetryTest/EqualsHashCodeSymmetryTest.java
+88
-0
未找到文件。
src/share/classes/java/awt/datatransfer/DataFlavor.java
浏览文件 @
fc6f83bc
...
...
@@ -25,13 +25,28 @@
package
java.awt.datatransfer
;
import
java.io.*
;
import
java.nio.*
;
import
java.util.*
;
import
sun.awt.datatransfer.DataTransferer
;
import
sun.reflect.misc.ReflectUtil
;
import
java.io.ByteArrayInputStream
;
import
java.io.CharArrayReader
;
import
java.io.Externalizable
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.ObjectInput
;
import
java.io.ObjectOutput
;
import
java.io.OptionalDataException
;
import
java.io.Reader
;
import
java.io.StringReader
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.ByteBuffer
;
import
java.nio.CharBuffer
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Objects
;
import
static
sun
.
security
.
util
.
SecurityConstants
.
GET_CLASSLOADER_PERMISSION
;
/**
...
...
@@ -501,7 +516,7 @@ public class DataFlavor implements Externalizable, Cloneable {
* @throws ClassNotFoundException
* @throws NullPointerException if <code>mimeType</code> is null
*
* @see tryToLoadClass
* @see
#
tryToLoadClass
*/
private
void
initialize
(
String
mimeType
,
String
humanPresentableName
,
ClassLoader
classLoader
)
throws
MimeTypeParseException
,
ClassNotFoundException
{
if
(
mimeType
==
null
)
{
...
...
@@ -990,14 +1005,8 @@ public class DataFlavor implements Externalizable, Cloneable {
return
true
;
}
if
(
representationClass
==
null
)
{
if
(
that
.
getRepresentationClass
()
!=
null
)
{
return
false
;
}
}
else
{
if
(!
representationClass
.
equals
(
that
.
getRepresentationClass
()))
{
return
false
;
}
if
(!
Objects
.
equals
(
this
.
getRepresentationClass
(),
that
.
getRepresentationClass
()))
{
return
false
;
}
if
(
mimeType
==
null
)
{
...
...
@@ -1010,34 +1019,22 @@ public class DataFlavor implements Externalizable, Cloneable {
}
if
(
"text"
.
equals
(
getPrimaryType
()))
{
if
(
DataTransferer
.
doesSubtypeSupportCharset
(
this
)
&&
representationClass
!=
null
&&
!(
isRepresentationClassReader
()
||
String
.
class
.
equals
(
representationClass
)
||
isRepresentationClassCharBuffer
()
||
char
[].
class
.
equals
(
representationClass
)))
{
if
(
DataTransferer
.
doesSubtypeSupportCharset
(
this
)
&&
representationClass
!=
null
&&
!
isStandardTextRepresentationClass
())
{
String
thisCharset
=
DataTransferer
.
canonicalName
(
getParameter
(
"charset"
));
DataTransferer
.
canonicalName
(
this
.
getParameter
(
"charset"
));
String
thatCharset
=
DataTransferer
.
canonicalName
(
that
.
getParameter
(
"charset"
));
if
(
thisCharset
==
null
)
{
if
(
thatCharset
!=
null
)
{
return
false
;
}
}
else
{
if
(!
thisCharset
.
equals
(
thatCharset
))
{
return
false
;
}
DataTransferer
.
canonicalName
(
that
.
getParameter
(
"charset"
));
if
(!
Objects
.
equals
(
thisCharset
,
thatCharset
))
{
return
false
;
}
}
if
(
"html"
.
equals
(
getSubType
())
&&
this
.
getParameter
(
"document"
)
!=
null
)
{
if
(!
this
.
getParameter
(
"document"
).
equals
(
that
.
getParameter
(
"document"
)))
{
if
(
"html"
.
equals
(
getSubType
()))
{
String
thisDocument
=
this
.
getParameter
(
"document"
);
String
thatDocument
=
that
.
getParameter
(
"document"
);
if
(!
Objects
.
equals
(
thisDocument
,
thatDocument
))
{
return
false
;
}
}
...
...
@@ -1094,18 +1091,21 @@ public class DataFlavor implements Externalizable, Cloneable {
// MimeType.match which reports a match if one or both of the
// subTypes is '*', regardless of the other subType.
if
(
"text"
.
equals
(
primaryType
)
&&
DataTransferer
.
doesSubtypeSupportCharset
(
this
)
&&
representationClass
!=
null
&&
!(
isRepresentationClassReader
()
||
String
.
class
.
equals
(
representationClass
)
||
isRepresentationClassCharBuffer
()
||
char
[].
class
.
equals
(
representationClass
)))
{
String
charset
=
DataTransferer
.
canonicalName
(
getParameter
(
"charset"
));
if
(
charset
!=
null
)
{
total
+=
charset
.
hashCode
();
if
(
"text"
.
equals
(
primaryType
))
{
if
(
DataTransferer
.
doesSubtypeSupportCharset
(
this
)
&&
representationClass
!=
null
&&
!
isStandardTextRepresentationClass
())
{
String
charset
=
DataTransferer
.
canonicalName
(
getParameter
(
"charset"
));
if
(
charset
!=
null
)
{
total
+=
charset
.
hashCode
();
}
}
if
(
"html"
.
equals
(
getSubType
()))
{
String
document
=
this
.
getParameter
(
"document"
);
if
(
document
!=
null
)
{
total
+=
document
.
hashCode
();
}
}
}
}
...
...
@@ -1181,6 +1181,20 @@ public class DataFlavor implements Externalizable, Cloneable {
return
mimeType
.
match
(
mtype
);
}
/**
* Checks if the representation class is one of the standard text
* representation classes.
*
* @return true if the representation class is one of the standard text
* representation classes, otherwise false
*/
private
boolean
isStandardTextRepresentationClass
()
{
return
isRepresentationClassReader
()
||
String
.
class
.
equals
(
representationClass
)
||
isRepresentationClassCharBuffer
()
||
char
[].
class
.
equals
(
representationClass
);
}
/**
* Does the <code>DataFlavor</code> represent a serialized object?
*/
...
...
test/java/awt/datatransfer/DataFlavor/EqualsHashCodeSymmetryTest/EqualsHashCodeSymmetryTest.java
0 → 100644
浏览文件 @
fc6f83bc
/*
* 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.awt.datatransfer.DataFlavor
;
/**
* @test
* @bug 8038999
* @summary DataFlavor.equals is not symmetric
* @author Petr Pchelko <petr.pchelko@oracle.com>
*/
public
class
EqualsHashCodeSymmetryTest
{
private
static
final
DataFlavor
[]
dataFlavors
=
{
DataFlavor
.
stringFlavor
,
DataFlavor
.
imageFlavor
,
DataFlavor
.
javaFileListFlavor
,
DataFlavor
.
allHtmlFlavor
,
DataFlavor
.
selectionHtmlFlavor
,
DataFlavor
.
fragmentHtmlFlavor
,
createFlavor
(
"text/html; class=java.lang.String"
),
new
DataFlavor
(
String
.
class
,
"My test flavor number 1"
),
new
DataFlavor
(
String
.
class
,
"My test flavor number 2"
),
new
DataFlavor
(
StringBuilder
.
class
,
"My test flavor number 1"
)
};
public
static
void
main
(
String
[]
args
)
{
testEqualsSymmetry
();
testEqualsHashCodeConsistency
();
testSimpleCollision
();
}
private
static
void
testEqualsSymmetry
()
{
for
(
DataFlavor
flavor1
:
dataFlavors
)
{
for
(
DataFlavor
flavor2
:
dataFlavors
)
{
if
(
flavor1
.
equals
(
flavor2
)
!=
flavor2
.
equals
(
flavor1
))
{
throw
new
RuntimeException
(
String
.
format
(
"Equals is not symmetric for %s and %s"
,
flavor1
,
flavor2
));
}
}
}
}
private
static
void
testEqualsHashCodeConsistency
()
{
for
(
DataFlavor
flavor1
:
dataFlavors
)
{
for
(
DataFlavor
flavor2
:
dataFlavors
)
{
if
((
flavor1
.
equals
(
flavor2
)
&&
flavor1
.
hashCode
()
!=
flavor2
.
hashCode
()))
{
throw
new
RuntimeException
(
String
.
format
(
"Equals and hash code not consistent for %s and %s"
,
flavor1
,
flavor2
));
}
}
}
}
private
static
void
testSimpleCollision
()
{
if
(
createFlavor
(
"text/html; class=java.lang.String"
).
hashCode
()
==
DataFlavor
.
allHtmlFlavor
.
hashCode
())
{
throw
new
RuntimeException
(
"HashCode collision because the document parameter is not used"
);
}
}
private
static
DataFlavor
createFlavor
(
String
mime
)
{
try
{
return
new
DataFlavor
(
mime
);
}
catch
(
ClassNotFoundException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录