java - should I pay much attention on NullPointerException? -
when use junit test check coding process,i find there problems bother me. example: list<user> list = userdao.findby("id",id); list.get(0).getname(); there problem.i didn't use assert check list not null before using may cause nullpointexception.but @ business logic. when create new user this. if(user!=null){ userdao.save(user) } it should not null.because check user not null when add one, know user successful in database. if add lot of when user: if(list!=null||list.size()>0){...}; in similar place makes code chaos. should add or not?how make choice? thx anyway. i think looking method preconditions or, more generally, contracts . let's assume code split many small methods, should be. define preconditions , postconditions every method. these need met, otherwise failure expected. if consistently, question of put these checks pretty answer in quite intuitive way. as example, let's consider 2 ways write method user : p...