Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Nov 16, 2021

While testing the new JavaTypeSystem on AndroidX, the api-diff was reporting various constructors had been removed:

Xamarin.Android.Glide.dll

Type Changed: Bumptech.Glide.Registry.NoModelLoaderAvailableException

Removed constructor:

public Registry.NoModelLoaderAvailableException (Java.Lang.Object model, System.Collections.IList matchingButNotHandlingModelLoaders);

Investigating let to realizing Java constructors can have generic type parameters:

  public static class NoModelLoaderAvailableException extends MissingComponentException {

    public <M> NoModelLoaderAvailableException(
        @NonNull M model, @NonNull List<ModelLoader<M, ?>> matchingButNotHandlingModelLoaders) {
      super(
          "Found ModelLoaders for model class: "
              + matchingButNotHandlingModelLoaders
              + ", but none that handle this specific model instance: "
              + model);
    }

(source)

class-parse correctly emits these constructor generic types:

     <constructor
        deprecated="not deprecated"
        final="false"
        name="Registry.NoModelLoaderAvailableException"
        static="false"
        visibility="public"
        bridge="false"
        synthetic="false"
        jni-signature="(Ljava/lang/Object;Ljava/util/List;)V">
        <typeParameters>
          <typeParameter
            name="M"
            jni-classBound="Ljava/lang/Object;"
            classBound="java.lang.Object"
            interfaceBounds=""
            jni-interfaceBounds="" />
        </typeParameters>
        <parameter
          name="model"
          type="M"
          jni-type="TM;"
          not-null="true" />
        <parameter
          name="matchingButNotHandlingModelLoaders"
          type="java.util.List&lt;com.bumptech.glide.load.model.ModelLoader&lt;M, ?&gt;&gt;"
          jni-type="Ljava/util/List&lt;Lcom/bumptech/glide/load/model/ModelLoader&lt;TM;*&gt;;&gt;;"
          not-null="true" />
      </constructor>

We need to import this information in JavaTypeSystem so that the type parameters can be resolved. Without them, the constructor is omitted because the type M cannot be resolved.

The constructor 'Constructor: com.bumptech.glide.Registry.NoModelLoaderAvailableException.Registry
.NoModelLoaderAvailableException' was removed because the Java parameter type 'M' could not be found.

Tested against AndroidX and this change restores the constructors.

@jpobst jpobst marked this pull request as ready for review November 18, 2021 15:18
@jonpryor jonpryor merged commit a8b444d into main Nov 23, 2021
@jonpryor jonpryor deleted the generic-ctors branch November 23, 2021 18:21
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants