Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED JENKINS-34741] Allow new Class(foo: bar) to work. #114

Merged
merged 1 commit into from
Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -163,6 +164,18 @@ private static boolean isInstancePrimitive(@Nonnull Class<?> type, @Nonnull Obje
return c;
}
}

// Only check for the magic Map constructor if we haven't already found a real constructor.
// Also note that this logic is derived from how Groovy itself decides to use the magic Map constructor, at
// MetaClassImpl#invokeConstructor(Class, Object[]).
if (args.length == 1 && args[0] instanceof Map) {
for (Constructor<?> c : receiver.getDeclaredConstructors()) {
if (c.getParameterTypes().length == 0 && !c.isVarArgs()) {
return c;
}
}
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ public static final class Special {
assertRejected(new AnnotatedWhitelist(), "staticMethod " + clazz + " explode", "C.m(); class C {static void m() {" + clazz + ".explode();}}");
}

@Ignore("TODO RejectedAccessException: unclassified new C java.util.LinkedHashMap")
@Issue("JENKINS-34741")
@Test public void structConstructor() throws Exception {
assertEvaluate(new StaticWhitelist(), "ok", "class C {String f}; new C(f: 'ok').f");
Expand Down