More aggressive errors for Types.
A testcase for the bug optional-binding bug closed this evening.
git-svn-id: https://google-guice.googlecode.com/svn/trunk@503 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/src/com/google/inject/internal/Types.java b/src/com/google/inject/internal/Types.java
index 41f593d..e0d6af7 100644
--- a/src/com/google/inject/internal/Types.java
+++ b/src/com/google/inject/internal/Types.java
@@ -239,6 +239,11 @@
this.rawType = canonicalize(rawType);
this.typeArguments = typeArguments.clone();
for (int t = 0; t < this.typeArguments.length; t++) {
+ if (this.typeArguments[t] instanceof Class<?>
+ && ((Class) this.typeArguments[t]).isPrimitive()) {
+ throw new IllegalArgumentException(
+ "Parameterized types may not have primitive arguments: " + this.typeArguments[t]);
+ }
this.typeArguments[t] = canonicalize(this.typeArguments[t]);
}
}
diff --git a/test/com/google/inject/OptionalBindingTest.java b/test/com/google/inject/OptionalBindingTest.java
index 76d4bae..a8973fd 100644
--- a/test/com/google/inject/OptionalBindingTest.java
+++ b/test/com/google/inject/OptionalBindingTest.java
@@ -269,6 +269,20 @@
assertSame(staticInjectA, injectA);
}
+ /**
+ * Test for bug 107, where we weren't doing optional injection properly for
+ * indirect injections.
+ */
+ public void testIndirectOptionalInjection() {
+ Indirect indirect = Guice.createInjector().getInstance(Indirect.class);
+ assertNotNull(indirect.hasOptionalInjections);
+ indirect.hasOptionalInjections.assertNothingInjected();
+ }
+
+ static class Indirect {
+ @Inject HasOptionalInjections hasOptionalInjections;
+ }
+
interface A {}
interface B {}
interface C {}
diff --git a/test/com/google/inject/ScopesTest.java b/test/com/google/inject/ScopesTest.java
index 46313ae..064434e 100644
--- a/test/com/google/inject/ScopesTest.java
+++ b/test/com/google/inject/ScopesTest.java
@@ -64,7 +64,6 @@
injector.getInstance(LinkedSingleton.class),
injector.getInstance(LinkedSingleton.class));
-
assertSame(
injector.getInstance(JustInTimeSingleton.class),
injector.getInstance(JustInTimeSingleton.class));
diff --git a/test/com/google/inject/internal/TypesTest.java b/test/com/google/inject/internal/TypesTest.java
index 2e53a2e..3d89809 100644
--- a/test/com/google/inject/internal/TypesTest.java
+++ b/test/com/google/inject/internal/TypesTest.java
@@ -18,6 +18,7 @@
package com.google.inject.internal;
import static com.google.inject.Asserts.assertEqualsBothWays;
+import com.google.inject.Asserts;
import junit.framework.TestCase;
import java.lang.reflect.GenericArrayType;
@@ -66,6 +67,16 @@
assertEquals(innerFloatDouble.toString(), actual.toString());
}
+ public void testTypeParametersMustNotBePrimitives() {
+ try {
+ Types.newTypeWithArgument(Map.class, String.class, int.class);
+ fail();
+ } catch (IllegalArgumentException expected) {
+ Asserts.assertContains(expected.getMessage(),
+ "Parameterized types may not have primitive arguments: int");
+ }
+ }
+
public void testEqualsAndHashcode() {
ParameterizedType parameterizedType
= Types.newTypeWithArgument(Map.class, String.class, Integer.class);
@@ -89,5 +100,6 @@
Types.toString(innerFloatDouble));
}
+ @SuppressWarnings("UnusedDeclaration")
class Inner<T1, T2> {}
}