Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
普通程序员一名
spring-framework
提交
1a955692
S
spring-framework
项目概览
普通程序员一名
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
1a955692
编写于
3月 25, 2021
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
missingAfterConversion flag for missing request values
Closes gh-26679
上级
2dc203ff
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
206 addition
and
32 deletion
+206
-32
spring-web/src/main/java/org/springframework/web/bind/MissingMatrixVariableException.java
...ingframework/web/bind/MissingMatrixVariableException.java
+19
-5
spring-web/src/main/java/org/springframework/web/bind/MissingPathVariableException.java
...pringframework/web/bind/MissingPathVariableException.java
+19
-5
spring-web/src/main/java/org/springframework/web/bind/MissingRequestCookieException.java
...ringframework/web/bind/MissingRequestCookieException.java
+19
-5
spring-web/src/main/java/org/springframework/web/bind/MissingRequestHeaderException.java
...ringframework/web/bind/MissingRequestHeaderException.java
+19
-5
spring-web/src/main/java/org/springframework/web/bind/MissingRequestValueException.java
...pringframework/web/bind/MissingRequestValueException.java
+50
-0
spring-web/src/main/java/org/springframework/web/bind/MissingServletRequestParameterException.java
...ork/web/bind/MissingServletRequestParameterException.java
+19
-4
spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java
...annotation/AbstractCookieValueMethodArgumentResolver.java
+8
-1
spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java
.../annotation/AbstractNamedValueMethodArgumentResolver.java
+15
-2
spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolver.java
...ethod/annotation/RequestHeaderMethodArgumentResolver.java
+7
-1
spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java
...method/annotation/RequestParamMethodArgumentResolver.java
+16
-2
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java
...thod/annotation/MatrixVariableMethodArgumentResolver.java
+7
-1
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java
...method/annotation/PathVariableMethodArgumentResolver.java
+8
-1
未找到文件。
spring-web/src/main/java/org/springframework/web/bind/MissingMatrixVariableException.java
浏览文件 @
1a955692
/*
* Copyright 2002-20
18
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -28,7 +28,7 @@ import org.springframework.core.MethodParameter;
* @see MissingPathVariableException
*/
@SuppressWarnings
(
"serial"
)
public
class
MissingMatrixVariableException
extends
ServletRequestBinding
Exception
{
public
class
MissingMatrixVariableException
extends
MissingRequestValue
Exception
{
private
final
String
variableName
;
...
...
@@ -41,7 +41,20 @@ public class MissingMatrixVariableException extends ServletRequestBindingExcepti
* @param parameter the method parameter
*/
public
MissingMatrixVariableException
(
String
variableName
,
MethodParameter
parameter
)
{
super
(
""
);
this
(
variableName
,
parameter
,
false
);
}
/**
* Constructor for use when a value was present but converted to {@code null}.
* @param variableName the name of the missing matrix variable
* @param parameter the method parameter
* @param missingAfterConversion whether the value became null after conversion
* @since 5.3.6
*/
public
MissingMatrixVariableException
(
String
variableName
,
MethodParameter
parameter
,
boolean
missingAfterConversion
)
{
super
(
""
,
missingAfterConversion
);
this
.
variableName
=
variableName
;
this
.
parameter
=
parameter
;
}
...
...
@@ -49,8 +62,9 @@ public class MissingMatrixVariableException extends ServletRequestBindingExcepti
@Override
public
String
getMessage
()
{
return
"Missing matrix variable '"
+
this
.
variableName
+
"' for method parameter of type "
+
this
.
parameter
.
getNestedParameterType
().
getSimpleName
();
return
"Required matrix variable '"
+
this
.
variableName
+
"' for method parameter type "
+
this
.
parameter
.
getNestedParameterType
().
getSimpleName
()
+
" is "
+
(
isMissingAfterConversion
()
?
"present but converted to null"
:
"not present"
);
}
/**
...
...
spring-web/src/main/java/org/springframework/web/bind/MissingPathVariableException.java
浏览文件 @
1a955692
/*
* Copyright 2002-20
18
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -30,7 +30,7 @@ import org.springframework.core.MethodParameter;
* @see MissingMatrixVariableException
*/
@SuppressWarnings
(
"serial"
)
public
class
MissingPathVariableException
extends
ServletRequestBinding
Exception
{
public
class
MissingPathVariableException
extends
MissingRequestValue
Exception
{
private
final
String
variableName
;
...
...
@@ -43,7 +43,20 @@ public class MissingPathVariableException extends ServletRequestBindingException
* @param parameter the method parameter
*/
public
MissingPathVariableException
(
String
variableName
,
MethodParameter
parameter
)
{
super
(
""
);
this
(
variableName
,
parameter
,
false
);
}
/**
* Constructor for use when a value was present but converted to {@code null}.
* @param variableName the name of the missing path variable
* @param parameter the method parameter
* @param missingAfterConversion whether the value became null after conversion
* @since 5.3.6
*/
public
MissingPathVariableException
(
String
variableName
,
MethodParameter
parameter
,
boolean
missingAfterConversion
)
{
super
(
""
,
missingAfterConversion
);
this
.
variableName
=
variableName
;
this
.
parameter
=
parameter
;
}
...
...
@@ -51,8 +64,9 @@ public class MissingPathVariableException extends ServletRequestBindingException
@Override
public
String
getMessage
()
{
return
"Missing URI template variable '"
+
this
.
variableName
+
"' for method parameter of type "
+
this
.
parameter
.
getNestedParameterType
().
getSimpleName
();
return
"Required URI template variable '"
+
this
.
variableName
+
"' for method parameter type "
+
this
.
parameter
.
getNestedParameterType
().
getSimpleName
()
+
" is "
+
(
isMissingAfterConversion
()
?
"present but converted to null"
:
"not present"
);
}
/**
...
...
spring-web/src/main/java/org/springframework/web/bind/MissingRequestCookieException.java
浏览文件 @
1a955692
/*
* Copyright 2002-20
18
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -28,7 +28,7 @@ import org.springframework.core.MethodParameter;
* @see MissingRequestHeaderException
*/
@SuppressWarnings
(
"serial"
)
public
class
MissingRequestCookieException
extends
ServletRequestBinding
Exception
{
public
class
MissingRequestCookieException
extends
MissingRequestValue
Exception
{
private
final
String
cookieName
;
...
...
@@ -41,7 +41,20 @@ public class MissingRequestCookieException extends ServletRequestBindingExceptio
* @param parameter the method parameter
*/
public
MissingRequestCookieException
(
String
cookieName
,
MethodParameter
parameter
)
{
super
(
""
);
this
(
cookieName
,
parameter
,
false
);
}
/**
* Constructor for use when a value was present but converted to {@code null}.
* @param cookieName the name of the missing request cookie
* @param parameter the method parameter
* @param missingAfterConversion whether the value became null after conversion
* @since 5.3.6
*/
public
MissingRequestCookieException
(
String
cookieName
,
MethodParameter
parameter
,
boolean
missingAfterConversion
)
{
super
(
""
,
missingAfterConversion
);
this
.
cookieName
=
cookieName
;
this
.
parameter
=
parameter
;
}
...
...
@@ -49,8 +62,9 @@ public class MissingRequestCookieException extends ServletRequestBindingExceptio
@Override
public
String
getMessage
()
{
return
"Missing cookie '"
+
this
.
cookieName
+
"' for method parameter of type "
+
this
.
parameter
.
getNestedParameterType
().
getSimpleName
();
return
"Required cookie '"
+
this
.
cookieName
+
"' for method parameter type "
+
this
.
parameter
.
getNestedParameterType
().
getSimpleName
()
+
" is "
+
(
isMissingAfterConversion
()
?
"present but converted to null"
:
"not present"
);
}
/**
...
...
spring-web/src/main/java/org/springframework/web/bind/MissingRequestHeaderException.java
浏览文件 @
1a955692
/*
* Copyright 2002-20
18
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -28,7 +28,7 @@ import org.springframework.core.MethodParameter;
* @see MissingRequestCookieException
*/
@SuppressWarnings
(
"serial"
)
public
class
MissingRequestHeaderException
extends
ServletRequestBinding
Exception
{
public
class
MissingRequestHeaderException
extends
MissingRequestValue
Exception
{
private
final
String
headerName
;
...
...
@@ -41,7 +41,20 @@ public class MissingRequestHeaderException extends ServletRequestBindingExceptio
* @param parameter the method parameter
*/
public
MissingRequestHeaderException
(
String
headerName
,
MethodParameter
parameter
)
{
super
(
""
);
this
(
headerName
,
parameter
,
false
);
}
/**
* Constructor for use when a value was present but converted to {@code null}.
* @param headerName the name of the missing request header
* @param parameter the method parameter
* @param missingAfterConversion whether the value became null after conversion
* @since 5.3.6
*/
public
MissingRequestHeaderException
(
String
headerName
,
MethodParameter
parameter
,
boolean
missingAfterConversion
)
{
super
(
""
,
missingAfterConversion
);
this
.
headerName
=
headerName
;
this
.
parameter
=
parameter
;
}
...
...
@@ -49,8 +62,9 @@ public class MissingRequestHeaderException extends ServletRequestBindingExceptio
@Override
public
String
getMessage
()
{
return
"Missing request header '"
+
this
.
headerName
+
"' for method parameter of type "
+
this
.
parameter
.
getNestedParameterType
().
getSimpleName
();
String
typeName
=
this
.
parameter
.
getNestedParameterType
().
getSimpleName
();
return
"Required request header '"
+
this
.
headerName
+
"' for method parameter type "
+
typeName
+
" is "
+
(
isMissingAfterConversion
()
?
"present but converted to null"
:
"not present"
);
}
/**
...
...
spring-web/src/main/java/org/springframework/web/bind/MissingRequestValueException.java
0 → 100644
浏览文件 @
1a955692
/*
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.web.bind
;
/**
* Base class for {@link ServletRequestBindingException} exceptions that could
* not bind because the request value is required but is either missing or
* otherwise resolves to {@code null} after conversion.
*
* @author Rossen Stoyanchev
* @since 5.3.6
*/
@SuppressWarnings
(
"serial"
)
public
class
MissingRequestValueException
extends
ServletRequestBindingException
{
private
final
boolean
missingAfterConversion
;
public
MissingRequestValueException
(
String
msg
)
{
this
(
msg
,
false
);
}
public
MissingRequestValueException
(
String
msg
,
boolean
missingAfterConversion
)
{
super
(
msg
);
this
.
missingAfterConversion
=
missingAfterConversion
;
}
/**
* Whether the request value was present but converted to {@code null}, e.g. via
* {@code org.springframework.core.convert.support.IdToEntityConverter}.
*/
public
boolean
isMissingAfterConversion
()
{
return
this
.
missingAfterConversion
;
}
}
spring-web/src/main/java/org/springframework/web/bind/MissingServletRequestParameterException.java
浏览文件 @
1a955692
/*
* Copyright 2002-20
12
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -23,7 +23,7 @@ package org.springframework.web.bind;
* @since 2.0.2
*/
@SuppressWarnings
(
"serial"
)
public
class
MissingServletRequestParameterException
extends
ServletRequestBinding
Exception
{
public
class
MissingServletRequestParameterException
extends
MissingRequestValue
Exception
{
private
final
String
parameterName
;
...
...
@@ -36,7 +36,20 @@ public class MissingServletRequestParameterException extends ServletRequestBindi
* @param parameterType the expected type of the missing parameter
*/
public
MissingServletRequestParameterException
(
String
parameterName
,
String
parameterType
)
{
super
(
""
);
this
(
parameterName
,
parameterType
,
false
);
}
/**
* Constructor for use when a value was present but converted to {@code null}.
* @param parameterName the name of the missing parameter
* @param parameterType the expected type of the missing parameter
* @param missingAfterConversion whether the value became null after conversion
* @since 5.3.6
*/
public
MissingServletRequestParameterException
(
String
parameterName
,
String
parameterType
,
boolean
missingAfterConversion
)
{
super
(
""
,
missingAfterConversion
);
this
.
parameterName
=
parameterName
;
this
.
parameterType
=
parameterType
;
}
...
...
@@ -44,7 +57,9 @@ public class MissingServletRequestParameterException extends ServletRequestBindi
@Override
public
String
getMessage
()
{
return
"Required "
+
this
.
parameterType
+
" parameter '"
+
this
.
parameterName
+
"' is not present"
;
return
"Required request parameter '"
+
this
.
parameterName
+
"' for method parameter type "
+
this
.
parameterType
+
" is "
+
(
isMissingAfterConversion
()
?
"present but converted to null"
:
"not present"
);
}
/**
...
...
spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java
浏览文件 @
1a955692
/*
* Copyright 2002-20
18
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -24,6 +24,7 @@ import org.springframework.web.bind.MissingRequestCookieException;
import
org.springframework.web.bind.ServletRequestBindingException
;
import
org.springframework.web.bind.WebDataBinder
;
import
org.springframework.web.bind.annotation.CookieValue
;
import
org.springframework.web.context.request.NativeWebRequest
;
/**
* A base abstract class to resolve method arguments annotated with
...
...
@@ -70,6 +71,12 @@ public abstract class AbstractCookieValueMethodArgumentResolver extends Abstract
throw
new
MissingRequestCookieException
(
name
,
parameter
);
}
@Override
protected
void
handleMissingValueAfterConversion
(
String
name
,
MethodParameter
parameter
,
NativeWebRequest
request
)
throws
Exception
{
throw
new
MissingRequestCookieException
(
name
,
parameter
,
true
);
}
private
static
final
class
CookieValueNamedValueInfo
extends
NamedValueInfo
{
...
...
spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java
浏览文件 @
1a955692
/*
* Copyright 2002-202
0
the original author or authors.
* Copyright 2002-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -135,7 +135,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
// Check for null value after conversion of incoming argument value
if
(
arg
==
null
&&
namedValueInfo
.
defaultValue
==
null
&&
namedValueInfo
.
required
&&
!
nestedParameter
.
isOptional
())
{
handleMissingValue
(
namedValueInfo
.
name
,
nestedParameter
,
webRequest
);
handleMissingValue
AfterConversion
(
namedValueInfo
.
name
,
nestedParameter
,
webRequest
);
}
}
...
...
@@ -237,6 +237,19 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
"' for method parameter of type "
+
parameter
.
getNestedParameterType
().
getSimpleName
());
}
/**
* Invoked when a named value is present but becomes {@code null} after conversion.
* @param name the name for the value
* @param parameter the method parameter
* @param request the current request
* @since 5.3.6
*/
protected
void
handleMissingValueAfterConversion
(
String
name
,
MethodParameter
parameter
,
NativeWebRequest
request
)
throws
Exception
{
handleMissingValue
(
name
,
parameter
,
request
);
}
/**
* A {@code null} results in a {@code false} value for {@code boolean}s or an exception for other primitives.
*/
...
...
spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolver.java
浏览文件 @
1a955692
/*
* Copyright 2002-20
18
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -87,6 +87,12 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueMetho
throw
new
MissingRequestHeaderException
(
name
,
parameter
);
}
@Override
protected
void
handleMissingValueAfterConversion
(
String
name
,
MethodParameter
parameter
,
NativeWebRequest
request
)
throws
Exception
{
throw
new
MissingRequestHeaderException
(
name
,
parameter
,
true
);
}
private
static
final
class
RequestHeaderNamedValueInfo
extends
NamedValueInfo
{
...
...
spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java
浏览文件 @
1a955692
/*
* Copyright 2002-20
19
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -190,6 +190,20 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
protected
void
handleMissingValue
(
String
name
,
MethodParameter
parameter
,
NativeWebRequest
request
)
throws
Exception
{
handleMissingValueInternal
(
name
,
parameter
,
request
,
false
);
}
@Override
protected
void
handleMissingValueAfterConversion
(
String
name
,
MethodParameter
parameter
,
NativeWebRequest
request
)
throws
Exception
{
handleMissingValueInternal
(
name
,
parameter
,
request
,
true
);
}
protected
void
handleMissingValueInternal
(
String
name
,
MethodParameter
parameter
,
NativeWebRequest
request
,
boolean
missingAfterConversion
)
throws
Exception
{
HttpServletRequest
servletRequest
=
request
.
getNativeRequest
(
HttpServletRequest
.
class
);
if
(
MultipartResolutionDelegate
.
isMultipartArgument
(
parameter
))
{
if
(
servletRequest
==
null
||
!
MultipartResolutionDelegate
.
isMultipartRequest
(
servletRequest
))
{
...
...
@@ -201,7 +215,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
}
else
{
throw
new
MissingServletRequestParameterException
(
name
,
parameter
.
getNestedParameterType
().
getSimpleName
());
parameter
.
getNestedParameterType
().
getSimpleName
()
,
missingAfterConversion
);
}
}
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java
浏览文件 @
1a955692
/*
* Copyright 2002-20
18
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -126,6 +126,12 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth
throw
new
MissingMatrixVariableException
(
name
,
parameter
);
}
@Override
protected
void
handleMissingValueAfterConversion
(
String
name
,
MethodParameter
parameter
,
NativeWebRequest
request
)
throws
Exception
{
throw
new
MissingMatrixVariableException
(
name
,
parameter
,
true
);
}
private
static
final
class
MatrixVariableNamedValueInfo
extends
NamedValueInfo
{
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java
浏览文件 @
1a955692
/*
* Copyright 2002-20
19
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -101,6 +101,13 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueMethod
throw
new
MissingPathVariableException
(
name
,
parameter
);
}
@Override
protected
void
handleMissingValueAfterConversion
(
String
name
,
MethodParameter
parameter
,
NativeWebRequest
request
)
throws
Exception
{
throw
new
MissingPathVariableException
(
name
,
parameter
,
true
);
}
@Override
@SuppressWarnings
(
"unchecked"
)
protected
void
handleResolvedValue
(
@Nullable
Object
arg
,
String
name
,
MethodParameter
parameter
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录