Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Static type checking error - No such property: value for class: java.lang.object Edited

I have got this little piece of code and can't get rid of the above error. The script runs all right. But the error message is irritating. Any help is welcome.

 

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import org.apache.log4j.Logger

def customFieldManager = ComponentAccessor.customFieldManager

def bvField = customFieldManager.getCustomFieldObjectsByName("WSJF-Business Value")[0]
def bvValue = issue.getCustomFieldValue(bvField)?.value as Long ?: 0L

def tcField = customFieldManager.getCustomFieldObjectsByName("WSJF-Kundennutzen")[0]
def tcValue = issue.getCustomFieldValue(tcField)?.value as Long ?: 0L

def rrField = customFieldManager.getCustomFieldObjectsByName("WSJF-Dringlichkeit")[0]
def rrValue = issue.getCustomFieldValue(rrField)?.value as Long ?: 0L

def jsField = customFieldManager.getCustomFieldObjectsByName("WSJF-Komplexität")[0]
def jsValue = issue.getCustomFieldValue(jsField)?.value as Long ?: 1L

def wsjf = (rrValue + bvValue + tcValue) / jsValue

def wsjfRounded = Math.round(wsjf * 100) / 100

return wsjfRounded

2 answers

0 votes

This error is really more of a warning about code than it is an error.  I think of it as saying "Oi, developer, your code here allows room for errors that may halt your code, and I, as a dumb compiler, can't understand whether it might or might not"

One reason we need warnings like this is the use of weakly typed languages like groovy over strongly typed ones like Java, and this is what you're running into in this case.

So, somewhere before the line which is showing you the warning, you are creating a variable that will contain an object.

On the line where you're using that variable, the function you are using needs to be given objects of a very specific type.  But when you give it a weakly typed variable, the compiler can not be sure that the input is going to be of the right type.

My guess would be the calculations in your script - arithmetic functions like +, -, / and * obviously expect numbers.  But, the compiler does not know that the value it gets back from "getCustomFieldValue" is going to be a number!  getCustomFieldValue might return a date object, a string, a (jira) option or a couple of other things.

So, you can get rid of the warning by using strict typing - instead of "def jsValue = getcustomfield value" use "long jsValue = getcustomfieldvalue" - that will fix the compiler warning, BUT it also assumes that your customfields are going to contain the right type of data, and your script will fail horribly if they're not (rather than moderately gracefully if you stick with "def")

0 votes

Nic is 100% correct of course.

And I used to not care so much ... but there are places where it becomes annoying to get all those static errors and it's nice to make them go away and it's very satisfying to get that green dot under your script.

So in your case, since you call ?.value on your custom field value, I'll assume that all your fields are based on some form of option (single select for example).

Fields that store values as options are returned as instances of LazyLoadedOption when you can getCustomFieldValue(). And the label of that option is accessed with getValue() or .value.

If that's not the case and those fields are number or text fields, then remove the ?.value and see if that works.

But otherwise, this version of your script is static-type-checking-error-free for me (not tested since I don't actually have those fields):

import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import org.apache.log4j.Logger

def customFieldManager = ComponentAccessor.customFieldManager

def bvField = customFieldManager.getCustomFieldObjectsByName("WSJF-Business Value")[0]
def bvValue = (issue.getCustomFieldValue(bvField) as LazyLoadedOption)?.value as Long ?: 0L

def tcField = customFieldManager.getCustomFieldObjectsByName("WSJF-Kundennutzen")[0]
def tcValue = (issue.getCustomFieldValue(tcField) as LazyLoadedOption)?.value as Long ?: 0L

def rrField = customFieldManager.getCustomFieldObjectsByName("WSJF-Dringlichkeit")[0]
def rrValue = (issue.getCustomFieldValue(rrField)as LazyLoadedOption)?.value as Long ?: 0L

def jsField = customFieldManager.getCustomFieldObjectsByName("WSJF-Komplexität")[0]
def jsValue = (issue.getCustomFieldValue(jsField)as LazyLoadedOption)?.value as Long ?: 1L

def wsjf = ((rrValue + bvValue + tcValue) / jsValue) as Double

def wsjfRounded = Math.round(wsjf * 100) / 100

return wsjfRounded

Yep, those red dots always make my codey-sense tingle.  Even when I know it's fine and it's always going to work, and my coding is a long way off the best in the world, there's a satisfaction in delivering a script without any :-)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

246 views 7 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you