i am trying to write test case for below controller its working fine,But problem is when i run unit test case then its showing null pointer exception in controller class at (LOGGER.info("========>request is------>" + objectMapper.writeValueAsString(basBaaisnEvcIdRequest));
can some one help me please how can i resolve this problem
controller
#RequestMapping(value = "/api/baaisn/queryevcid", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
#ResponseBody
public BaaisnEvcIdResponse getQueryEvcid(#RequestBody BaaisnEvcIdRequest basBaaisnEvcIdRequest)
throws IOException, DAOException, SQLException, HttpServletException,JsonProcessingException {
LOGGER.info("========>request is------>" + objectMapper.writeValueAsString(basBaaisnEvcIdRequest));
if (basBaaisnEvcIdRequest.getLata() != 0 && (basBaaisnEvcIdRequest.getProduct_type() != null
&& !basBaaisnEvcIdRequest.getProduct_type().equalsIgnoreCase(""))) {
BaaisnEvcIdResponse baaisnEvcIdResponse = BaaisnEvcIdMSService.getQueryEvcidService(basBaaisnEvcIdRequest);
return baaisnEvcIdResponse;
} else {
BaaisnEvcIdResponse basiBaaisnEvcIdResponse = new BaaisnEvcIdResponse();
basiBaaisnEvcIdResponse.setStatus_code(0);
if (basBaaisnEvcIdRequest.getProduct_type() == null || basBaaisnEvcIdRequest.getProduct_type().equals("")) {
basiBaaisnEvcIdResponse.setStatus_desc("Please send Product type");
} else if (basBaaisnEvcIdRequest.getLata() == 0) {
basiBaaisnEvcIdResponse.setStatus_desc("Please send Lata");
}
return basiBaaisnEvcIdResponse;
}
}
Test class
#InjectMocks
BaaisnEvcIdMSController baaisnEvcIdMSController;
#Mock
BaaisnEvcIdMSService baaisnEvcIdMSService;
#Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
#Test
public void getQueryEvcid() throws
IOException, DAOException, SQLException, HttpServletException,JsonProcessingException{
//Request object
BaaisnEvcIdRequest baaisnEvcIdRequest = mock(BaaisnEvcIdRequest.class);
Mockito.when(baaisnEvcIdRequest.getLata()).thenReturn(620);
Mockito.when(baaisnEvcIdRequest.getProduct_type()).thenReturn("LEVC");
Mockito.when(baaisnEvcIdRequest.getSvc_type()).thenReturn("EMS");
//Response object
BaaisnEvcIdResponse basiBaaisnEvcIdResponse = mock(BaaisnEvcIdResponse.class);
Mockito.when(basiBaaisnEvcIdResponse.getEvc_id()).thenReturn("/TLSM/100020218/001");
Mockito.when(basiBaaisnEvcIdResponse.getStatus_code()).thenReturn(1);
Mockito.when(basiBaaisnEvcIdResponse.getStatus_desc()).thenReturn("Success");
Mockito.when(baaisnEvcIdMSService.getQueryEvcidService(Mockito.any()))
.thenReturn(basiBaaisnEvcIdResponse);
BaaisnEvcIdResponse mockResponse = baaisnEvcIdMSController.getQueryEvcid(baaisnEvcIdRequest);
assertEquals("Success", mockResponse.getStatus_desc());
assertEquals("/TLSM/100020218/001", mockResponse.getEvc_id());
}
exception
java.lang.NullPointerException
at com.verizon.uts.ms.cdm.baaisn.evcid.controller.BaaisnEvcIdMSController.getQueryEvcid(BaaisnEvcIdMSController.java:44)
at com.verizon.uts.ms.cdm.baaisn.evcid.controller.BaaisnEvcIdMSControllerTest.getQueryEvcid(BaaisnEvcIdMSControllerTest.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:40)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)
at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:71)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:137)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Related
So I have the following pieces of code and like it says in the title, despite expecting the exception and catching it, it is escalated. This is gonna be a game and my whole communication to the gui about invalid turn is based on exceptions, so if this persists with my custom exceptions, i'm in trouble.
#Test
public void testLoadMoneyCards() {
File file = new File(MONEY_CARDS_PATH);
try {
System.out.println(ioController.loadCards(file));
} catch (IOException e) {
e.printStackTrace();
}
}
private Card parseCard(String[] properties,int id) throws IOException {
if (properties[0].equals("Wertung")) {
Score score = new Score();
score.setId(id);
try {
score.setType(Integer.parseInt(properties[1]) == 1 ? ScoreRound.FIRST : ScoreRound.SECOND);
} catch (NumberFormatException e) {throw new IOException("Card object could not be parsed");}
return score;
} else if (!properties[0].equals("Waehrung")) {
Money card = new Money();
card.setId(id);
card.setColor(parseMoneyColor(properties[0]));
try {
card.setValue(Integer.parseInt(properties[1]));
} catch (NumberFormatException e) {throw new IOException("Card object could not be parsed");}
return card;
}
return null;
}
java.io.IOException: Card object could not be parsed
at controller.IOController.parseCard(IOController.java:145)
at controller.IOController.loadCards(IOController.java:82)
at controller.IOControllerTest.testLoadMoneyCards(IOControllerTest.java:27)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:118)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:835)
I am using Mockito for testing. Getting nullpointerexcpetion with message as null
TestMethod
// build request
RequestObject requestObject = new RequestObject();
String accountNumber = "12345628928";
String accountId = "dc23362e-f46f-4cce-b49a-cd10d737f483";
requestObject.setAccountId(accountId);
requestObject.setAccountNumber(accountNumber);
String firstName = "test";
String middlename = "test";
String lastName = "test";
String gender = "M";
String dob = "01-JUN-2016";
String emailaddress = "test#test.com";
String prefferedLanguageCode = "1";
String preffredname = "test";
String prefix = "Mr.";
String suffix = "Jr";
String minor = "1";
String deathDate = "09-SEP-2009";
String deathInformationDate = "14-OCT-2010";
Customer customer = new Customer();
customer.setFirstName(firstName);
customer.setMiddleName(middlename);
customer.setLastName(lastName);
customer.setGender(gender);
customer.setDob(dob);
customer.setEmail(emailaddress);
customer.setPreferredLanguageCode(prefferedLanguageCode);
customer.setPreferredName(preffredname);
customer.setPrefix(prefix);
customer.setSuffix(suffix);
customer.setMinor(minor);
customer.setDeathDate(deathDate);
customer.setDeathInformedDate(deathInformationDate);
requestObject.setCustomer(customer);
IdObject idObject = new IdObject();
idObject.setAccountId(UUID.fromString(accountId));
List<PersonAccount> personAccount = new ArrayList<PersonAccount>();
PersonAccount personAccount1 = new PersonAccount();
personAccount1.setFirstName("First name in testing");
personAccount.add(personAccount1);
// mock external call
when(sessionFactory.openSession()).thenReturn(session);
when(session.beginTransaction()).thenReturn(transaction);
when(session.createQuery(SQLConstants.FETCH_PERSON_ACCT)).thenReturn(query);
when(query.list()).thenReturn(personAccount);
when(query.executeUpdate()).thenReturn(1);
// Call the testing method
idObject = customerDAOImpl.updateCustomerRecord(requestObject);
//check the assertion
assertEquals("dc23362e-f46f-4cce-b49a-cd10d737f483", idObject.getAccountId().toString());
// verify the mock call
verify(customerDAOImpl, times(1)).updateCustomerRecord(requestObject);
and my
UpdateMethod
`
private void updateAccountInformation(RequestObject requestObject, Session session)
throws CustomerDataException{
try{
Query queryForPersonAccount = session.createQuery(SQLConstants.FETCH_PERSON_ACCT);
queryForPersonAccount.setParameter(Constants.ACCOUNTID, UUID.fromString(requestObject.getAccountId().toUpperCase()));
#SuppressWarnings("unchecked")
List<PersonAccount> listpersonAccount = (List<PersonAccount>) queryForPersonAccount.list();
if (CollectionUtils.isNotEmpty(listpersonAccount)) {
PersonAccount personAccount = listpersonAccount.get(0);
Query updateQuery = session.createQuery(SQLConstants.UPDATE_PERSON_ACCOUNT);
updateQuery.setParameter(Constants.ACCOUNTID,UUID.fromString(requestObject.getAccountId().toUpperCase()));
updateQuery.setParameter(Constants.UPDATED_BY_NAME, Constants.PCF);
updateQuery.setParameter(Constants.END_TIMESTAMP,DateUtil.dateDDMMMYY());
updateQuery.executeUpdate();
updatePersonAccount(session,personAccount, requestObject);
}else{
throw new CustomerDataException(MessageKeys.UPDATE_CUSTOMER_ERRROR_MESSAGE);
}
}catch(Exception ex)
{
LOGGER.error(Constants.PATIENT_FETCH_EXCEPTION, ex);
throw new CustomerDataException(MessageKeys.UPDATE_CUSTOMER_ERRROR_MESSAGE);
}
}`
I am getting nuppointerexception at line updateQuery.setParameter(Constants.ACCOUNTID,UUID.fromString(requestObject.getAccountId().toUpperCase())).
I can see the accountID is available in the requestObject when I debug.
Following is the stacktrace. Help is apprecited :)
ava.lang.NullPointerException: null
at com.cardinalhealth.chh.dao.CustomerDAOImpl.updateAccountInformation(CustomerDAOImpl.java:312)
at com.cardinalhealth.chh.dao.CustomerDAOImpl.updateCustomer(CustomerDAOImpl.java:285)
at com.cardinalhealth.chh.dao.CustomerDAOImpl.updateCustomerInformations(CustomerDAOImpl.java:180)
at com.cardinalhealth.chh.dao.CustomerDAOImpl.updateCustomerRecord(CustomerDAOImpl.java:141)
at com.cardinalhealth.chh.dao.CustomerDAOImplTest.testUpdateCustomerRecordforCustomerObject(CustomerDAOImplTest.java:452)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Your stubbing of session.createQuery:
when(session.createQuery(SQLConstants.FETCH_PERSON_ACCT)).thenReturn(query);
And what your code actually calls right before you get the exception:
Query updateQuery = session.createQuery(SQLConstants.UPDATE_PERSON_ACCOUNT);
So createQuery is stubbed to return a query when called with a different constant.
Meaning your production code will return null from createQuery and the next line then throws your NPE.
This question already has an answer here:
How to convert Part to Blob, so I can store it in MySQL?
(1 answer)
Closed 6 years ago.
I want to upload a file and save it to mysql database. thus far, I am able to upload the file, print its detail. However, when I attempt to store it in the database via a helper class everything except for the ID become null. Can you take a look and let me know what I am missing? Also, let me know if you see anything that I should change/modify as code enhancement.
Uploading the file using JSF/Primefaces:
<h:form enctype="multipart/form-data">
<p:growl id="messages" showDetail="true" />
<p:fileUpload value="#{fileUploadView1.file}" mode="simple"/>
<p:commandButton value="Submit" ajax="false" actionListener="#{fileUploadView1.upload}" />
</h:form>
FileBean:
#ManagedBean
#SessionScoped
public class FileUploadView1 {
private InputStream input;
private String fileName;
private Long fileSize;
private UploadedFile file;
#Inject
private FileController1 fileController;
public InputStream getInput() {
return input;
}
public String getFileName() {
return fileName;
}
public Long getFileSize() {
return fileSize;
}
public FileController1 getFileController() {
return fileController;
}
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
System.out.println("filesize " + file.getSize());
}
public void upload() throws IOException {
if (file != null) {
FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
input = file.getInputstream();
fileName = file.getFileName();
fileSize = file.getSize();
System.out.println("filesize3 " + file.getSize());
fileController.uploadFile(file);
}
}
}
FileController:
#ManagedBean
#SessionScoped
public class FileController1 {
private FileDbUtil1 fileDbUtil;
private Logger logger = Logger.getLogger(getClass().getName());
public FileController1() throws Exception {
fileDbUtil = FileDbUtil1.getInstance();
}
public String uploadFile(UploadedFile theFile) {
logger.info("Uploading File: " + theFile);
try {
fileDbUtil.uploadFile(theFile);
} catch (Exception exc) {
logger.log(Level.SEVERE, "Error adding files", exc);
addErrorMessage(exc);
return null;
}
return "welcomePrimefaces";
}
private void addErrorMessage(Exception exc) {
FacesMessage message = new FacesMessage("Error: " + exc.getMessage());
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
FileDbUtil File
public static FileDbUtil1 getInstance() throws Exception {
if (instance == null) {
instance = new FileDbUtil1();
}
return instance;
}
private FileDbUtil1() throws Exception {
dataSource = getDataSource();
}
private DataSource getDataSource() throws NamingException {
Context context = new InitialContext();
DataSource theDataSource = (DataSource) context.lookup(jndiName);
return theDataSource;
}
public void uploadFile(UploadedFile theFile) throws Exception {
fileName = theFile.getFileName();
input = theFile.getInputstream();
Connection myConn = null;
PreparedStatement myStmt = null;
try {
myConn = getConnection();
String sql = "insert into upload"
+ "(name, file)"
+ " values (?,?)";
myStmt = myConn.prepareStatement(sql);
// set params
myStmt.setString(1, fileName);
myStmt.setBinaryStream(2, input);
myStmt.executeUpdate();
} finally {
close(myConn, myStmt);
}
}
private Connection getConnection() throws Exception {
Connection theConn = dataSource.getConnection();
return theConn;
}
private void close(Connection theConn, Statement theStmt) {
close(theConn, theStmt, null);
}
private void close(Connection theConn, Statement theStmt, ResultSet theRs) {
try {
if (theRs != null) {
theRs.close();
}
if (theStmt != null) {
theStmt.close();
}
if (theConn != null) {
theConn.close();
}
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
Stack Trace: Note that I am able to print the file size before calling the helper class
Info: filesize 3501
Info: filesize3 3501
Warning: java.lang.NullPointerException
javax.el.ELException: java.lang.NullPointerException
at com.sun.el.parser.AstValue.invoke(AstValue.java:293)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:814)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at com.uploadfile.test.FileUploadView1.upload(FileUploadView1.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
... 39 more
FATAL: JSF1073: javax.faces.FacesException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=, Message=java.lang.NullPointerException
FATAL: java.lang.NullPointerException
javax.faces.FacesException: java.lang.NullPointerException
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.ELException: java.lang.NullPointerException
at com.sun.el.parser.AstValue.invoke(AstValue.java:293)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:814)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
... 31 more
Caused by: java.lang.NullPointerException
at com.uploadfile.test.FileUploadView1.upload(FileUploadView1.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
... 39 more
Caused by: java.lang.NullPointerException
at com.uploadfile.test.FileUploadView1.upload(FileUploadView1.java:68)
fileController isn't getting injected.
Use #Inject private FileController1 fileController.
BalusC is right on his comment.
I have a RESTeasy service thats running on JBOSS AS 7, that is trying to create a connection with a local database (mysql server).
The data source is properly defined in the JBOSS management and connects fine (a JSF app can connect fine with it and it can modify the database), however when I try to connect in my RESTeasy service, it gives me a nullPointerException and I can't seem to figure out why. kumonobs is the database in question. The error occurs in the persist method, which is called through a post request. Any help would be much appreciated, if any additional information is needed please ask!
#Path("/RSAndroid")
#ApplicationScoped
public class HelloWorldResource implements Serializable{
#Resource(mappedName = "java:jboss/datasources/kumonobs")
private static DataSource dataSource;
private static ArrayList<Student> students = new ArrayList<Student>();
#GET()
#Produces("text/plain")
public String sayHello() {
return stringStudents(students);
}
#POST()
#Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String postStudent(#FormParam("Student ID") String student){
Date date = new Date();
Student kumonstudent = new Student(student, date);
studentCheck(kumonstudent);
System.out.println(kumonstudent.toString());
return "OK";
}
public String stringStudents(ArrayList<Student> s){
String students = "";
for(Student student : s){
students += student.toString();
}
return students;
}
public void studentCheck(Student student){
boolean checkIn = true;
int count = 0;
for(Student s : students){
count++;
//If Student has been found in the list.
if(s.getStudentID().equals(student.getStudentID())){
//remove the student from the list.
students.remove(count-1);
// ** DO DATABASE STUFF HERE FOR REMOVING STUDENT **
checkIn = false;
break;
}
}
//If student needs to be checked in, add to list.
if(checkIn){
System.out.println(student.getDate());
students.add(student);
// ** DO DATABASE STUFF HERE FOR ADDING STUDENT **
persist(student);
}
}
//Insert student into database table.
public void persist(Student student) {
PreparedStatement stmt = null;
Connection connection = null;
try {
try {
connection = dataSource.getConnection(); //ERROR OCCURS HERE NULLPOINTER
try {
System.out.println("Fourth");
stmt = connection.prepareStatement(
"INSERT INTO checkin VALUES (?, ?)");
stmt.setString(1, "A00105010");
stmt.setString(2, "Sample Name");
stmt.executeUpdate();
} finally {
if (stmt != null) {
stmt.close();
}
}
} finally {
if (connection != null) {
connection.close();
}
}
} catch (SQLException ex) {
System.out.println("Error in persist ");
ex.printStackTrace();
}
}
}
Stack
14:29:22,040 INFO [stdout] (http--0.0.0.0-8080-1) 2012-11-06
14:29:22,040 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host]. [/AndroidRS].[Resteasy]] (http--0.0.0.0-8080-1) Servlet.service() for servlet R
esteasy threw exception: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:340) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:540) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.2.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_27]
Caused by: java.lang.NullPointerException
at org.jboss.samples.rs.webservices.HelloWorldResource.persist(HelloWorldResource.java:92) [classes:]
at org.jboss.samples.rs.webservices.HelloWorldResource.studentCheck(HelloWorldResource.java:81) [classes:]
at org.jboss.samples.rs.webservices.HelloWorldResource.postStudent(HelloWorldResource.java:44) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_27]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_27]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_27]
at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_27]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525) [resteasy-jaxrs-2.3.2.Final.jar:]
... 19 more
Found the solution, instead of the Annotation to the datasource use:
String strDSName = "java:jboss/datasources/thenamehere";
ctx = new InitialContext();
dataSource = (javax.sql.DataSource) ctx.lookup(strDSName);
I'm trying to figure out how to serialize a list using AutoBean in GWT, but I keep getting a Null Pointer Exception.
Here's what I have:
GuideCreatorFactory beanFactory = AutoBeanFactorySource.create(GuideCreatorFactory.class);
List<Guide> guides = new LinkedList<Guide>();
Guide guide = new Guide();
guide.setText("this is the text");
guide.setTitle("this is the title");
guides.add(guide);
GuideCreatorList<Guide> impl = new GuideCreatorListImpl();
impl.setGuides(guides);
System.out.println("Serializing the given parameter to JSON");
// Fails on the below lines w/ NPE
AutoBean<GuideCreatorList> bean = beanFactory.create(GuideCreatorList.class, impl);
String json = AutoBeanCodex.encode(bean).getPayload();
System.out.println("guides as json: " + json);
Can anyone help point me in the right direction? Thank you very much.
Here's the supporting classes and interfaces:
public interface GuideCreatorFactory extends AutoBeanFactory {
AutoBean<GuideCreator> createGuide();
AutoBean<GuideCreatorList> createGuideList();
}
public interface GuideCreator {
public String getText();
public void setText(String text);
public String getTitle();
public void setTitle(String title);
}
public interface GuideCreatorList<T extends GuideCreator> {
public List<T> getGuides();
public void setGuides(List<T> guides);
}
class GuideCreatorListImpl implements GuideCreatorList<Guide> {
private List<Guide> guides;
public GuideCreatorListImpl() {
}
#Override
public List<Guide> getGuides() {
return guides;
}
#Override
public void setGuides(List<Guide> guides) {
this.guides = guides;
}
};
Here's the NPE:
java.lang.NullPointerException
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl.doEncode(AutoBeanCodexImpl.java:558)
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$ObjectCoder.encode(AutoBeanCodexImpl.java:321)
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$CollectionCoder.encode(AutoBeanCodexImpl.java:163)
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$PropertyGetter.encodeProperty(AutoBeanCodexImpl.java:413)
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$PropertyGetter.visitReferenceProperty(AutoBeanCodexImpl.java:389)
at com.google.web.bindery.autobean.shared.AutoBeanVisitor.visitCollectionProperty(AutoBeanVisitor.java:229)
at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean.java:300)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:166)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.accept(AbstractAutoBean.java:101)
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl.doEncode(AutoBeanCodexImpl.java:558)
at com.google.web.bindery.autobean.shared.AutoBeanCodex.encode(AutoBeanCodex.java:83)
at com.districthp.core.ui.client.review.JsonSerializationText.testMyObject(JsonSerializationText.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
This is unfortunately a known issue: https://github.com/gwtproject/gwt/issues/6903
The problem is that the items of the list are not wrapped into AutoBeans so AutoBeanUtils#getAutoBean in AutoBeanCodexImpl.ObjectCoder#encode returns null, hence the NPE in AutoBeanCodexImpl#doEncode.
The workaround involves replacing the list items with AutoBeans that wrap the actual value.