error: cannot find symbol

Hello friends ,
Am working on TRUNK-4946 with four classes linked on this ticket which handles retiring any object that implements the Retireable interface example, BaseRetireHandler . To ensure we don’t write any other data when committing, I had to call the Context#refreshEntity() function mentioned in the ticket. Making the implementation of handle() in the BaseRetireHandler to appear like this:

@Override
public void handle(Retireable retireableObject, User retiringUser, Date retireDate, String retireReason) {

	// reload object from database if it has been saved before
	if (retireableObject.getId() != null) {
		Context.refreshEntity(retireableObject);
	}
	
	// skip over doing retire stuff if already retired
	if (!retireableObject.getRetired() || retireableObject.getRetiredBy() == null) {
		
		retireableObject.setRetired(true);
		retireableObject.setRetireReason(retireReason);
		
		if (retireableObject.getRetiredBy() == null) {
			retireableObject.setRetiredBy(retiringUser);
		}
		if (retireableObject.getDateRetired() == null) {
			retireableObject.setDateRetired(retireDate);
		}
		
	}
	
}

Then I added a unit test at the end of the class to verify the behavior: btu when I run mvn clean install after saving the changes, I run into this error https://pastebin.com/PwYEzRn5. I have tried different possible solutions but still running into the same output. I kindly request for help on how to solve this error.

1 Like

Just solve the error by: import org.openmrs.api.context.Context;

1 Like

Next time you can make a commit such that we can relate the line of code referenced in the stack trace to your code…

Thanks for the advice .

2 Likes

@jwnasambu what do you get when you run debug with “mvn clean install -X” .It look like [ERROR] \Users\JULIE\OpenMRS-Tickets\openmrs-core\api\src\main\java\org\openmrs\api\handler\BaseRetireHandler.java:[59,3] error: cannot find symbol

BaseRetireHandler.java is not being seen on the path.

Thanks so much for your prompt response. My error was caused by missing the import for Context which I solve by by adding import org.openmrs.api.context.Context; near the top of the class. Once again! am grateful for your response.

1 Like

Glad you did. :smile: :smile:

1 Like

just an add on,so many times when you are missing an import,you always get a red line around the code that requires the import.tested this with eclipse IDE

Hello friends, can someone help me understand the abnormality of this unit test build failure. Am working on this ticket which has four classes and each needs a unit test. I had successfully created unit tests for the first three classes BaseRetireHandler, BaseUnretireHandler and BaseVoidHandler but when I re-run mvn package -Dtest=BaseVoidHandlerTest#handle_shoudNotUpdateFieldBesidesVoidFields to reconfirm if the test for BaseVoidHandler class still works well, I got this error https://pastebin.com/ivWhDZL1 which prompted me to re-test the BaseUnretireHandler and the output was the same error log as this https://pastebin.com/ivWhDZL1. Today, without any changes made I attempted to test the BaseVoidHandler class again and the build is successful as you can see on this link https://pastebin.com/dVgQrMuv. I’m confused because I had spend two days searching for the solution to the error without any success but today without any changes made, its building. This is the link to my changes https://github.com/openmrs/openmrs-core/compare/master...jwnasambu:TRUNK-4946?expand=1. Kindly what is the trick? am scared of spending more days on this now that am working on my final class.