Today I found something looks like a bug in Ivy Script.

In Ivy Script, I want to have a List of all the elements of an enum, say WorkflowPriority, I simply call WorkflowPriority.values(). However, the instance of List returned by the call doesn't work correctly, especially with operation contains and remove.

Here are the tests that I made to check:

(This is an Ivy Script snippet)

import org.junit.Assert;
import com.genzerhawherk.bugs.Lists;
import ch.ivyteam.ivy.workflow.WorkflowPriority;

// Below are all failed tests
Assert.assertTrue(WorkflowPriority.values().contains(WorkflowPriority.HIGH));

List<WorkflowPriority> withGenerics = WorkflowPriority.values();
Assert.assertTrue(withGenerics.contains(WorkflowPriority.HIGH));

List fromEnums = Lists.fromEnums(WorkflowPriority.class);
Assert.assertTrue(fromEnums.contains(WorkflowPriority.HIGH));

List fromEnumVarargs = Lists.enumVarArgs(WorkflowPriority.HIGH, WorkflowPriority.EXCEPTION);
Assert.assertTrue(fromEnumVarargs.contains(WorkflowPriority.HIGH));

// Below are all passed tests
List listComprehensive = [WorkflowPriority.HIGH];
Assert.assertTrue(listComprehensive.contains(WorkflowPriority.HIGH));

List newPriorities = new List().addAll(WorkflowPriority.values());
Assert.assertTrue(newPriorities.contains(WorkflowPriority.HIGH));

List fromList = Lists.toArray([WorkflowPriority.HIGH]);
Assert.assertTrue(fromList.contains(WorkflowPriority.HIGH));

List fromVarArgs = Lists.normalVarArgs(WorkflowPriority.HIGH);
Assert.assertTrue(fromVarArgs.contains(WorkflowPriority.HIGH));

List<WorkflowPriority> manuallyConstructed = new List<WorkflowPriority>();
manuallyConstructed.add(WorkflowPriority.HIGH);
Assert.assertTrue(manuallyConstructed.contains(WorkflowPriority.HIGH));

The bug particularly relates to converting <T extends Enum<T>> T[] into a List<T>

Below is the class Lists I use in the test

public class Lists {

    public static Object[] toArray(Collection<?> collection) {
        return collection.toArray();
    }

    @SafeVarargs
    public static <T> T[] normalVarArgs(T...elements) {
        return Arrays.copyOf(elements, elements.length);
    }

    public static <T extends Enum<T>> T[] fromEnums(Class<T> enums) {
        return enums.getEnumConstants();
    }

    @SafeVarargs
    public static <T extends Enum<T>> T[] enumVarArgs(T...enums) {
        return enums;
    }
}

asked 12.03.2015 at 08:27

Genzer%20Hawker's gravatar image

Genzer Hawker
481222636
accept rate: 66%

edited 12.03.2015 at 08:30


Yes, you are right. This is a bug in the ivyScript List that wraps an Array of Objects.

I created an issue (#25528) for this. We will provide a fix with one of the next versions. Thanks for reporting!

link

answered 19.05.2015 at 15:57

Dominik%20Regli's gravatar image

Dominik Regli ♦
9013518
accept rate: 85%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×33
×5
×3
×1

Asked: 12.03.2015 at 08:27

Seen: 1,207 times

Last updated: 19.05.2015 at 15:57