Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,603
Community Members
 
Community Events
176
Community Groups

JQL Function throws exception in scriptrunner. Please help spotting the issue.

After writing the following JQL function (my very first attempt) following the examples on https://scriptrunner.adaptavist.com/latest/jira/custom-jql-functions.html

and doing further reading here: https://developer.atlassian.com/server/jira/platform/jql-function/

Once I put the file (class is the same name as the file btw) under com.reslove.jira.groovy.jql and click scan, page gets wiped out from the built in jql functions that com built in the scriptrunner. IOW, it stops working properly. 

Also when i navigate to the issue navigator in jira to search for issues, the page doesn't load at all.

it happens only when i add my file with the code below. when i add one of the jql functions in the scriptrunner wiki examples above, scan works fine and everything works as expected.

Looks like my code has definitely something wrong that causes compilation to error out

here is the code:

package com.onresolve.jira.groovy.jql

import com.atlassian.fugue.Option
import com.atlassian.jira.JiraDataType
import com.atlassian.jira.JiraDataTypes
import com.atlassian.jira.bc.user.property.DefaultUserPropertyService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.entity.property.EntityProperty
import com.atlassian.jira.entity.property.EntityPropertyService
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.MessageSet
import com.atlassian.jira.jql.validator.NumberOfArgumentsValidator
import groovy.json.JsonSlurper
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.user.search.UserSearchParams
import groovy.util.logging.Log4j

@Log4j
class EmpolyeeInType extends AbstractScriptedJqlFunction implements JqlFunction {

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def userPropertyService = ComponentAccessor.getComponent(DefaultUserPropertyService.class)
def userSearchService = ComponentAccessor.getComponent(UserSearchService.class)
def userSearchParams = (new UserSearchParams.Builder()).allowEmptyQuery(true).includeActive(true).includeInactive(false).maxResults(100000).build()

@Override
String getDescription() {
"Query Assignees by employee type"
}


@Override
String getFunctionName() {
"employeeType"
}

@Override
JiraDataType getDataType() {
JiraDataTypes.USER
}

@Override
MessageSet validate(ApplicationUser user, FunctionOperand operand, TerminalClause terminalClause) {
def messageSet = new NumberOfArgumentsValidator(1, 1, getI18n()).validate(operand)

if (messageSet.hasAnyErrors()) {
return messageSet
}

def employeeType = operand.getArgs().get(0)
if (!employeeType.toString().equalsIgnoreCase("A") ||
!employeeType.toString().equalsIgnoreCase("B") ||
!employeeType.toString().equalsIgnoreCase("C")) {
messageSet.addErrorMessage(getI18n().getText("expected A or B or C"))
return messageSet
}
}

@Override
List<Map> getArguments() {
[
[
description: "Employee Type to look for",
optional: false,
]
]
}


@Override
List<QueryLiteral> getValues(
QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {
def empType = operand.args.get(0)
userSearchService.findUsers("", userSearchParams).findAll{
EntityPropertyService.PropertyResult propertyValues = userPropertyService.getProperty(user, it.key, empType)//THIS SHOULD CONTAIN MY PROPERTIES
Option<EntityProperty> jsonValues = propertyValues.getEntityProperty()
def value1 = jsonValues.getOrNull()
def x = new JsonSlurper().parseText(value1.value)
x.value.equalsIgnoreCase(empType)
}.collect{
new QueryLiteral(operand, it.id)
}

}
}








 And here is the exception thrown:



2018-02-23 02:34:36,119 http-nio-8080-exec-1 WARN xxxx@xxxx.xxx 154x123380x1 jqx0c3 184.175.21.22,127.0.0.1 /rest/scriptrunner-jira/latest/jqlfunctions/scan [c.a.jira.plugin.AbstractJiraModuleDescriptor] Unable to instantiate module class: class com.onresolve.jira.groovy.jql.ScriptedJqlFunction
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor9168.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.atlassian.jira.plugin.AbstractJiraModuleDescriptor$GhettoInitter.maybeInit(AbstractJiraModuleDescriptor.java:289)
at com.atlassian.jira.plugin.AbstractJiraModuleDescriptor.createModule(AbstractJiraModuleDescriptor.java:183)
at com.atlassian.jira.plugin.AbstractJiraModuleDescriptor$1.create(AbstractJiraModuleDescriptor.java:60)
at com.atlassian.util.concurrent.ResettableLazyReference$InternalReference.create(ResettableLazyReference.java:182)
at com.atlassian.util.concurrent.LazyReference$Sync.run(LazyReference.java:325)
at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:143)
at com.atlassian.util.concurrent.LazyReference.get(LazyReference.java:112)
at com.atlassian.util.concurrent.ResettableLazyReference.get(ResettableLazyReference.java:92)
at com.atlassian.jira.plugin.AbstractJiraModuleDescriptor.getModule(AbstractJiraModuleDescriptor.java:167)
at com.atlassian.jira.jql.operand.registry.LazyResettableJqlFunctionHandlerRegistry.loadFromJqlFunctionModuleDescriptors(LazyResettableJqlFunctionHandlerRegistry.java:74)
at com.atlassian.jira.jql.operand.registry.LazyResettableJqlFunctionHandlerRegistry$1.create(LazyResettableJqlFunctionHandlerRegistry.java:52)
at com.atlassian.jira.jql.operand.registry.LazyResettableJqlFunctionHandlerRegistry$1.create(LazyResettableJqlFunctionHandlerRegistry.java:49)
at com.atlassian.util.concurrent.ResettableLazyReference$InternalReference.create(ResettableLazyReference.java:182)
at com.atlassian.util.concurrent.LazyReference$Sync.run(LazyReference.java:325)
at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:143)
at com.atlassian.util.concurrent.LazyReference.get(LazyReference.java:112)
at com.atlassian.util.concurrent.ResettableLazyReference.get(ResettableLazyReference.java:92)
at com.atlassian.util.concurrent.Supplier$get.call(Unknown Source)
at com.onresolve.scriptrunner.runner.JqlFunctionsManagerImpl.getScriptedFunctions(JqlFunctionsManagerImpl.groovy:167)
at com.onresolve.scriptrunner.runner.rest.jira.JqlFunctionsEndpoint.rescanScriptFunctions(JqlFunctionsEndpoint.groovy:47)
... 3 filtered
at java.lang.reflect.Method.invoke(Method.java:498)
... 19 filtered
at com.atlassian.plugins.rest.module.RestDelegatingServletFilter$JerseyOsgiServletContainer.doFilter(RestDelegatingServletFilter.java:154)
... 1 filtered
at com.atlassian.plugins.rest.module.RestDelegatingServletFilter.doFilter(RestDelegatingServletFilter.java:68)
... 32 filtered
at com.atlassian.servicedesk.internal.web.ExternalCustomerLockoutFilter.doFilter(ExternalCustomerLockoutFilter.java:56)
... 13 filtered
at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21)
... 53 filtered
at com.atlassian.jira.security.JiraSecurityFilter.lambda$doFilter$0(JiraSecurityFilter.java:66)
... 1 filtered
at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:64)
... 16 filtered
at com.atlassian.plugins.rest.module.servlet.RestSeraphFilter.doFilter(RestSeraphFilter.java:37)
... 19 filtered
at com.atlassian.jira.servermetrics.CorrelationIdPopulatorFilter.doFilter(CorrelationIdPopulatorFilter.java:30)
... 5 filtered
at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.lambda$invokeFilterChain$0(CustomerContextSettingFilter.java:181)
at com.atlassian.servicedesk.internal.api.util.context.ReentrantThreadLocalBasedCodeContext.rteInvoke(ReentrantThreadLocalBasedCodeContext.java:137)
at com.atlassian.servicedesk.internal.api.util.context.ReentrantThreadLocalBasedCodeContext.runOutOfContext(ReentrantThreadLocalBasedCodeContext.java:90)
at com.atlassian.servicedesk.internal.utils.context.CustomerContextServiceImpl.runOutOfCustomerContext(CustomerContextServiceImpl.java:47)
at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.outOfCustomerContext(CustomerContextSettingFilter.java:174)
at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilterImpl(CustomerContextSettingFilter.java:130)
at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilter(CustomerContextSettingFilter.java:121)
... 4 filtered
at com.atlassian.jwt.internal.servlet.JwtAuthFilter.doFilter(JwtAuthFilter.java:32)
... 8 filtered
at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21)
... 4 filtered
at com.atlassian.web.servlet.plugin.LocationCleanerFilter.doFilter(LocationCleanerFilter.java:36)
... 26 filtered
at com.atlassian.jira.servermetrics.MetricsCollectorFilter.doFilter(MetricsCollectorFilter.java:25)
... 23 filtered
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Cannot invoke method toURI() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.loadScriptByName(ScriptRunnerImpl.groovy:664)
at com.onresolve.scriptrunner.runner.ScriptRunner$loadScriptByName$6.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at com.onresolve.scriptrunner.runner.ScriptRunner$loadScriptByName$6.call(Unknown Source)
at com.onresolve.jira.groovy.jql.ScriptedJqlFunction.init(ScriptedJqlFunction.groovy:77)
... 274 more
2018-02-23 02:34:36,123 http-nio-8080-exec-1 ERROR xxxxx@xxxx.xxx 154x123380x1 jqx0c3 184.175.21.22,127.0.0.1 /rest/scriptrunner-jira/latest/jqlfunctions/scan [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
com.atlassian.util.concurrent.LazyReference$InitializationException: com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:149)
at com.atlassian.util.concurrent.LazyReference.get(LazyReference.java:112)
at com.atlassian.util.concurrent.ResettableLazyReference.get(ResettableLazyReference.java:92)
at com.atlassian.util.concurrent.Supplier$get.call(Unknown Source)
at com.onresolve.scriptrunner.runner.JqlFunctionsManagerImpl.getScriptedFunctions(JqlFunctionsManagerImpl.groovy:167)
at com.onresolve.scriptrunner.runner.rest.jira.JqlFunctionsEndpoint.rescanScriptFunctions(JqlFunctionsEndpoint.groovy:47)
... 3 filtered
at java.lang.reflect.Method.invoke(Method.java:498)
... 19 filtered
at com.atlassian.plugins.rest.module.RestDelegatingServletFilter$JerseyOsgiServletContainer.doFilter(RestDelegatingServletFilter.java:154)
... 1 filtered
at com.atlassian.plugins.rest.module.RestDelegatingServletFilter.doFilter(RestDelegatingServletFilter.java:68)
... 32 filtered
at com.atlassian.servicedesk.internal.web.ExternalCustomerLockoutFilter.doFilter(ExternalCustomerLockoutFilter.java:56)
... 13 filtered
at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21)
... 53 filtered
at com.atlassian.jira.security.JiraSecurityFilter.lambda$doFilter$0(JiraSecurityFilter.java:66)
... 1 filtered
at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:64)
... 16 filtered
at com.atlassian.plugins.rest.module.servlet.RestSeraphFilter.doFilter(RestSeraphFilter.java:37)
... 19 filtered
at com.atlassian.jira.servermetrics.CorrelationIdPopulatorFilter.doFilter(CorrelationIdPopulatorFilter.java:30)
... 5 filtered
at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.lambda$invokeFilterChain$0(CustomerContextSettingFilter.java:181)
at com.atlassian.servicedesk.internal.api.util.context.ReentrantThreadLocalBasedCodeContext.rteInvoke(ReentrantThreadLocalBasedCodeContext.java:137)
at com.atlassian.servicedesk.internal.api.util.context.ReentrantThreadLocalBasedCodeContext.runOutOfContext(ReentrantThreadLocalBasedCodeContext.java:90)
at com.atlassian.servicedesk.internal.utils.context.CustomerContextServiceImpl.runOutOfCustomerContext(CustomerContextServiceImpl.java:47)
at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.outOfCustomerContext(CustomerContextSettingFilter.java:174)
at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilterImpl(CustomerContextSettingFilter.java:130)
at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilter(CustomerContextSettingFilter.java:121)
... 4 filtered
at com.atlassian.jwt.internal.servlet.JwtAuthFilter.doFilter(JwtAuthFilter.java:32)
... 8 filtered
at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21)
... 4 filtered
at com.atlassian.web.servlet.plugin.LocationCleanerFilter.doFilter(LocationCleanerFilter.java:36)
... 26 filtered
at com.atlassian.jira.servermetrics.MetricsCollectorFilter.doFilter(MetricsCollectorFilter.java:25)
... 23 filtered
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:149)
at com.atlassian.util.concurrent.LazyReference.get(LazyReference.java:112)
at com.atlassian.util.concurrent.ResettableLazyReference.get(ResettableLazyReference.java:92)
at com.atlassian.jira.plugin.AbstractJiraModuleDescriptor.getModule(AbstractJiraModuleDescriptor.java:167)
at com.atlassian.jira.jql.operand.registry.LazyResettableJqlFunctionHandlerRegistry.loadFromJqlFunctionModuleDescriptors(LazyResettableJqlFunctionHandlerRegistry.java:74)
at com.atlassian.jira.jql.operand.registry.LazyResettableJqlFunctionHandlerRegistry$1.create(LazyResettableJqlFunctionHandlerRegistry.java:49)
at com.atlassian.util.concurrent.ResettableLazyReference$InternalReference.create(ResettableLazyReference.java:182)
at com.atlassian.util.concurrent.LazyReference$Sync.run(LazyReference.java:325)
at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:143)
... 256 more
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.atlassian.jira.plugin.AbstractJiraModuleDescriptor$GhettoInitter.maybeInit(AbstractJiraModuleDescriptor.java:295)
at com.atlassian.jira.plugin.AbstractJiraModuleDescriptor.createModule(AbstractJiraModuleDescriptor.java:183)
at com.atlassian.jira.plugin.AbstractJiraModuleDescriptor$1.create(AbstractJiraModuleDescriptor.java:60)
at com.atlassian.util.concurrent.ResettableLazyReference$InternalReference.create(ResettableLazyReference.java:182)
at com.atlassian.util.concurrent.LazyReference$Sync.run(LazyReference.java:325)
... 265 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor9168.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.atlassian.jira.plugin.AbstractJiraModuleDescriptor$GhettoInitter.maybeInit(AbstractJiraModuleDescriptor.java:289)
... 270 more
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at java_net_URL$toURI$1.call(Unknown Source)
at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.loadScriptByName(ScriptRunnerImpl.groovy:664)
at com.onresolve.scriptrunner.runner.ScriptRunner$loadScriptByName$6.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at com.onresolve.scriptrunner.runner.ScriptRunner$loadScriptByName$6.call(Unknown Source)
at com.onresolve.jira.groovy.jql.ScriptedJqlFunction.init(ScriptedJqlFunction.groovy:77)
... 274 more

 

1 answer

1 accepted

0 votes
Answer accepted

Found the problem. NVM this question. thanks

I would be very interested to know what the problem was. I am getting the same error and can't find the cause.

So I found more examples here and copied some of them in my dev server and started playing with them and understanding what each function does via trial and error and eventually mine started running after some adjustments. IIRC, I was missing : 

@Override
JiraDataType getDataType() {
JiraDataTypes.User
}

 You will get to see what is the problem with yours once you play with those examples.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events