Said
6 years agoContributor
java.lang.NullPointerException when sorting project properties
I have 146 project properties that I would like to sort. I have found this post. I modified the code a bit to sort project properties. See below:
def obj = testRunner.testCase.testSuite.project log.info "Number of Properties: " + obj.getPropertyCount(); def propList = []; // Arraylist to store properties obj.getPropertyList().each { prop -> // For all Project (custom) properties propList.add(prop.name); // Add it to the arraylist } def sortedList = propList.sort(); // Sort the array list def index = 0 sortedList.each { name -> // Loop the sorted ArrayList log.info index + " - " + name + " - " + obj.getPropertyValue(name) obj.moveProperty(name, index); // Get Project (custom) property by name an move it to sorted position index++ }
I randomly get "java.lang.NullPointerException" when running the code at red statement above. I does however sort 4 to 10 properties before I get the error. So each time I re-run the code I get a bit further before I get error message. So I managed to get the properties sorted.
But why am I getting this error?
Thanks in advance!