Skip to content

[Bug]: size property access for List is incompatible with newer Groovy/Java versions (i.e Java 17) #483

@Neopixler

Description

@Neopixler

Plugin Name

artifactCleanup.groovy

Plugin Path?

cleanup/artifactCleanup/artifactCleanup.groovy

IsDeprecated

Yes

config/properties

{"policies":[{"cron":"0 0 6 * * ?","repos":["codesign_largefiles-generic-dev-local"],"timeUnit":"day","timeInterval":1,"dryRun":false,"paceTimeMS":500,"disablePropertiesSupport":true}]}

Artifactory Version?

7.98.14

Alternatives Explored

I fixed it locally, here the diff:

diff --git a/artifactCleanup.groovy b/artifactCleanup.groovy
index d91e81b..6dbd352 100644
--- a/artifactCleanup.groovy
+++ b/artifactCleanup.groovy
@@ -276,7 +276,7 @@ private def getSkippedPaths(String[] repos) {
         // Simplify list to have only parent paths
         def paths = []
         for (path in pathsTmp.sort{ it }) {
-            if (paths.size == 0 || ! path.startsWith(paths[-1])) {
+            if (paths.size() == 0 || ! path.startsWith(paths[-1])) {
                 if (log.isTraceEnabled()){
                     log.trace "skip added for " + repoKey + ":" + path
                 }
@@ -284,8 +284,8 @@ private def getSkippedPaths(String[] repos) {
             }
         }

-        if (paths.size > 0){
-            skip[repoKey] = paths.toArray(new String[paths.size])
+        if (paths.size() > 0){
+            skip[repoKey] = paths.toArray(new String[paths.size()])
         }
     }
     def timeStop = new Date()

Issue Summary

See following stack-trace:

2025-03-05T07:46:54.669Z [jfrt ] [INFO ] [4c75eb8c005255f3] [artifactCleanup:-2            ] [http-nio-8081-exec-5] - Removing all artifacts not downloaded since 2025/02/05 07:46
2025-03-05T07:46:54.685Z [jfrt ] [ERROR] [4c75eb8c005255f3] [c.e.m.GlobalExceptionMapper:51] [http-nio-8081-exec-5] - Exception evaluating property 'size' for java.util.ImmutableCollections$ListN, Reason: groovy.lang.MissingPropertyException: No such property: size for class: org.artifactory.model.common.RepoPathImpl
Possible solutions: file, id, name                                                                                 groovy.lang.MissingPropertyException: Exception evaluating property 'size' for java.util.ImmutableCollections$ListN, Reason: groovy.lang.MissingPropertyException: No such property: size for class: org.artifactory.model.common.RepoPathImpl                                                                                                           Possible solutions: file, id, name                                                                                         at org.codehaus.groovy.runtime.DefaultGroovyMethods.getAtIterable(DefaultGroovyMethods.java:8785)                  at org.codehaus.groovy.runtime.DefaultGroovyMethods.getAt(DefaultGroovyMethods.java:8773)                          at groovy.lang.MetaClassImpl$6.getProperty(MetaClassImpl.java:2051)                                                at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:63)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:329)
        at artifactCleanup$_artifactCleanup_closure4.doCall(artifactCleanup.groovy:207)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.base/java.lang.reflect.Method.invoke(Method.java:569)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:274)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1030)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:38)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at org.codehaus.groovy.runtime.callsite.BooleanReturningMethodInvoker.invoke(BooleanReturningMethodInvoker.java:49)
        at org.codehaus.groovy.runtime.callsite.BooleanClosureWrapper.call(BooleanClosureWrapper.java:52)
        at org.codehaus.groovy.runtime.DefaultGroovyMethods.find(DefaultGroovyMethods.java:4453)
        at org.codehaus.groovy.runtime.dgm$237.invoke(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:242)
        at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:51)                        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
        at artifactCleanup.artifactCleanup(artifactCleanup.groovy:181)                                                     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.base/java.lang.reflect.Method.invoke(Method.java:569)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)                                       at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:362)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1030)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:814)
        at groovy.lang.GroovyObject.invokeMethod(GroovyObject.java:39)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeOnDelegationObjects(ClosureMetaClass.java:424)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:350)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:61)
        at artifactCleanup$_run_closure1$_closure7.doCall(artifactCleanup.groovy:68)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.base/java.lang.reflect.Method.invoke(Method.java:569)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)                                       at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)                                                      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:274)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1030)                                                 at groovy.lang.Closure.call(Closure.java:427)
        at groovy.lang.Closure.call(Closure.java:416)

Can you fix it?

Yes

Expected Solution

No exceptions and proper cleanup with modern Java versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions