I think your problem is related with the lack of a @Component annotation in your BoardDao class. The component should have a @Component annotation to instantiate the singleton to be injected in your Service Layer.

@Component
public class BoardDao extends SqlSessionDaoSupport{

    @Autowired
    SqlSessionTemplate session;

    public List<BoardDto> listboard(BoardDto dto) {
        System.out.println("dao.");
        List<BoardDto> result = session.selectList("boarddate.listboard", dto);
        return result;
    }

}

If the problem persist, you may try with the @Repository annotation. Sadly I haven't used the class SqlSessionDaoSupport, so I don't know exactly the best annotation for that.

Answer from Oscar Navarrete on Stack Overflow
🌐
OneUptime
oneuptime.com › home › blog › how to handle 'cannot invoke method on null' errors
How to Handle 'Cannot invoke method on null' Errors
December 22, 2025 - It occurs when you try to call a method or access a property on a null reference. This guide covers how to prevent, find, and fix these errors. java.lang.NullPointerException: Cannot invoke "String.length()" because "str" is null at ...
Discussions

java - Spring Boot Unit test gives error: Cannot invoke "" because "this.taskService" is null - Stack Overflow
I'm trying to unit test my service class and the repository. I want to test whether the code will correctly create and read the data. I mock the repo but when I run the test it just says: java.lang. More on stackoverflow.com
🌐 stackoverflow.com
Spring Boot Test cannot give a clear message but throw NPE now when @SpringBootConfiguration cannot be found
When we try spring boot test without @SpringBootConfiguration,NPE exception will occur. Before supporting AOT,it throws IllegalStateException with message: Unable to find a @SpringBootConfiguration, you need to use " + "@ContextConfigura... More on github.com
🌐 github.com
1
November 26, 2022
Cannot invoke "java.lang.Class.isInterface()" because "typeToRead" is null
There was an error while loading. Please reload this page · When using Spring data JPA projection, the application is failing to start with the following error: More on github.com
🌐 github.com
1
January 22, 2022
spring boot - java.lang.NullPointerException: Cannot invoke because the return value of is null - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
🌐
OneUptime
oneuptime.com › home › blog › how to fix 'cannot invoke tostring() on null' errors
How to Fix 'Cannot invoke toString() on null' Errors
December 22, 2025 - NullPointerExceptions account for a significant portion of runtime errors in Java applications. Understanding why they occur and how to prevent them is essential for building robust applications. flowchart TD A[Method Call] --> B{Is Object Null?} B -->|No| C[Execute Method] B -->|Yes| D[NullPointerException] D --> E["Cannot invoke toString() because X is null"] subgraph Common Causes F[Uninitialized Variables] G[Missing Database Records] H[Null API Responses] I[Missing Config Values] end
🌐
GitHub
github.com › spring-projects › spring-boot › issues › 33370
Spring Boot Test cannot give a clear message but throw NPE now when @SpringBootConfiguration cannot be found · Issue #33370 · spring-projects/spring-boot
November 26, 2022 - When we try spring boot test without @SpringBootConfiguration,NPE exception will occur. Before supporting AOT,it throws IllegalStateException with message: Unable to find a @SpringBootConfiguration, you need to use " + "@ContextConfiguration or @SpringBootTest(classes=...) with your test ... java.lang.NullPointerException: Cannot invoke "java.lang.Class.getName()" because "found" is null at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.findConfigurationClass(SpringBootTestContextBootstrapper.java:261)
Author: spring-projects
🌐
GitHub
github.com › spring-projects › spring-boot › issues › 29531
Cannot invoke "java.lang.Class.isInterface()" because "typeToRead" is null · Issue #29531 · spring-projects/spring-boot
January 22, 2022 - When using Spring data JPA projection, the application is failing to start with the following error: Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Class.isInterface()" because "typeToRead" is null at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:181) ~[spring-data-jpa-2.6.1.jar:2.6.1] at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:152) ~[spring-data-jpa-2.6.1.jar:2.6.1] at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:59) ~[spring-dat
Author: spring-projects
Find elsewhere
Top answer
1 of 5
4

You're probably missing the @repository annotation on top of your repository class.

Another unrelated word of advice:

In your controller you use findAll and filter in java to keep only the ids. Then you go to the same repository and perform another query per user-id from above. This is a causing you to create multiple database calls which are one of the most expensive operations you can do, when you already have all your data from the first single query...

Also if you're only looking at the bottom part of the function you don't event need a query per each user-id (when you have a list of user ids as input), you can create a query that uses the 'in' convention and pass a list of user-ids to create a single db call.

2 of 5
1

First of all I would get rid of @Autowired ICustomerRepository customerRepository; in UserList class. It doesn't belong there. The counting of linked customers should be executed in ICustomerRepository and the result to be passed into UserList via the constructor.

e.g.

public class UserList {

    private  String id;
    private String email;
    private String userType;
    private String rolls;
    private String partner;
    private Long customersLinked; //better use Long instead of Integer
    private String position;
    private String status;


    // constructor takes the number of linked customers as parameter
    public UserList (Users user, Long customersLinked ) { 
        this.id = user.getId();
        this.email = user.getEmail();
        this.userType = user.getUserType();
        this.rolls = user.getRolls();
        this.partner = user.getPartner();
        this.customersLinked = customersLinked;
        this.position = user.getPosition();
        this.status =user.getStatus();
    }

    //Getter and Setter
}

and then create the count query in ICustomerRepository

e.g.

public interface ICustomerRepository extends MongoRepository<Customer, String> {
    //other methods

    Long countByLinkedUsersIn(String id); //not so sure if this query works in mongo
}

and finally in your controller

Optional<Users> user = this.usersRepository.findById(userId);
Long count = this.usersRepository.countByLinkedUsersIn(userId);
userList.add(new UserList(user.get(), count));

P.S. I have a doubt for the query method: Long countByLinkedUsersIn(String id);. Usually when repository methods have "In" in their names, countByLinkedUsersIn, then it is expected as parameter a List and not a single user id. However if your previous method List<Customer> findAllByLinkedUsersIn(String id); worked for you, then this one should work too.

Top answer
1 of 2
5

The solution is simple. You mocked a class customerDataRepository but did not instruct it the mock what to do if the corresponding method is called. Mockito mocks then default back on doing nothing by method call and if there is a return value return null. Since your returned customerData is null you get your NPE when calling on this object. In your case this is in the error case that you get by calling getCustomerId().

To solve this issue simply instruct your mock

@Test
void removeCustomerDataWhenConsentIsNotGiven() {
   CustomerData customerDataTest = customerData;
   //when
   Mockito.when(customerDataRepository.findCustomerByDialogId(Mockito.any())).thenReturn(new CustomerData()); // <-- Add this line
   customerDataService.giveConsent(false,22L);
   //then 
   verify(customerDataRepository,times(1)).save(customerDataTest);
}

you can obviously replace Mockito.any() with Mockito.anyInt() or 42 and new CustomerData() with a object you previously created. I think you get the idea ;)

2 of 2
1

Assuming that you have just corrected method names before posting it to Stackoverflow, and method you are calling in the test: giveConsent is, actually, the same method as methodTotest of the CustomerDataService.

Before calling customerDataService.giveConsent(false,22L);, you need to configure you repository to return some test (not null! or mocked) customerData entity:

when(customerDataRepository.findCustomerByDialogId(22L)).thenReturn(customerDataTest);
customerDataService.giveConsent(false,22L);

Note: since you are passing false as 1st variable, you will get to this branch of code

    if (!consent) {  
      customerDataRepository.deleteById(customer.getCustomerId());
    }

And in the test you are expecting save() method to be called, so the test will fail.

🌐
GitHub
github.com › spring-projects › spring-kafka › issues › 2914
Spring Boot 3.2.0 > java.lang.NullPointerException: Cannot invoke "kafka.raft.KafkaRaftManager.apiVersions()" because the return value of "kafka.server.SharedServer.raftManager()" is null · Issue #2914 · spring-projects/spring-kafka
November 24, 2023 - When I upgraded to Spring Boot 3.2.0, it throws the following Exception: java.lang.NullPointerException: Cannot invoke "kafka.raft.KafkaRaftManager.apiVersions()" because the return value of "kafka.server.SharedServer.raftManager()" is null
Author: spring-projects
🌐
Reddit
reddit.com › r/springboot › could not write json: cannot invoke "java.lang.integer.intvalue()" because attribute is null
r/SpringBoot on Reddit: Could not write JSON: Cannot invoke "java.lang.Integer.intValue()" because attribute is null
October 6, 2024 -

I am new to spring boot and I am wondering how to allow a response JSON to include null values for database columns that are nullable. This is my controller, service, repository and model:

package com.findersgame.questtracker.controller;

import java.util.List;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.findersgame.questtracker.model.MapArea;
import com.findersgame.questtracker.service.MapAreaService;

@RestController
public class MapAreaController {

    private MapAreaService mapAreaService;

    public MapAreaController(MapAreaService mapAreaService) {
        super();
        this.mapAreaService = mapAreaService;
    }
    
    @PostMapping("selected_map_areas")
    public List<MapArea> selectedMapAreas(@RequestBody List<Integer> selectedMapAreas) {
        return mapAreaService.selectedMapAreas(selectedMapAreas);
    }
}


package com.findersgame.questtracker.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.findersgame.questtracker.model.MapArea;
import com.findersgame.questtracker.repository.MapAreaRepository;

@Service
public class MapAreaService {
    
    private MapAreaRepository mapAreaRepository;
    
    public MapAreaService(MapAreaRepository mapAreaRepository) {
        super();
        this.mapAreaRepository = mapAreaRepository;
    }
    
    public List<MapArea> selectedMapAreas(List<Integer> selectedIds) {
        return mapAreaRepository.findAllById(selectedIds);
    }
}

package com.findersgame.questtracker.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.findersgame.questtracker.model.MapArea;

public interface MapAreaRepository extends JpaRepository<MapArea, Integer> {

}

package com.findersgame.questtracker.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "map_areas")
public class MapArea {
    
    @Id
    private Integer id;
    
    @Column
    private Integer mapTabId;

    @Column
    private String name;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    
    public Integer getMapTabId() {
        return mapTabId;
    }

    public void setMapTabId(Integer mapTabId) {
        this.mapTabId = mapTabId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

My problem is that when I call http://localhost:8080/selected_map_areas with body [14, 15, 16] I get the following error.

Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Cannot invoke "java.lang.Integer.intValue()" because "this.mapTabId" is null]

I guess it makes sense because in the database, the map_tab_id value is null for both id 15 and 16. I'm guessing that I'm missing an annotation in one of the classes/interfaces above but I have not been able to find which one.

Note that it works fine and I get the correct result in Postman when `map_tab_id` has a value.

Please help.

🌐
Stack Overflow
stackoverflow.com › questions › 71448503 › spring-boot-cant-invoke-service-because-service-is-null-exception
nullpointerexception - Spring boot can't invoke Service because Service is null exception - Stack Overflow
This is Exception: enter code herejava.lang.NullPointerException: Cannot invoke "com.company.MedicalManagement.repository.DoctorRepository.findById(Object)" because "this.doctorRepository" is null
🌐
Coderanch
coderanch.com › t › 740840 › frameworks › Spring-Data-JPA-Invoke-Data
Spring Data JPA: Cannot Invoke Data Transfer Object Because it's null (Spring forum at Coderanch)
Reference: https://www.baeldung.com/spring-data-jpa-query Because the name is not descriptive, it's not a list but a simple POJO. @Bryan, are you sure this user exists in the database? Because if it doesn't, then you'll definitely get a null from the repository.
🌐
Reddit
reddit.com › r/javahelp › spring: nullpointerexception trying to access findall() @repository
r/javahelp on Reddit: Spring: NullPointerException trying to access findAll() @Repository
February 23, 2022 -

java.lang.NullPointerException: Cannot invoke "com.example.demo.student.StudentRepository.findAll()" because "this.studentRepository" is null

I do have a @Repository annotated above my StudentRepository class. I also used @Autorwired above the constructor in my StudentService class. I think the problem is with dependency injection but I don't see why.

Related code:

//StudentRepository.java
package com.example.demo.student;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface StudentRepository extends JpaRepository<Student, Long> {
}

//StudentService.java
package com.example.demo.student;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.Month;
import java.util.List;

@Service
public class StudentService {

    private final StudentRepository studentRepository;

    @Autowired
    public StudentService(StudentRepository studentRepository) {
        this.studentRepository = studentRepository;
    }

    public List<Student> getStudents() {
        return studentRepository.findAll();
    }
}

//StudentController.java
package com.example.demo.student;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(path = "api/v1/student")
public class StudentController {

    private final StudentService studentService;

    @Autowired
    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }

    @GetMapping
    public List<Student> getStudents(StudentService studentService) {
        return studentService.getStudents();
    }
}
🌐
Reddit
reddit.com › r/javahelp › repositorys returning nullpointerexception when calling jparepository save
r/javahelp on Reddit: Repositorys returning NullPointerException when calling JpaRepository save
December 9, 2023 -

I'm pretty new at Java and was trying to do a CRUD, the process was going pretty smoothly until i had to make the create function to the table with a composite key.

At first i thought the problem was with the Dependecy Injection, but it's working just fine in the methods getByStateAndModelId() and getAll().I also tried to set the names for the EquipmentModel and EquipmentState in the createEmshe (In the POST i just insert the Id of both State and Models, and the Value, so the names from Model and State coming from the DTO are null and i thought that maybe that was the cause). But then, both the equipmentModelRepository and the equipmentStateRepository returned the NullPointerException too, what i'm missing?here's the relevant code:

The service:

package com.api.forestoperation.emshe;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.api.forestoperation.equipmentmodel.EquipmentModelModel;
import com.api.forestoperation.equipmentmodel.EquipmentModelRepository;
import com.api.forestoperation.equipmentstate.EquipmentStateModel;
import com.api.forestoperation.equipmentstate.EquipmentStateRepository;

@Service
public class EquipmentModelStateHourlyEarningsService {
	@Autowired
	EquipmentModelStateHourlyEarningsRepository emsheRepository;
	@Autowired
	EquipmentModelRepository equipmentModelRepository;
	@Autowired
	EquipmentStateRepository equipmentStateRepository;

	public List<EquipmentModelStateHourlyEarningsModel> getAllEmshe() {
		return emsheRepository.findAll();
	}

	public EquipmentModelStateHourlyEarningsModel createEmshe(EquipmentModelStateHourlyEarningsDTO emsheDTO) {
		var emsheModel = new EquipmentModelStateHourlyEarningsModel();

		BeanUtils.copyProperties(emsheDTO, emsheModel);

		EquipmentModelModel emsheModelInfo = emsheModel.getId().getEquipmentModel();
		EquipmentStateModel emsheStateInfo = emsheModel.getId().getEquipmentState();
		EquipmentModelStateHourlyEarningsPK emshePk = new EquipmentModelStateHourlyEarningsPK(emsheModelInfo,
				emsheStateInfo);

		emsheModel.setId(emshePk);

		return emsheRepository.save(emsheModel);
	}

	public EquipmentModelStateHourlyEarningsModel getEmsheByStateAndModelId(UUID modelId, UUID stateId) {
		var modelExists = equipmentModelRepository.findById(modelId).orElse(null);
		var stateExists = equipmentStateRepository.findById(stateId).orElse(null);
		if (modelExists != null && stateExists != null) {
			EquipmentModelStateHourlyEarningsPK emshePk = new EquipmentModelStateHourlyEarningsPK(modelExists,
					stateExists);
			EquipmentModelStateHourlyEarningsModel emsheModel = emsheRepository.findById(emshePk).orElse(null);
			return emsheModel;
		}
		return null;
	}
}

The Controller:

package com.api.forestoperation.emshe;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EquipmentModelStateHourlyEarningsController {
	@Autowired
	EquipmentModelStateHourlyEarningsService emsheService;

	@PostMapping("/equipment-model-state-hourly-earnings")
	public ResponseEntity<Object> saveEmshe(@RequestBody EquipmentModelStateHourlyEarningsDTO emsheDTO) {
		var savedEmshe = new EquipmentModelStateHourlyEarningsService().createEmshe(emsheDTO);
		return savedEmshe != null
				? ResponseEntity.status(HttpStatus.CREATED)
						.body("EquipmentModelStateHourlyEarnings created with Sucess")
				: ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
	}

	@GetMapping("/equipment-model-state-hourly-earnings")
	public ResponseEntity<List<EquipmentModelStateHourlyEarningsModel>> getAllEmshe() {
		List<EquipmentModelStateHourlyEarningsModel> equipments = emsheService.getAllEmshe();
		return ResponseEntity.status(HttpStatus.OK).body(equipments);
	}

	@GetMapping("/equipment-model-state-hourly-earnings/{modelId}/{stateId}")
	public ResponseEntity<Object> getEmsheByModelAndStateId(@PathVariable(value = "modelId") UUID modelId,
			@PathVariable(value = "stateId") UUID stateId, EquipmentModelStateHourlyEarningsPK emshePk) {
		EquipmentModelStateHourlyEarningsModel emsheModel = emsheService.getEmsheByStateAndModelId(modelId, stateId);
		return emsheModel == null ? ResponseEntity.status(HttpStatus.BAD_REQUEST).body("EMSHE nulo")
				: ResponseEntity.status(HttpStatus.OK).body(emsheModel);

	}
}

The Repository:

	package com.api.forestoperation.equipment;

import java.util.UUID;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface EquipmentRepository extends JpaRepository<EquipmentModel, UUID> {

}

The Model:

	package com.api.forestoperation.emshe;

import java.io.Serializable;

import com.api.forestoperation.equipmentmodel.EquipmentModelModel;
import com.api.forestoperation.equipmentstate.EquipmentStateModel;

import jakarta.persistence.Column;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;

@Entity
@Table(name="equipment_model_state_hourly_earnings", schema="operation")
public class EquipmentModelStateHourlyEarningsModel implements Serializable {
	@EmbeddedId
	private EquipmentModelStateHourlyEarningsPK id;
	private static final long serialVersionUID = 1L;
	
	@Column(name="value")
	private double value;
	
	public EquipmentModelStateHourlyEarningsPK getId() {
		return id;
	}

	public void setId(EquipmentModelStateHourlyEarningsPK id) {
		this.id = id;
	}

	public double getValue() {
		return value;
	}

	public void setValue(double value) {
		this.value = value;
	}
	
	
	public EquipmentModelModel getEquipmentModel() {
		return id.getEquipmentModel();
	}
	
	public EquipmentStateModel getEquipmentState() {
		return id.getEquipmentState();
	}

}

The Pk:

package com.api.forestoperation.emshe;

import java.io.Serializable;
import java.util.Objects;

import com.api.forestoperation.equipmentmodel.EquipmentModelModel;
import com.api.forestoperation.equipmentstate.EquipmentStateModel;

import jakarta.persistence.Embeddable;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;

@Embeddable
public class EquipmentModelStateHourlyEarningsPK implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@ManyToOne
	@JoinColumn(name = "equipment_model_id")
	private EquipmentModelModel equipmentModel;

	@ManyToOne
	@JoinColumn(name = "equipment_state_id")
	private EquipmentStateModel equipmentState;

	public EquipmentModelStateHourlyEarningsPK() {

	}

	public EquipmentModelStateHourlyEarningsPK(EquipmentModelModel equipmentModelModel,
			EquipmentStateModel equipmentStateModel) {
		this.equipmentModel = equipmentModelModel;
		this.equipmentState = equipmentStateModel;
	}

	@Override
	public int hashCode() {
		return Objects.hash(equipmentModel, equipmentState);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EquipmentModelStateHourlyEarningsPK other = (EquipmentModelStateHourlyEarningsPK) obj;
		return Objects.equals(equipmentModel, other.equipmentModel)
				&& Objects.equals(equipmentState, other.equipmentState);
	}

	public EquipmentModelModel getEquipmentModel() {
		return equipmentModel;
	}

	public void setEquipmentModel(EquipmentModelModel equipmentModel) {
		this.equipmentModel = equipmentModel;
	}

	public EquipmentStateModel getEquipmentState() {
		return equipmentState;
	}

	public void setEquipmentState(EquipmentStateModel equipmentState) {
		this.equipmentState = equipmentState;
	}
}

Here's the error i get:

java.lang.NullPointerException: Cannot invoke     "com.api.forestoperation.emshe.EquipmentModelStateHourlyEarningsRepository.save(Object)" because "this.emsheRepository" is null
at com.api.forestoperation.emshe.EquipmentModelStateHourlyEarningsService.createEmshe(EquipmentModelStateHourlyEarningsService.java:39) ~[classes/:na]
at com.api.forestoperation.emshe.EquipmentModelStateHourlyEarningsController.saveEmshe(EquipmentModelStateHourlyEarningsController.java:22) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-6.0.13.jar:6.0.13]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-6.0.13.jar:6.0.13]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118) ~[spring-webmvc-6.0.13.jar:6.0.13]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:884) ~[spring-webmvc-6.0.13.jar:6.0.13]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-6.0.13.jar:6.0.13]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-6.0.13.jar:6.0.13]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1081) ~[spring-webmvc-6.0.13.jar:6.0.13]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:974) ~[spring-webmvc-6.0.13.jar:6.0.13]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1011) ~[spring-webmvc-6.0.13.jar:6.0.13]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:914) ~[spring-webmvc-6.0.13.jar:6.0.13]
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590) ~[tomcat-embed-core-10.1.15.jar:6.0]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) ~[spring-webmvc-6.0.13.jar:6.0.13]
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) ~[tomcat-embed-core-10.1.15.jar:6.0]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) ~[tomcat-embed-websocket-10.1.15.jar:10.1.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-6.0.13.jar:6.0.13]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.13.jar:6.0.13]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-6.0.13.jar:6.0.13]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.13.jar:6.0.13]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-6.0.13.jar:6.0.13]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.13.jar:6.0.13]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:340) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-10.1.15.jar:10.1.15]
at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]

Top answer
1 of 4
4
Your EquipmentModelStateHourlyEarningsRepository isn't being injected into your EquipmentModelStateHourlyEarningsService. You would have to provide your spring configuration for us to troubleshoot it properly (or even better provide full source of project). You should really be using constructors instead of putting `@Autowired` on the fields. If you use the constructor then your application will fail fast at startup instead.
2 of 4
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
GitHub
github.com › spring-projects › spring-boot › issues › 28794
because "this.condition" is null · Issue #28794 · spring-projects/spring-boot
November 24, 2021 - 2021-11-24 10:45:19,845 ERROR [restartedMain] o.s.boot.SpringApplication [SpringApplication.java : 819] Application run failed org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) at org.springframework.context.support.DefaultLifecycleProcessor
Author: spring-projects
🌐
GitHub
github.com › spring-projects › spring-data-jpa › issues › 3086
NullPointerException when using "IS NULL" on an enum parameter in a query · Issue #3086 · spring-projects/spring-data-jpa
July 26, 2023 - I created a proof of concept repository to demonstrate the error: https://github.com/clemens-ruettermann-viadee/poc_spring_jpa_enum The code is working with Spring Boot 2.7.14 but not with 3.1.2 (or 3.0.0 for that matter). Note that this problem only occurs, when the enum value of the parameter is not null. ... java.lang.NullPointerException: Cannot invoke "org.hibernate.metamodel.mapping.JdbcMapping.getJdbcValueBinder()" because "jdbcMapping" is null at org.hibernate.sql.exec.internal.AbstractJdbcParameter.bindParameterValue(AbstractJdbcParameter.java:108) at org.hibernate.sql.exec.internal.A
Author: spring-projects
🌐
Coderanch
coderanch.com › t › 773642 › databases › NullPointerException-invoke-java-lang-Integer
NullPointerException Cannot invoke java.lang.Integer.intValue() (Object Relational Mapping forum at Coderanch)
I've a controller defined like this and getting a NullPointerException Cannot invoke "java.lang.Integer.intValue()" because "this.id" is null (some stack trace shown in the end - had to shorten it as it was exceeding 10k character limit) while processing the form using Hibernate.