-
1. Re: NPE when logging inside a property getter
pmuir Jan 30, 2008 2:58 PM (in response to cyberanto)Where do you call getFeatures from?
-
2. Re: NPE when logging inside a property getter
jdijkmeijer Jan 31, 2008 9:28 AM (in response to cyberanto)Also make sure that your Log is a seam Log, and not a commons log or something different. check your import.s
-
3. Re: NPE when logging inside a property getter
cyberanto Feb 1, 2008 3:48 PM (in response to cyberanto)hmm, I had transferred a couple of DAOs from another project which had been using commons logging.
After replacing all my commons logging imports with seam.log.Log, all hell is breaking loose ...
e.g.
==========================================
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.log.Log;
@Name("applicationCache")
@Scope(APPLICATION)
public class SwcmApplicationCache implements Serializable {
@Logger private Log log;
CategoryDAO categoryDao = new CategoryDAO();
public String refreshCategories() {
String outcome = ActionOutcomes.SUCCESS;
try {
categories.clear();
categories.addAll(categoryDao.getAllCategories());
staleCategory = false;
} catch (ServerException e) {
e.printStackTrace();
outcome = ActionOutcomes.FAILURE;
}
log.info("updating application cache categories outcome: "+outcome);
return outcome;
}
...
}
============================================
@Name("categoryDao")
public class CategoryDAO extends AbstractDAO {
@Logger private Log log;
public ArrayList getAllCategories() throws ServerException {
...
System.out.println("Logger is: "+log);
log.info("#0 categories returned ...", categories.size());
return categories;
}
}
bombs on Line 55 - the log.info() in the CategoryDAO ... (categories is NOT null) ...
14:39:56,171 INFO [STDOUT] Logger is: null
Caused by: java.lang.NullPointerException
at com.jostens.swcm.sql.CategoryDAO.getAllCategories(CategoryDAO.java:55)
at com.jostens.swcm.application.SwcmApplicationCache.refreshCategories(SwcmApplicationCache.java:68)
Unless someone can tell me what I am doing wrong, I may have to replace all my logging with System.out.print()'s ...
I am using JBOSS Developer Studio and set up my project using its ejb wizard. The SEAM Logger works fine in some other classes ... -
4. Re: NPE when logging inside a property getter
cyberanto Feb 1, 2008 4:39 PM (in response to cyberanto)I found out what my mistake was:
I didn't use injection to create the component which contained the SEAM Logger ...
injecting the component initializes the Logger correctly.
@In(create=true)
private CategoryDAO categoryDao;
//
// CategoryDAO categoryDao = new CategoryDAO();
There used to be a class org.jboss.seam.log.LogImpl ... not any more
How do I get a Seam Logger if I want to instantiate the class "normally" ? -
5. Re: NPE when logging inside a property getter
nickarls Feb 1, 2008 5:30 PM (in response to cyberanto)Haven't used it but Logger seams to have some static methods that might be interesting.