Skip to content

Commit

Permalink
GROOVY-10378: coerce iterable to array or collection
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 16, 2024
1 parent b3142a3 commit d54ca19
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ private static Object continueCastOnCollection(final Object object, final Class
return answer;
}

if (object instanceof BaseStream || object instanceof Optional) {
if (object instanceof BaseStream // GROOVY-10028
|| object instanceof Optional // GROOVY-10223
|| (object instanceof Iterable // GROOVY-11378
&& !(object instanceof Collection))) { // GROOVY-7867
Collection answer = newCollection.get();
answer.addAll(asCollection(object));
return answer;
Expand Down Expand Up @@ -479,6 +482,8 @@ public static Collection asCollection(final Object value) {
return StreamGroovyMethods.toList((BaseStream) value);
} else if (value instanceof String || value instanceof GString) {
return StringGroovyMethods.toList((CharSequence) value);
} else if (value instanceof Iterable) { // GROOVY-10378
return DefaultGroovyMethods.toList((Iterable<?>) value);
} else if (value instanceof Optional) { // GROOVY-10223
return ((Optional<?>) value).map(Collections::singleton).orElseGet(Collections::emptySet);
} else if (value instanceof Class && ((Class) value).isEnum()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,33 @@ final class DefaultTypeTransformationTest {
assert result[1] == 1
}

@Test // GROOVY-10223
@Test // GROOVY-11378
void testCastToType5() {
def input = new org.codehaus.groovy.util.ArrayIterable<Integer>(0,1), result

result = DefaultTypeTransformation.castToType(input, Number[])
assert result instanceof Number[]
assert result[0] == 0
assert result[1] == 1

result = DefaultTypeTransformation.castToType(input, int[])
assert result instanceof int[]
assert result[0] == 0
assert result[1] == 1

result = DefaultTypeTransformation.castToType(input, List)
assert result instanceof List
assert result[0] == 0
assert result[1] == 1

result = DefaultTypeTransformation.castToType(input, Set)
assert result instanceof Set
assert result[0] == 0
assert result[1] == 1
}

@Test // GROOVY-10223
void testCastToType6() {
def err = shouldFail GroovyCastException, {
DefaultTypeTransformation.castToType(Optional.of('123'), Number[])
}
Expand Down

2 comments on commit d54ca19

@daniellansun
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io.micronaut.http.client.jdk.SslSpec > bad server ssl cert bad server ssl cert [url: https://revoked.badssl.com/, #4] FAILED (1.2s)

  org.gradle.internal.exceptions.DefaultMultiCauseException: Multiple Failures (6 failures)
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
      at app//org.spockframework.runtime.ErrorInfoCollector.assertEmpty(ErrorInfoCollector.java:32)
      at app//org.spockframework.runtime.IterationNode.execute(IterationNode.java:51)
      at app//org.spockframework.runtime.IterationNode.execute(IterationNode.java:13)
      at app//org.spockframework.runtime.SpockNode.sneakyInvoke(SpockNode.java:40)
      at app//org.spockframework.runtime.IterationNode.lambda$around$0(IterationNode.java:67)
      at app//org.spockframework.runtime.PlatformSpecRunner.lambda$createMethodInfoForDoRunIteration$5(PlatformSpecRunner.java:236)
      at app//org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:156)
      at app//org.spockframework.runtime.PlatformSpecRunner.invokeRaw(PlatformSpecRunner.java:407)
      at app//org.spockframework.runtime.PlatformSpecRunner.invoke(PlatformSpecRunner.java:390)
      at app//org.spockframework.runtime.PlatformSpecRunner.runIteration(PlatformSpecRunner.java:218)
      at app//org.spockframework.runtime.IterationNode.around(IterationNode.java:67)
      at app//org.spockframework.runtime.IterationNode.around(IterationNode.java:13)
      at app//org.spockframework.runtime.ParameterizedFeatureChildExecutor.execute(ParameterizedFeatureChildExecutor.java:104)
      at app//org.spockframework.runtime.PlatformParameterizedSpecRunner$1.runIteration(PlatformParameterizedSpecRunner.java:72)
      at app//org.spockframework.runtime.extension.IDataDriver.lambda$static$0(IDataDriver.java:37)
      at app//org.spockframework.runtime.PlatformParameterizedSpecRunner.runParameterizedFeature(PlatformParameterizedSpecRunner.java:47)
      at app//org.spockframework.runtime.ParameterizedFeatureNode.execute(ParameterizedFeatureNode.java:40)
      at app//org.spockframework.runtime.ParameterizedFeatureNode.execute(ParameterizedFeatureNode.java:16)
      at app//org.spockframework.runtime.SpockNode.sneakyInvoke(SpockNode.java:40)
      at app//org.spockframework.runtime.FeatureNode.lambda$around$0(FeatureNode.java:41)
      at app//org.spockframework.runtime.PlatformSpecRunner.lambda$createMethodInfoForDoRunFeature$4(PlatformSpecRunner.java:199)
      at app//org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:156)
      at app//org.spockframework.runtime.PlatformSpecRunner.invokeRaw(PlatformSpecRunner.java:407)
      at app//org.spockframework.runtime.PlatformSpecRunner.invoke(PlatformSpecRunner.java:390)
      at app//org.spockframework.runtime.PlatformSpecRunner.runFeature(PlatformSpecRunner.java:192)
      at app//org.spockframework.runtime.FeatureNode.around(FeatureNode.java:41)
      at app//org.spockframework.runtime.FeatureNode.around(FeatureNode.java:12)
      at java.base@17.0.11/java.util.ArrayList.forEach(ArrayList.java:1511)
      at app//org.spockframework.runtime.SpockNode.sneakyInvoke(SpockNode.java:40)
      at app//org.spockframework.runtime.SpecNode.lambda$around$0(SpecNode.java:63)
      at app//org.spockframework.runtime.PlatformSpecRunner.lambda$createMethodInfoForDoRunSpec$0(PlatformSpecRunner.java:61)
      at app//org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:156)
      at app//org.spockframework.runtime.PlatformSpecRunner.invokeRaw(PlatformSpecRunner.java:407)
      at app//org.spockframework.runtime.PlatformSpecRunner.invoke(PlatformSpecRunner.java:390)
      at app//org.spockframework.runtime.PlatformSpecRunner.runSpec(PlatformSpecRunner.java:55)
      at app//org.spockframework.runtime.SpecNode.around(SpecNode.java:63)
      at app//org.spockframework.runtime.SpecNode.around(SpecNode.java:11)
      at java.base@17.0.11/java.util.ArrayList.forEach(ArrayList.java:1511)
  Caused by: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
      at app//org.spockframework.lang.SpecInternals.checkExceptionThrown(SpecInternals.java:84)
      at app//org.spockframework.lang.SpecInternals.thrownImpl(SpecInternals.java:71)
      at io.micronaut.http.client.jdk.SslSpec.bad server ssl cert(SslSpec.groovy:29)

@daniellansun
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Micronaut joint validation build relies on outside site, succeeded before, bu when we rerun the build, fails this time...

Please sign in to comment.