1.结论if判断空对象没写,java是强类型语言,以后还需要注意一点。
请求
{
"code": 400,
"message": "Source must not be null",
"error": "非法的参数",
"path": "/store/home/homePage",
"verb": "GET"
}
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@978bc02] was not registered for synchronization because synchronization is not active
2023-03-10 21:51:06.662 DEBUG 26464 --- [io-18082-exec-4] o.s.jdbc.datasource.DataSourceUtils : Fetching JDBC Connection from DataSource
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@60db5aad] will not be managed by Spring
==> Preparing: SELECT user_id,merchant_code,merchant_name,deleted,creator_id,gmt_create,modifier_id,gmt_modify FROM hall_merchant WHERE deleted=0 AND (user_id = ?)
==> Parameters: 1(Long)
<== Total: 0
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@978bc02]
2023-03-10 21:51:06.710 DEBUG 26464 --- [io-18082-exec-4] .m.m.a.ExceptionHandlerExceptionResolver : Using @ExceptionHandler com.bci.bootstrap.exception.ControllerExceptionHandler#handle(IllegalArgumentException, HttpServletRequest)
2023-03-10 21:51:06.710 WARN 26464 --- [io-18082-exec-4] c.b.b.e.ControllerExceptionHandler : 非法的参数: Source must not be null
2023-03-10 21:51:06.711 DEBUG 26464 --- [io-18082-exec-4] m.m.a.RequestResponseBodyMethodProcessor : Using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, application/*+json]
2023-03-10 21:51:06.711 DEBUG 26464 --- [io-18082-exec-4] m.m.a.RequestResponseBodyMethodProcessor : Writing [RestResult(code=400, message=Source must not be null, error=非法的参数, data=null, path=/store/home/homeP (truncated)...]
2023-03-10 21:51:06.712 DEBUG 26464 --- [io-18082-exec-4] o.s.s.w.header.writers.HstsHeaderWriter : Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@2dcc11cd
2023-03-10 21:51:06.713 DEBUG 26464 --- [io-18082-exec-4] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [java.lang.IllegalArgumentException: Source must not be null]
2023-03-10 21:51:06.713 DEBUG 26464 --- [io-18082-exec-4] o.s.web.servlet.DispatcherServlet : Completed 400 BAD_REQUEST
2023-03-10 21:51:06.714 DEBUG 26464 --- [io-18082-exec-4] o.s.s.w.a.ExceptionTranslationFilter : Chain processed normally
2023-03-10 21:51:06.714 DEBUG 26464 --- [io-18082-exec-4] s.s.w.c.SecurityContextPersistenceFilter : SecurityContextHolder now cleared, as request processing completed
2023-03-10 21:51:06.717 DEBUG 26464 --- [io-18082-exec-4] o.apache.coyote.http11.Http11Processor : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@4378e206:org.apache.tomcat.util.net.NioChannel@7319d854:java.nio.channels.SocketChannel[connected local=/192.168.110.102:18082 remote=/192.168.110.102:60324]], Status in: [OPEN_READ], State out: [CLOSED]
2023-03-10 21:51:06.717 DEBUG 26464 --- [io-18082-exec-4] o.apache.tomcat.util.threads.LimitLatch : Counting down[http-nio-18082-exec-4] latch=1
2023-03-10 21:51:06.717 DEBUG 26464 --- [io-18082-exec-4] org.apache.tomcat.util.net.NioEndpoint : Calling [org.apache.tomcat.util.net.NioEndpoint@3efb1922].closeSocket([org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@4378e206:org.apache.tomcat.util.net.NioChannel@7319d854:java.nio.channels.SocketChannel[connected local=/192.168.110.102:18082 remote=/192.168.110.102:60324]])
2023-03-10 21:51:14.979 DEBUG 26464 --- [SchedulerThread] org.quartz.core.QuartzSchedulerThread : batch acquisition of 0 triggers
错误原因:
hall_merchant 表查询不到,后面copy的时候报错。但是try catch捕获不到异常。
错误代码 :
异常来源
package org.springframework.beans;
BeanUtils.java
private static void copyProperties(Object source, Object target, @Nullable Class<?> editable,
@Nullable String... ignoreProperties) throws BeansException {
Assert.notNull(source, "Source must not be null");
Assert.notNull(target, "Target must not be null");
Class<?> actualEditable = target.getClass();
if (editable != null) {
if (!editable.isInstance(target)) {
throw new IllegalArgumentException("Target class [" + target.getClass().getName() +
"] not assignable to Editable class [" + editable.getName() + "]");
}
actualEditable = editable;
}
PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null);
for (PropertyDescriptor targetPd : targetPds) {
Method writeMethod = targetPd.getWriteMethod();
if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) {
PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
if (sourcePd != null) {
Method readMethod = sourcePd.getReadMethod();
if (readMethod != null) {
ResolvableType sourceResolvableType = ResolvableType.forMethodReturnType(readMethod);
ResolvableType targetResolvableType = ResolvableType.forMethodParameter(writeMethod, 0);
// Ignore generic types in assignable check if either ResolvableType has unresolvable generics.
boolean isAssignable =
(sourceResolvableType.hasUnresolvableGenerics() || targetResolvableType.hasUnresolvableGenerics() ?
ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType()) :
targetResolvableType.isAssignableFrom(sourceResolvableType));
if (isAssignable) {
try {
if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
readMethod.setAccessible(true);
}
Object value = readMethod.invoke(source);
if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
writeMethod.setAccessible(true);
}
writeMethod.invoke(target, value);
}
catch (Throwable ex) {
throw new FatalBeanException(
"Could not copy property '" + targetPd.getName() + "' from source to target", ex);
}
}
}
}
}
}
}