jfrog / artifactory-client-java

Artifactory REST Client Java API bindings
Apache License 2.0
319 stars 153 forks source link

Move results in IndexOutOfBounds Exception #333

Open HendrikHoetker opened 2 years ago

HendrikHoetker commented 2 years ago

I am using the Artifactory Client API in my java application:

@Override public boolean rename(String oldPath, String newPath) {
    try {
        artifactory.repository(repository).file(oldPath).move(repository, newPath);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    return isFile(newPath);
}

I am sure I am logged in correctly via username/password as other functions work properly

The file to be renamed is a simple text file (32bytes) which is confirmed to exists and is a valid file. Renaming the same file via Web User Interface with same name works fine.

Resulting exception:

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248) at java.base/java.util.Objects.checkIndex(Objects.java:372) at java.base/java.util.ArrayList.get(ArrayList.java:459) at java_util_List$get.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128) at org.jfrog.artifactory.client.impl.ItemHandleImpl.moveOrCopy(ItemHandleImpl.groovy:153) at org.jfrog.artifactory.client.impl.ItemHandleImpl.move(ItemHandleImpl.groovy:133)

eyalbe4 commented 2 years ago

Thanks for reporting this @HendrikHoetker. Since artifactory-client-java uses the underlying REST API of Artifactory, it's worth checking if the REST API works properly for you. If the issue is with the artifactory-client-java code, we'd gladly accept a pull request with the fix.

jonesbusy commented 8 months ago

Hi,

I just go the same issue.

My code is as simple as

ItemHandle sourceItem = artifactory.repository(config.getRepository()).folder(sourcePath);
sourceItem.move(config.getRepository(), targetPath);

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
...
at org.jfrog.artifactory.client.impl.ItemHandleImpl.moveOrCopy(ItemHandleImpl.groovy:153)
at org.jfrog.artifactory.client.impl.ItemHandleImpl.move(ItemHandleImpl.groovy:133)
...
jonesbusy commented 8 months ago

This fail because of this check (https://github.com/jfrog/artifactory-client-java/blob/e39db33c2d8b87134bac115ae43a1408ee1964b6/services/src/main/groovy/org/jfrog/artifactory/client/impl/ItemHandleImpl.groovy#L153C1-L155C10)

        if (!message.getMessages().get(0).getLevel().contains('INFO')) {
            throw new CopyMoveException(message)
        }

Looks message.getMessages() is empty for some reason.

I would like to submit a patch to check check that the messages are notEmpty before checking the first element