spring源碼之—Assert.notNull

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必須不能爲空。如果爲空就拋出異常。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章