Re: Google Guice problem - Specified cast is not valid. - Type <=> Class conversion problem?

Martin Gerhardy <[email protected]> Wed, 8 Feb 2017 11:07:48 +0000
Newsgroups gmane.comp.java.ikvm.devel
Message-ID <0598D786697B0A42AAEE9344938160534069B9F1@srv024038.bigpoint.local>
Hi

This method is the cause of all evil. I wasn't able to create a minimal failure case.

  public static <T> TypeLiteral<T> canonicalizeForKey(TypeLiteral<T> typeLiteral) {
    Type type = typeLiteral.getType();
    if (!isFullySpecified(type)) {
      Errors errors = new Errors().keyNotFullySpecified(typeLiteral);
      throw new ConfigurationException(errors.getMessages());
    }

    if (typeLiteral.getRawType() == javax.inject.Provider.class) {
      ParameterizedType parameterizedType = (ParameterizedType) type;

      // the following casts are generally unsafe, but com.google.inject.Provider extends
      // javax.inject.Provider and is covariant
      @SuppressWarnings("unchecked")
      TypeLiteral<T> guiceProviderType = (TypeLiteral<T>) TypeLiteral.get(
          Types.providerOf(parameterizedType.getActualTypeArguments()[0]));
      return guiceProviderType;
    }

Line 104 is this cast:

ParameterizedType parameterizedType = (ParameterizedType) type;

I've read in the changelog that there were particular guice test cases executed and some bugs were fixed in a previous release of ikvm. Can someone please tell me how to run the tests locally on my own? I would like to validate whether a newer guice version broke something else or whether the test cases are just not complete.

Thanks a lot
Regards
Martin

________________________________________
Von: Martin Gerhardy
Gesendet: Freitag, 3. Februar 2017 15:12
An: [email protected]
Betreff: Google Guice problem - Specified cast is not valid. - Type <=> Class conversion problem?

Hi,

still fighting with guice - now whenever I configure a factory builder like this.

-----------------------------
java
------------------------------

public interface UserFactory {
        User create(@Assisted UserId id);
}

public interface User {
        UserId getId();
}


-----------------------------
csharp code using ikvm converted java classes from above given code
------------------------------

public class BasicUser : User {
}

public class MyModule : AbstractModule {
        protected void configure() {
                install(new FactoryModuleBuilder().implement(typeof(User), typeof(BasicUser)).build(typeof(UserFactory)));
        }
}

-------------------------------

I get


INFORMATION: An exception was caught and reported. Message: java.lang.ClassCastException: Specified cast is not valid.
java.lang.ClassCastException: Specified cast is not valid.
        at com.google.inject.internal.MoreTypes.canonicalizeForKey(MoreTypes.java:104)
        at com.google.inject.Key.<init>(Key.java:137)
        at com.google.inject.Key.get(Key.java:277)
        at com.google.inject.internal.Annotations.getKey(Annotations.java:283)
        at com.google.inject.assistedinject.FactoryProvider2.constructorHasMatchingParams(FactoryProvider2.java:552)
        at com.google.inject.assistedinject.FactoryProvider2.findMatchingConstructorInjectionPoint(FactoryProvider2.java:496)
        at com.google.inject.assistedinject.FactoryProvider2.<init>(FactoryProvider2.java:292)
        at com.google.inject.assistedinject.FactoryModuleBuilder$1.configure(FactoryModuleBuilder.java:334)
        at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
        at com.google.inject.AbstractModule.install(AbstractModule.java:122)

Is that just a feature that doesn't work? Looks like all the other binds are working properly for now - just not the factory builder.

Regards
Martin

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot