You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered a NullPointerException when using JavaBeanTester to test a POJO. The error occurs during the invocation of a method on a null object. Below is the full error message and steps to reproduce the issue.
Error Message:
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null
at java.base/java.lang.reflect.Method.invoke(Method.java:561)
at com.codebox.bean.JavaBeanTesterWorker.getterSetterTests(JavaBeanTesterWorker.java:219)
at com.codebox.bean.JavaBeanTesterWorker.test(JavaBeanTesterWorker.java:157)
at com.codebox.bean.JavaBeanTesterBuilder.test(JavaBeanTesterBuilder.java:204)
at org.giriraj.pojo.TruckTest.testTruck(TruckTest.java:16)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Steps to Reproduce:
1. Create a POJO class with Lombok annotations:
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class Truck {
String wheels;
String color;
String model;
String make;
}
2. Write a JUnit test class to test the POJO using JavaBeanTester:
import com.codebox.bean.JavaBeanTester;
import org.giriraj.pojo.Truck;
import org.junit.jupiter.api.Test;
public class TruckTest {
@Test
public void testTruckBean() {
JavaBeanTester.builder(Truck.class)
.checkEquals()
.checkConstructor()
.checkClear()
.loadData()
.test();
}
}
JUnit version: 5.10.0
Java version: 17
JavaBeanTester version: 2.8.3
The text was updated successfully, but these errors were encountered:
GirirajSinghRathore
changed the title
NullPointerException in JavaBeanTester: “Cannot invoke Object.getClass()” when testing POJO with SLF4J warning
NullPointerException in JavaBeanTester: “Cannot invoke Object.getClass()” when testing POJO
Oct 15, 2024
What is the delomboked code look like? As a pojo, it looks fine. Due to lombok usage, I don't know what its setting exactly. Would need to see that. If you write a unit test using that inside the project tests, I'm sure you can debug and figure it out and produced a pull request contribution. The tests are heavy on lombok and it works without issue in 1000s of projects I run it at work on latest between many jdks. So it has to do something with lombok there.
I encountered a NullPointerException when using JavaBeanTester to test a POJO. The error occurs during the invocation of a method on a null object. Below is the full error message and steps to reproduce the issue.
Error Message:
Steps to Reproduce:
The text was updated successfully, but these errors were encountered: