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

@Nullable not transferred correctly to generics #1293

Open
xenoterracide opened this issue Apr 28, 2021 · 3 comments
Open

@Nullable not transferred correctly to generics #1293

xenoterracide opened this issue Apr 28, 2021 · 3 comments

Comments

@xenoterracide
Copy link

I have this class

package com.xenoterracide.brix.configloader.api;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Value;

import java.nio.file.Path;
import java.util.Map;

@Value.Immutable
public abstract class ProcessedFileConfiguration {

  public abstract Map<String, @Nullable Object> getContext();

  public abstract @Nullable Boolean getOverwrite();

  public abstract @Nullable Path getSource();

  public abstract Path getDestination();

  @Override
  public String toString() {
    return ToStringBuilder.reflectionToString( this, ToStringStyle.MULTI_LINE_STYLE );
  }
}

but this (etc) is being generated

  /**
   * @return The value of the {@code context} attribute
   */
  @Override
  public Map<String, Object> getContext() {
    return context;
  }
  
      /**
     * Put one entry to the {@link ProcessedFileConfiguration#getContext() context} map.
     * @param key The key in the context map
     * @param value The associated value in the context map
     * @return {@code this} builder for use in a chained invocation
     */
    public final Builder putContext(String key, Object value) {
      if (this.context == null) {
        this.context = new LinkedHashMap<String, Object>();
      }
      this.context.put(key, value);
      return this;
    }

    public final Builder context(Map<String, ? extends Object> entries) {
      if (entries == null) {
        this.context = null;
        return this;
      }
      this.context = new LinkedHashMap<String, Object>();
      return putAllContext(entries);
    }

which results in checker having compile errors because the intent is for values to be nullables but but the generated object only takes non nullables.

@elucash
Copy link
Member

elucash commented May 9, 2021

As discussed recently in another issue (#1288), there are some difficult problems with type level annotations on type arguments. @AllowNulls/@SkipNulls (from any package) on a collection might produce some signatures with nullable args in theory.

@xenoterracide
Copy link
Author

I told the code to include the type level annotations so that error prone or checker framework can properly do its job...

you can close this through if you want, I'm removing immutables, it's far too painful to work with. I spend more time trying to figure out how to make it do what I want due to an unintuitive API (could be fixed with a v3) that defaults to arguably incorrect behavior, than writing productive code. With this, it appears I can't actually make use of the compile time safety features I want. Well, that's not entirely true, I could go about treating the generated code as a 3rd party library, but that's just annoying to write even more code for that when I feel like this should just work.

@xenoterracide
Copy link
Author

out of curiosity, did this ever get fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants