Assert a good practice or not ?

Posted by rkenshin on Stack Overflow See other posts from Stack Overflow or by rkenshin
Published on 2010-03-14T02:33:41Z Indexed on 2010/03/14 2:45 UTC
Read the original article Hit count: 639

Filed under:
|
|

Is it a good practice to use Assert for function parameters to enforce their validity. I was going through the source code of Spring Framework and I noticed that they use Assert.notNull a lot. Here's an example

   public static ParsedSql parseSqlStatement(String sql) {
    Assert.notNull(sql, "SQL must not be null");}

Here's Another one

public NamedParameterJdbcTemplate(DataSource dataSource) {
            Assert.notNull(dataSource,
                    "The [dataSource] argument cannot be null.");
            this .classicJdbcTemplate = new JdbcTemplate(dataSource);
        }

        public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate) {
            Assert.notNull(classicJdbcTemplate,
                    "JdbcTemplate must not be null");
            this .classicJdbcTemplate = classicJdbcTemplate;
      }

Thank you

© Stack Overflow or respective owner

Related posts about java

Related posts about assert