Giter Club home page Giter Club logo

Comments (10)

mattnworb avatar mattnworb commented on August 28, 2024

Confirmed that this is fixed in #1141 (if merged):

        35: invokevirtual #733                // Method com/spotify/docker/client/messages/NetworkSettings.ports:()Lcom/spotify/docker/client/shaded/com/google/common/collect/ImmutableMap;
        38: invokevirtual #739                // Method com/spotify/docker/client/shaded/com/google/common/collect/ImmutableMap.entrySet:()Lcom/spotify/docker/client/shaded/com/google/common/collect/ImmutableSet;
        41: invokevirtual #744                // Method com/spotify/docker/client/shaded/com/google/common/collect/ImmutableSet.iterator:()Lcom/spotify/docker/client/shaded/com/google/common/collect/UnmodifiableIterator;

from helios.

davidxia avatar davidxia commented on August 28, 2024

On the other hand, upgrading docker-client so that the NetworkSettings.ports() method does not return a type from the com.google.common.collect package should also fix this.

We can return the built in Collection types, but AutoValue docs recommend returning the Immutable types. See https://github.com/google/auto/blob/master/value/userguide/howto.md#mutable_property

from helios.

mattnworb avatar mattnworb commented on August 28, 2024

I think they mean that as a general principle and not something directly related to using auto-value.

I started on a branch to reduce our usage of Guava in the public API of docker-client, but it might break a lot of methods on classes in the 'messages' package that use the immutable Builders or offer varargs setters.

from helios.

davidxia avatar davidxia commented on August 28, 2024

Can I close this issue since the original problem is now fixed?

I think they mean that as a general principle and not something directly related to using auto-value.

Are you sure? The example they give here has ImmutableList as the return type of the getter.

@AutoValue
public abstract class ListExample {
  public static ListExample create(String[] mutableNames) {
    return new AutoValue_ListExample(ImmutableList.copyOf(mutableNames));
  }

  public abstract ImmutableList<String> names();
}

from helios.

mattnworb avatar mattnworb commented on August 28, 2024

@davidxia my point was more that it is a recommendation and not a requirement when using auto-value, and we don't have to follow it if it leads to a problematic design like in this case.

I'm not sure if this is still a problem or not, I haven't tried building a new project that uses helios-testing:shaded since #1141 was done - there might be other problems.

from helios.

mattnworb avatar mattnworb commented on August 28, 2024

To elaborate a little bit:

Returning Guava types (ImmutableList, ListenableFuture, etc.) from the public API surface of helios-testing or docker-client means that the users of these libraries have to be aware of Guava too. This has caused a lot of pain internally for projects that use a number of clients that depend on differing Guava versions, since there have been a number of incompatibilities between recent Guava versions recently.

Trying to alleviate this by shading and relocating the Guava classes in helios-testing or docker-client would seem like an obvious solution, but if the public API is returning Guava types, then these uses get relocated too. This means that someone using the normal helios-testing passes in a com.google.guava.whatever.ImmutableList to a docker-client/helios-testing method, but if they want to use helios-testing:shaded then now they have to change their code to pass in a com.spotify.helios.relocated.com.google.guava.whatever.ImmutableList instance. This makes it harder for someone to switch to using the shaded artifact as they have to update their code and not just the coordinates of the artifact in their pom. It gets more complicated if helios-testing (regular) is to use docker-client:shaded. So in the end the relocation is still painful to users, as the use of Guava is not purely internal to the library.

For a value class like NetworkSettings I think it is a bad idea (from the lessons we've learned with all the Guava upgrade pains internally) to return Guava collection types as opposed to the core types like Set or List for just this reason. It also makes it harder to ever decide to remove Guava from the library, as now that is a breaking API change for users.

Should note that if you decide to not expose fields as Immutable/Guava types, you can still use them internally in the auto-value static factory - accept a List and wrap it in a ImmutableList.copyOf() - without exposing this to users.

Also for a class like NetworkSettings I don't think there is any reasonable expectation that a user could add elements to a field like List ports(), especially since I don't think the client ever accepts a user-supplied NetworkSettings as an input to an operation. I would be a bigger fan of communicating immutability with javadocs or annotations rather than using the Guava type.

from helios.

davidxia avatar davidxia commented on August 28, 2024

from helios.

mattnworb avatar mattnworb commented on August 28, 2024

No, I hadn't started on that. That type of change might be considered breaking, since code like the following would fail to compile:

ImmutableList<?> ports = networkSettings.ports() // if ports() now returns java.util.List

from helios.

davidxia avatar davidxia commented on August 28, 2024

from helios.

stale avatar stale commented on August 28, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from helios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.