java.lang.NoSuchMethodError: 'java.util.Collection com.atlassian.jira.util.collect.CollectionUtil.filter

I am getting below error… in Jira 10. Can anyone please help me with this. I am using Java 17.

java.lang.NoSuchMethodError: 'java.util.Collection com.atlassian.jira.util.collect.CollectionUtil.filter(java.util.Collection, com.atlassian.jira.util.Predicate)'
	at com.thed.zephyr.je.attachment.ZTemporaryAttachmentsMonitor.getByEntityId(ZTemporaryAttachmentsMonitor.java:58) [?:?]

Below is the code where the error is coming…

public Collection<TemporaryAttachment> getByEntityId(final Long entityId)
    {
        final ArrayList<TemporaryAttachment> ret = new ArrayList<TemporaryAttachment>();
        
        Iterable<TemporaryAttachment> values = CollectionUtil.filter(temporaryAttachments.values(), new Predicate<TemporaryAttachment>()
        {
            @Override
			public boolean evaluate(final TemporaryAttachment input)
            {
                return entityId == null && input.getEntityId() == null || (entityId != null && entityId.equals(input.getEntityId()));
            }
        });
        for(TemporaryAttachment item: values) {
        	ret.add(item);
        }
        Collections.sort(ret);
        return ret;
    }

I’d suggest to just rewrite it as:

public Collection<TemporaryAttachment> getByEntityId(final Long entityId) {
   return temporaryAttachments.values()
      .stream()
      .filter(input -> entityId == null && input.getEntityId() == null || (entityId != null && entityId.equals(input.getEntityId())))
      .sorted()
      .collect(Collectors.toList())
}

(I didn’t write it in an IDE nor I tried running it, there may be some extra parenthesis or some minor mistake to fix, exercise left to the reader :smile:)

1 Like

Thank you so much @PaoloCampanelli ,
It worked

1 Like