码迷,mamicode.com
首页 > 编程语言 > 详细

spring源码之—Assert.notNull

时间:2018-08-27 14:11:20      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:The   分享   进入   概念   hat   div   unit   check   fail   

org.springframework.util.Assert
Assert翻译为中文为"断言".用过JUNIT的应该都知道这个概念了.
就是断定某一个实际的值就为自己预期想得到的,如果不一样就抛出异常.
Assert经常用于:
1.判断METHOD的参数是否属于正常值.
2.JUNIT中使用.
 
我发现SPRING1.2.6里面有BUG
请看:
org.springframework.core.io.support.EncodedResource中
public EncodedResource(Resource resource, String encoding) {
  Assert.notNull("Resource is required");
  this.resource = resource;
  this.encoding = encoding;
}

 

Assert.notNull("Resource is required");
这句应该为
Assert.notNull(resource,"Resource is required");
不然resource都没传过来,还断什么言啊,呵呵.
 
------------------------------------------------------------------------
上面是在网上看到了,但是我进入spring里面看了一下源码,如下:
技术分享图片
/**
* Assert that an object is not <code>null</code> .
* <pre class="code">Assert.notNull(clazz, "The class must not be null");</pre>
* @param object the object to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object is <code>null</code>
*/
public static void notNull(Object object, String message) {
  if (object == null) {
    throw new IllegalArgumentException(message);
  }
}
技术分享图片
该函数的意思是传入的object必须不能为空。如果为空就抛出异常。
 
转自:http://jack-chen10.blog.163.com/blog/static/6775128201348545984/

spring源码之—Assert.notNull

标签:The   分享   进入   概念   hat   div   unit   check   fail   

原文地址:https://www.cnblogs.com/jpfss/p/9541397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!