Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.NoClassDefFoundError occurs when accessing Profields

SWAPNIL SRIVASTAV
Contributor
June 22, 2020

I am trying to access the values of 2 Profields in Script Runner's Escalation Service groovy script. I tried the below code:

import java.text.DecimalFormat
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.workflow.TransitionOptions
import static com.atlassian.jira.workflow.TransitionOptions.Builder
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.Field
import com.deiser.jira.profields.api.value.ValueService
import com.deiser.jira.profields.api.field.text.TextField
import com.deiser.jira.profields.api.field.system.ProjectLeadField
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.deiser.jira.profields")

def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
def userSearchService = ComponentAccessor.getComponent(UserSearchService)
String esTotalDurValue
def counter = 0

def esTotalDur = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'ES Incident Total Duration in Hours'}
def esTotalDurVal = (Double)issue.getCustomFieldValue(esTotalDur)
if(esTotalDurVal.toString().indexOf('.') != -1)
esTotalDurValue = new DecimalFormat("##.###").format(esTotalDurVal)
else
esTotalDurValue = esTotalDurVal

if(esTotalDurVal > 6) {
String userAppname, userLeadName
def projectKey = issue.projectObject.key
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey(projectKey)

def appManId = 1;
Field appManager = fieldService.get(appManId);
def appManagerValue = valueService.getValue(project, (TextField) appManager).toString()

def lead= -5
Field proLead = fieldService.get(lead)
def proLeadValue = valueService.getValue(project, (ProjectLeadField) proLead).toString()
def userApp = userSearchService.findUsersByFullName(appManagerValue)

if (userApp && proLeadValue) {
String name= userApp.first()
userAppname = name.substring(0,name.indexOf('('))
userLeadName = proLeadValue.substring(0,proLeadValue.indexOf('('))
}

def comments = ComponentAccessor.getCommentManager().getComments(issue)
if (comments) {
def author = comments.authorFullName
log.error "authors list----" + author
for (def i=0; i < author.size(); i++) {
if(author[i] == "Srivastav Swapnil")
counter ++
}
}
log.error "Final value of counter ---" + counter
TransitionOptions skipPermissions = new Builder().skipPermissions().build()

if (counter == 0)
issueInputParameters.setComment("Some message....")
}

I tried it on the staging environment and it was working fine for at least 10 days and then suddenly it stopped working and I get the below error in logs:

Escalation Service (ES Incident Escalation Service) failed for issue TECOS-1422
java.lang.NoClassDefFoundError: com/deiser/jira/profields/api/value/ValueService
	at Script15.run(Script15.groovy:15)
	at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runScriptAndGetContext(ScriptRunnerImpl.groovy:177)
	at com.onresolve.scriptrunner.runner.ScriptRunner$runScriptAndGetContext$5.callCurrent(Unknown Source)
	at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runStringAsScript(ScriptRunnerImpl.groovy:166)
	at com.onresolve.scriptrunner.runner.ScriptRunner$runStringAsScript$4.call(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate.doScript(CustomScriptDelegate.groovy:70)
	at com.onresolve.scriptrunner.canned.jira.utils.AdditionalCustomScriptDelegate.super$2$doScript(AdditionalCustomScriptDelegate.groovy)
	at com.onresolve.scriptrunner.canned.jira.utils.AdditionalCustomScriptDelegate.doScript(AdditionalCustomScriptDelegate.groovy:22)
	at com.onresolve.scriptrunner.canned.jira.utils.AdditionalCustomScriptDelegate$doScript$1.call(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils.doAdditional(ConditionUtils.groovy:226)
	at com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils$doAdditional$0.call(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.utils.WorkflowUtils.updateIssue(WorkflowUtils.groovy:251)
	at com.onresolve.scriptrunner.canned.jira.utils.WorkflowUtils.updateIssue(WorkflowUtils.groovy)
	at com.onresolve.scriptrunner.canned.jira.utils.WorkflowUtils$updateIssue.call(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.admin.EscalationService$_runService_closure4.doCall(EscalationService.groovy:420)
	at com.onresolve.scriptrunner.canned.jira.admin.EscalationService.runService(EscalationService.groovy:386)
	at com.onresolve.scriptrunner.canned.jira.admin.EscalationService.execute(EscalationService.groovy:356)
	at com.onresolve.scriptrunner.canned.jira.admin.EscalationService$execute$0.callCurrent(Unknown Source)
	at com.onresolve.scriptrunner.canned.jira.admin.EscalationService.runJob(EscalationService.groovy:459)

 I think it might be because of the problem mentioned here:

https://productsupport.adaptavist.com/browse/SRPLAT-77

 

But as per above the issue was fixed in Script Runner version 5.4.30

I am trying this on version 5.4.49 and Profield version 6.9.1, so this problem should not occur. Could anyone please help me resolve this error.

 

@JamieA : Could you please help.

 

Thanks in advance

1 answer

0 votes
Fede Baronti -Deiser-
Community Champion
June 23, 2020

Hi  @SWAPNIL SRIVASTAV , 

I'm Fede Baronti from DEISER's Customer Support. 

As you see here: https://scriptrunner.adaptavist.com/4.3.5/jira/scripting-other-plugins.html   This is the way to use other plugins modules from ScriptRunner (@WithPlugin and @PluginModule):  

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule

@WithPlugin("com.deiser.jira.profields")
 
@PluginModule
ValueService valueService;

However, we think that this isn't your problem. 

Sometimes, we do experience this problem. It might be due to ScriptRunner losing or not be able to load the classloader for an external (3rd party) plugin. 

When this occurs to us, by disabling and re-enabling ScriptRunner the problem gets solved. 

Hope this helps. 

Cheers, 
Fede. 

SWAPNIL SRIVASTAV
Contributor
June 23, 2020

Hello @Fede Baronti -Deiser- ,

Thank you for the response.

I tried the workaround and it works. There is the other workaround mentioned in the ticket: https://productsupport.adaptavist.com/browse/SRPLAT-77  . If we edit the script and it gets recompiled then it works properly after that.

But is there something we can do to fix this problem? So that it does not occur in the first place.

Suggest an answer

Log in or Sign up to answer