Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
1d47fc6e
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1d47fc6e
编写于
12月 17, 2013
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consistent non-declaration of serialVersionUID
Issue: SPR-11242
上级
994efe45
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
73 deletion
+37
-73
spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java
...ava/org/springframework/core/SerializableTypeWrapper.java
+31
-66
spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java
...java/org/springframework/core/convert/TypeDescriptor.java
+6
-7
未找到文件。
spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java
浏览文件 @
1d47fc6e
...
@@ -22,6 +22,7 @@ import java.io.Serializable;
...
@@ -22,6 +22,7 @@ import java.io.Serializable;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.GenericArrayType
;
import
java.lang.reflect.GenericArrayType
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Proxy
;
import
java.lang.reflect.Proxy
;
...
@@ -53,8 +54,8 @@ import org.springframework.util.ReflectionUtils;
...
@@ -53,8 +54,8 @@ import org.springframework.util.ReflectionUtils;
*/
*/
abstract
class
SerializableTypeWrapper
{
abstract
class
SerializableTypeWrapper
{
private
static
final
Class
<?>[]
SUPPORTED_SERIAL
AZABLE_TYPES
=
{
GenericArrayType
.
class
,
private
static
final
Class
<?>[]
SUPPORTED_SERIAL
IZABLE_TYPES
=
{
ParameterizedType
.
class
,
TypeVariable
.
class
,
WildcardType
.
class
};
GenericArrayType
.
class
,
ParameterizedType
.
class
,
TypeVariable
.
class
,
WildcardType
.
class
};
/**
/**
...
@@ -76,12 +77,9 @@ abstract class SerializableTypeWrapper {
...
@@ -76,12 +77,9 @@ abstract class SerializableTypeWrapper {
/**
/**
* Return a {@link Serializable} variant of {@link Class#getGenericSuperclass()}.
* Return a {@link Serializable} variant of {@link Class#getGenericSuperclass()}.
*/
*/
@SuppressWarnings
(
"serial"
)
public
static
Type
forGenericSuperclass
(
final
Class
<?>
type
)
{
public
static
Type
forGenericSuperclass
(
final
Class
<?>
type
)
{
return
forTypeProvider
(
new
DefaultTypeProvider
()
{
return
forTypeProvider
(
new
DefaultTypeProvider
()
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
@Override
public
Type
getType
()
{
public
Type
getType
()
{
return
type
.
getGenericSuperclass
();
return
type
.
getGenericSuperclass
();
...
@@ -92,15 +90,12 @@ abstract class SerializableTypeWrapper {
...
@@ -92,15 +90,12 @@ abstract class SerializableTypeWrapper {
/**
/**
* Return a {@link Serializable} variant of {@link Class#getGenericInterfaces()}.
* Return a {@link Serializable} variant of {@link Class#getGenericInterfaces()}.
*/
*/
@SuppressWarnings
(
"serial"
)
public
static
Type
[]
forGenericInterfaces
(
final
Class
<?>
type
)
{
public
static
Type
[]
forGenericInterfaces
(
final
Class
<?>
type
)
{
Type
[]
result
=
new
Type
[
type
.
getGenericInterfaces
().
length
];
Type
[]
result
=
new
Type
[
type
.
getGenericInterfaces
().
length
];
for
(
int
i
=
0
;
i
<
result
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
result
.
length
;
i
++)
{
final
int
index
=
i
;
final
int
index
=
i
;
result
[
i
]
=
forTypeProvider
(
new
DefaultTypeProvider
()
{
result
[
i
]
=
forTypeProvider
(
new
DefaultTypeProvider
()
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
@Override
public
Type
getType
()
{
public
Type
getType
()
{
return
type
.
getGenericInterfaces
()[
index
];
return
type
.
getGenericInterfaces
()[
index
];
...
@@ -113,15 +108,12 @@ abstract class SerializableTypeWrapper {
...
@@ -113,15 +108,12 @@ abstract class SerializableTypeWrapper {
/**
/**
* Return a {@link Serializable} variant of {@link Class#getTypeParameters()}.
* Return a {@link Serializable} variant of {@link Class#getTypeParameters()}.
*/
*/
@SuppressWarnings
(
"serial"
)
public
static
Type
[]
forTypeParameters
(
final
Class
<?>
type
)
{
public
static
Type
[]
forTypeParameters
(
final
Class
<?>
type
)
{
Type
[]
result
=
new
Type
[
type
.
getTypeParameters
().
length
];
Type
[]
result
=
new
Type
[
type
.
getTypeParameters
().
length
];
for
(
int
i
=
0
;
i
<
result
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
result
.
length
;
i
++)
{
final
int
index
=
i
;
final
int
index
=
i
;
result
[
i
]
=
forTypeProvider
(
new
DefaultTypeProvider
()
{
result
[
i
]
=
forTypeProvider
(
new
DefaultTypeProvider
()
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
@Override
public
Type
getType
()
{
public
Type
getType
()
{
return
type
.
getTypeParameters
()[
index
];
return
type
.
getTypeParameters
()[
index
];
...
@@ -131,7 +123,6 @@ abstract class SerializableTypeWrapper {
...
@@ -131,7 +123,6 @@ abstract class SerializableTypeWrapper {
return
result
;
return
result
;
}
}
/**
/**
* Return a {@link Serializable} {@link Type} backed by a {@link TypeProvider} .
* Return a {@link Serializable} {@link Type} backed by a {@link TypeProvider} .
*/
*/
...
@@ -140,7 +131,7 @@ abstract class SerializableTypeWrapper {
...
@@ -140,7 +131,7 @@ abstract class SerializableTypeWrapper {
if
(
provider
.
getType
()
instanceof
Serializable
||
provider
.
getType
()
==
null
)
{
if
(
provider
.
getType
()
instanceof
Serializable
||
provider
.
getType
()
==
null
)
{
return
provider
.
getType
();
return
provider
.
getType
();
}
}
for
(
Class
<?>
type
:
SUPPORTED_SERIAL
A
ZABLE_TYPES
)
{
for
(
Class
<?>
type
:
SUPPORTED_SERIAL
I
ZABLE_TYPES
)
{
if
(
type
.
isAssignableFrom
(
provider
.
getType
().
getClass
()))
{
if
(
type
.
isAssignableFrom
(
provider
.
getType
().
getClass
()))
{
ClassLoader
classLoader
=
provider
.
getClass
().
getClassLoader
();
ClassLoader
classLoader
=
provider
.
getClass
().
getClassLoader
();
Class
<?>[]
interfaces
=
new
Class
<?>[]
{
type
,
Serializable
.
class
};
Class
<?>[]
interfaces
=
new
Class
<?>[]
{
type
,
Serializable
.
class
};
...
@@ -148,8 +139,7 @@ abstract class SerializableTypeWrapper {
...
@@ -148,8 +139,7 @@ abstract class SerializableTypeWrapper {
return
(
Type
)
Proxy
.
newProxyInstance
(
classLoader
,
interfaces
,
handler
);
return
(
Type
)
Proxy
.
newProxyInstance
(
classLoader
,
interfaces
,
handler
);
}
}
}
}
throw
new
IllegalArgumentException
(
"Unsupported Type class "
throw
new
IllegalArgumentException
(
"Unsupported Type class "
+
provider
.
getType
().
getClass
().
getName
());
+
provider
.
getType
().
getClass
().
getName
());
}
}
...
@@ -167,17 +157,14 @@ abstract class SerializableTypeWrapper {
...
@@ -167,17 +157,14 @@ abstract class SerializableTypeWrapper {
* Return the source of the type or {@code null}.
* Return the source of the type or {@code null}.
*/
*/
Object
getSource
();
Object
getSource
();
}
}
/**
/**
* Default implementation of {@link TypeProvider} with a {@code null} source.
* Default implementation of {@link TypeProvider} with a {@code null} source.
*/
*/
static
abstract
class
DefaultTypeProvider
implements
TypeProvider
{
@SuppressWarnings
(
"serial"
)
private
static
abstract
class
DefaultTypeProvider
implements
TypeProvider
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
@Override
public
Object
getSource
()
{
public
Object
getSource
()
{
...
@@ -186,25 +173,21 @@ abstract class SerializableTypeWrapper {
...
@@ -186,25 +173,21 @@ abstract class SerializableTypeWrapper {
}
}
/**
/**
* {@link Serializable} {@link InvocationHandler} used by the Proxied {@link Type}.
* {@link Serializable} {@link InvocationHandler} used by the Proxied {@link Type}.
* Provides serialization support and enhances any methods that return {@code Type}
* Provides serialization support and enhances any methods that return {@code Type}
* or {@code Type[]}.
* or {@code Type[]}.
*/
*/
private
static
class
TypeProxyInvocationHandler
implements
InvocationHandler
,
@SuppressWarnings
(
"serial"
)
Serializable
{
private
static
class
TypeProxyInvocationHandler
implements
InvocationHandler
,
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
final
TypeProvider
provider
;
private
final
TypeProvider
provider
;
public
TypeProxyInvocationHandler
(
TypeProvider
provider
)
{
public
TypeProxyInvocationHandler
(
TypeProvider
provider
)
{
this
.
provider
=
provider
;
this
.
provider
=
provider
;
}
}
@Override
@Override
public
Object
invoke
(
Object
proxy
,
Method
method
,
Object
[]
args
)
throws
Throwable
{
public
Object
invoke
(
Object
proxy
,
Method
method
,
Object
[]
args
)
throws
Throwable
{
if
(
Type
.
class
.
equals
(
method
.
getReturnType
())
&&
args
==
null
)
{
if
(
Type
.
class
.
equals
(
method
.
getReturnType
())
&&
args
==
null
)
{
...
@@ -217,35 +200,34 @@ abstract class SerializableTypeWrapper {
...
@@ -217,35 +200,34 @@ abstract class SerializableTypeWrapper {
}
}
return
result
;
return
result
;
}
}
return
method
.
invoke
(
this
.
provider
.
getType
(),
args
);
try
{
return
method
.
invoke
(
this
.
provider
.
getType
(),
args
);
}
catch
(
InvocationTargetException
ex
)
{
throw
ex
.
getTargetException
();
}
}
}
}
}
/**
/**
* {@link TypeProvider} for {@link Type}s obtained from a {@link Field}.
* {@link TypeProvider} for {@link Type}s obtained from a {@link Field}.
*/
*/
@SuppressWarnings
(
"serial"
)
static
class
FieldTypeProvider
implements
TypeProvider
{
static
class
FieldTypeProvider
implements
TypeProvider
{
private
static
final
long
serialVersionUID
=
1L
;
private
final
String
fieldName
;
private
final
String
fieldName
;
private
final
Class
<?>
declaringClass
;
private
final
Class
<?>
declaringClass
;
private
transient
Field
field
;
private
transient
Field
field
;
public
FieldTypeProvider
(
Field
field
)
{
public
FieldTypeProvider
(
Field
field
)
{
this
.
fieldName
=
field
.
getName
();
this
.
fieldName
=
field
.
getName
();
this
.
declaringClass
=
field
.
getDeclaringClass
();
this
.
declaringClass
=
field
.
getDeclaringClass
();
this
.
field
=
field
;
this
.
field
=
field
;
}
}
@Override
@Override
public
Type
getType
()
{
public
Type
getType
()
{
return
this
.
field
.
getGenericType
();
return
this
.
field
.
getGenericType
();
...
@@ -256,29 +238,24 @@ abstract class SerializableTypeWrapper {
...
@@ -256,29 +238,24 @@ abstract class SerializableTypeWrapper {
return
this
.
field
;
return
this
.
field
;
}
}
private
void
readObject
(
ObjectInputStream
inputStream
)
throws
IOException
,
private
void
readObject
(
ObjectInputStream
inputStream
)
throws
IOException
,
ClassNotFoundException
{
ClassNotFoundException
{
inputStream
.
defaultReadObject
();
inputStream
.
defaultReadObject
();
try
{
try
{
this
.
field
=
this
.
declaringClass
.
getDeclaredField
(
this
.
fieldName
);
this
.
field
=
this
.
declaringClass
.
getDeclaredField
(
this
.
fieldName
);
}
}
catch
(
Throwable
ex
)
{
catch
(
Throwable
ex
)
{
throw
new
IllegalStateException
(
throw
new
IllegalStateException
(
"Could not find original class structure"
,
ex
);
"Could not find original class structure"
,
ex
);
}
}
}
}
}
}
/**
/**
* {@link TypeProvider} for {@link Type}s obtained from a {@link MethodParameter}.
* {@link TypeProvider} for {@link Type}s obtained from a {@link MethodParameter}.
*/
*/
@SuppressWarnings
(
"serial"
)
static
class
MethodParameterTypeProvider
implements
TypeProvider
{
static
class
MethodParameterTypeProvider
implements
TypeProvider
{
private
static
final
long
serialVersionUID
=
1L
;
private
final
String
methodName
;
private
final
String
methodName
;
private
final
Class
<?>[]
parameterTypes
;
private
final
Class
<?>[]
parameterTypes
;
...
@@ -289,7 +266,6 @@ abstract class SerializableTypeWrapper {
...
@@ -289,7 +266,6 @@ abstract class SerializableTypeWrapper {
private
transient
MethodParameter
methodParameter
;
private
transient
MethodParameter
methodParameter
;
public
MethodParameterTypeProvider
(
MethodParameter
methodParameter
)
{
public
MethodParameterTypeProvider
(
MethodParameter
methodParameter
)
{
if
(
methodParameter
.
getMethod
()
!=
null
)
{
if
(
methodParameter
.
getMethod
()
!=
null
)
{
this
.
methodName
=
methodParameter
.
getMethod
().
getName
();
this
.
methodName
=
methodParameter
.
getMethod
().
getName
();
...
@@ -315,38 +291,31 @@ abstract class SerializableTypeWrapper {
...
@@ -315,38 +291,31 @@ abstract class SerializableTypeWrapper {
return
this
.
methodParameter
;
return
this
.
methodParameter
;
}
}
private
void
readObject
(
ObjectInputStream
inputStream
)
throws
IOException
,
private
void
readObject
(
ObjectInputStream
inputStream
)
throws
IOException
,
ClassNotFoundException
{
ClassNotFoundException
{
inputStream
.
defaultReadObject
();
inputStream
.
defaultReadObject
();
try
{
try
{
if
(
this
.
methodName
!=
null
)
{
if
(
this
.
methodName
!=
null
)
{
this
.
methodParameter
=
new
MethodParameter
(
this
.
methodParameter
=
new
MethodParameter
(
this
.
declaringClass
.
getDeclaredMethod
(
this
.
methodName
,
this
.
declaringClass
.
getDeclaredMethod
(
this
.
methodName
,
this
.
parameterTypes
),
this
.
parameterIndex
);
this
.
parameterTypes
),
this
.
parameterIndex
);
}
}
else
{
else
{
this
.
methodParameter
=
new
MethodParameter
(
this
.
methodParameter
=
new
MethodParameter
(
this
.
declaringClass
.
getDeclaredConstructor
(
this
.
parameterTypes
),
this
.
declaringClass
.
getDeclaredConstructor
(
this
.
parameterTypes
),
this
.
parameterIndex
);
this
.
parameterIndex
);
}
}
}
}
catch
(
Throwable
ex
)
{
catch
(
Throwable
ex
)
{
throw
new
IllegalStateException
(
throw
new
IllegalStateException
(
"Could not find original class structure"
,
ex
);
"Could not find original class structure"
,
ex
);
}
}
}
}
}
}
/**
/**
* {@link TypeProvider} for {@link Type}s obtained by invoking a no-arg method.
* {@link TypeProvider} for {@link Type}s obtained by invoking a no-arg method.
*/
*/
@SuppressWarnings
(
"serial"
)
static
class
MethodInvokeTypeProvider
implements
TypeProvider
{
static
class
MethodInvokeTypeProvider
implements
TypeProvider
{
private
static
final
long
serialVersionUID
=
1L
;
private
final
TypeProvider
provider
;
private
final
TypeProvider
provider
;
private
final
String
methodName
;
private
final
String
methodName
;
...
@@ -355,7 +324,6 @@ abstract class SerializableTypeWrapper {
...
@@ -355,7 +324,6 @@ abstract class SerializableTypeWrapper {
private
transient
Object
result
;
private
transient
Object
result
;
public
MethodInvokeTypeProvider
(
TypeProvider
provider
,
Method
method
,
int
index
)
{
public
MethodInvokeTypeProvider
(
TypeProvider
provider
,
Method
method
,
int
index
)
{
this
.
provider
=
provider
;
this
.
provider
=
provider
;
this
.
methodName
=
method
.
getName
();
this
.
methodName
=
method
.
getName
();
...
@@ -363,7 +331,6 @@ abstract class SerializableTypeWrapper {
...
@@ -363,7 +331,6 @@ abstract class SerializableTypeWrapper {
this
.
result
=
ReflectionUtils
.
invokeMethod
(
method
,
provider
.
getType
());
this
.
result
=
ReflectionUtils
.
invokeMethod
(
method
,
provider
.
getType
());
}
}
@Override
@Override
public
Type
getType
()
{
public
Type
getType
()
{
if
(
this
.
result
instanceof
Type
||
this
.
result
==
null
)
{
if
(
this
.
result
instanceof
Type
||
this
.
result
==
null
)
{
...
@@ -377,13 +344,11 @@ abstract class SerializableTypeWrapper {
...
@@ -377,13 +344,11 @@ abstract class SerializableTypeWrapper {
return
null
;
return
null
;
}
}
private
void
readObject
(
ObjectInputStream
inputStream
)
throws
IOException
,
private
void
readObject
(
ObjectInputStream
inputStream
)
throws
IOException
,
ClassNotFoundException
{
ClassNotFoundException
{
inputStream
.
defaultReadObject
();
inputStream
.
defaultReadObject
();
Method
method
=
ReflectionUtils
.
findMethod
(
Method
method
=
ReflectionUtils
.
findMethod
(
this
.
provider
.
getType
().
getClass
(),
this
.
methodName
);
this
.
provider
.
getType
().
getClass
(),
this
.
methodName
);
this
.
result
=
ReflectionUtils
.
invokeMethod
(
method
,
this
.
provider
.
getType
());
this
.
result
=
ReflectionUtils
.
invokeMethod
(
method
,
this
.
provider
.
getType
());
}
}
}
}
}
}
spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java
浏览文件 @
1d47fc6e
...
@@ -40,19 +40,18 @@ import org.springframework.util.ObjectUtils;
...
@@ -40,19 +40,18 @@ import org.springframework.util.ObjectUtils;
* @author Sam Brannen
* @author Sam Brannen
* @since 3.0
* @since 3.0
*/
*/
@SuppressWarnings
(
"serial"
)
public
class
TypeDescriptor
implements
Serializable
{
public
class
TypeDescriptor
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
static
final
Annotation
[]
EMPTY_ANNOTATION_ARRAY
=
new
Annotation
[
0
];
static
final
Annotation
[]
EMPTY_ANNOTATION_ARRAY
=
new
Annotation
[
0
];
private
static
final
Map
<
Class
<?>,
TypeDescriptor
>
commonTypesCache
=
new
HashMap
<
Class
<?>,
TypeDescriptor
>();
private
static
final
Map
<
Class
<?>,
TypeDescriptor
>
commonTypesCache
=
new
HashMap
<
Class
<?>,
TypeDescriptor
>();
private
static
final
Class
<?>[]
CACHED_COMMON_TYPES
=
{
Boolean
.
class
,
byte
.
class
,
private
static
final
Class
<?>[]
CACHED_COMMON_TYPES
=
{
Boolean
.
class
,
byte
.
class
,
Byte
.
class
,
char
.
class
,
Character
.
class
,
short
.
class
,
Short
.
class
,
int
.
class
,
Byte
.
class
,
char
.
class
,
Character
.
class
,
short
.
class
,
Short
.
class
,
int
.
class
,
Integer
.
class
,
long
.
class
,
Long
.
class
,
float
.
class
,
Float
.
class
,
double
.
class
,
Integer
.
class
,
long
.
class
,
Long
.
class
,
float
.
class
,
Float
.
class
,
double
.
class
,
Double
.
class
,
String
.
class
};
Double
.
class
,
String
.
class
};
static
{
static
{
for
(
Class
<?>
preCachedClass
:
CACHED_COMMON_TYPES
)
{
for
(
Class
<?>
preCachedClass
:
CACHED_COMMON_TYPES
)
{
commonTypesCache
.
put
(
preCachedClass
,
valueOf
(
preCachedClass
));
commonTypesCache
.
put
(
preCachedClass
,
valueOf
(
preCachedClass
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录