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

Using a collection builder with ImmutableSortedSet #666

Closed
jonfreedman opened this issue Sep 25, 2018 · 3 comments · Fixed by #737
Closed

Using a collection builder with ImmutableSortedSet #666

jonfreedman opened this issue Sep 25, 2018 · 3 comments · Fixed by #737
Assignees

Comments

@jonfreedman
Copy link

I want to have a class similar to the below but ImmutableSortedSet.Builder throws an exception from it's factory method. Is this possible?

public abstract static class Builder {
    private static Builder builder() {
        return new AutoValue_Object.Builder();
    }

    abstract ImmutableSortedSet.Builder<ComparableObject> pointsBuilder();

    public abstract Builder setPoints(final ImmutableList<ComparableObject> points);

    public Builder addPoint(final ComparableObject point) {
        pointsBuilder().add(point);
        return this;
    }
    
    public abstract Object build();
}
@jonfreedman
Copy link
Author

I had a quick look into what's going on, I would say that ImmutableSortedSetDeserializer in jackson-datatype-guava sets president for using ImmutableSortedSet.naturalOrder() instead of ImmutableSortedSet.builder()

@eamonnmcmanus eamonnmcmanus self-assigned this Sep 25, 2018
@eamonnmcmanus
Copy link
Member

It's a fair point. ImmutableSortedSet.builder() throws UnsupportedOperationException because its signature would ideally be the same as ImmutableSortedSet.naturalOrder(), i.e. static <E extends Comparable<?>> Builder<E> builder(). But that's not possible because it conflicts with the signature in the ancestor class ImmutableSet, which is static <E> Builder<E> builder(). I think throwing an exception is kind of obnoxious but that's how it is (and has been since 2009).

We could recognize naturalOrder() for ImmutableSortedSet and ImmutableSortedMap. If the element type is not actually Comparable then this would provoke a surprising error in the generated code, unless AutoValue makes the Comparable check itself.

@jonfreedman
Copy link
Author

I think the alternative would involve being able to define the factory method somehow with an annotation?

@ronshapiro ronshapiro mentioned this issue May 27, 2019
ronshapiro pushed a commit that referenced this issue May 27, 2019
…pyOfSorted when setting from a SortedSet or SortedMap. Use .naturalOrder when constructing a builder.

Fixes #666.

RELNOTES=Use ImmutableSortedSet.copyOfSorted and .naturalOrder where appropriate.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=249632356
ronshapiro pushed a commit that referenced this issue May 27, 2019
…pyOfSorted when setting from a SortedSet or SortedMap. Use .naturalOrder when constructing a builder.

Fixes #666.

RELNOTES=Use ImmutableSortedSet.copyOfSorted and .naturalOrder where appropriate.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=249632356
emspishak pushed a commit to google/closure-templates that referenced this issue Oct 26, 2020
…value-annotations.

I will fully admit, I don't really know what I am doing here. In child cl/336538362, I add a test for an AutoValue object that needs google/auto#666 resolved (specifically google/auto@a0de99b to be in the build). This looks like it was added to AutoValue starting in release 1.6.6 but for the maven build Soy is using auto value version 1.6.3. As part of this version update, I ran into a problem with duplicate classes for auto-value-annotation. This was stemming from truth still depending on version 1.6.3 of auto-value-annotation. Therefore, I added an exclusion to that dependency for auto-value-annotation. I think is the right thing to do but I again don't really know what I am doing.

[]

I also bumped the version of maven project, which I think is the right thing to do?

GITHUB_BREAKING_CHANGES=changes maven build to use auto value version 1.7.4

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=337885608
copybara-service bot pushed a commit that referenced this issue Sep 10, 2024
Bumps the github-actions group with 1 update: [actions/setup-java](https://github.com/actions/setup-java).

Updates `actions/setup-java` from 4.2.2 to 4.3.0
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/actions/setup-java/releases">actions/setup-java's releases</a>.</em></p>
<blockquote>
<h2>v4.3.0</h2>
<p>What's Changed</p>
<ul>
<li>Add support for SapMachine JDK/JRE by <a href="https://github.com/Shegox"><code>@​Shegox</code></a> in <a href="https://redirect.github.com/actions/setup-java/issues/614">#614</a></li>
</ul>
<pre lang="yaml"><code>steps:
 - name: Checkout
   uses: actions/checkout@v4
 - name: Setup-java
   uses: actions/setup-java@v4
   with:
     distribution: ‘sapmachine’
     java-version: ’21’
</code></pre>
<p>Bug fixes :</p>
<ul>
<li>
<pre><code>Fix typos on Corretto by @johnshajiang in [#666](actions/setup-java#666)
</code></pre>
</li>
<li>
<pre><code>IBM Semeru Enhancement on arm64 by @mahabaleshwars in [#677](actions/setup-java#677)
</code></pre>
</li>
<li>
<pre><code>Resolve Basic Validation Check Failures by @aparnajyothi-y
 in [#682](actions/setup-java#682)
</code></pre>
</li>
</ul>
<p>New Contributors :</p>
<ul>
<li>
<pre><code>@johnshajiang made their first contribution in [#666](actions/setup-java#666)
</code></pre>
</li>
<li>
<pre><code>@Shegox made their first contribution in [#614](actions/setup-java#614)
</code></pre>
</li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/actions/setup-java/compare/v4...v4.3.0">https://github.com/actions/setup-java/compare/v4...v4.3.0</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/actions/setup-java/commit/2dfa2011c5b2a0f1489bf9e433881c92c1631f88"><code>2dfa201</code></a> basic validation failure fix (<a href="https://redirect.github.com/actions/setup-java/issues/682">#682</a>)</li>
<li><a href="https://github.com/actions/setup-java/commit/7467385c615a13cecd14d5768e738332968d0792"><code>7467385</code></a> feat: add support for SapMachine JDK/JRE (<a href="https://redirect.github.com/actions/setup-java/issues/614">#614</a>)</li>
<li><a href="https://github.com/actions/setup-java/commit/8e04ddff28554375a9a1096c888a2ef2c9803cd7"><code>8e04ddf</code></a> Update Error Messages and Fix Architecture Detection for IBM Semeru (<a href="https://redirect.github.com/actions/setup-java/issues/677">#677</a>)</li>
<li><a href="https://github.com/actions/setup-java/commit/67fbd726daaf08212a7b021c1c4d117f94a81dd3"><code>67fbd72</code></a> Fix typos on Corretto (<a href="https://redirect.github.com/actions/setup-java/issues/665">#665</a>) (<a href="https://redirect.github.com/actions/setup-java/issues/666">#666</a>)</li>
<li>See full diff in <a href="https://github.com/actions/setup-java/compare/6a0805fcefea3d4657a47ac4c165951e33482018...2dfa2011c5b2a0f1489bf9e433881c92c1631f88">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/setup-java&package-manager=github_actions&previous-version=4.2.2&new-version=4.3.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions

</details>

Fixes #1834

COPYBARA_INTEGRATE_REVIEW=#1834 from google:dependabot/github_actions/github-actions-bc3bba8501 ab1fc54
PiperOrigin-RevId: 672948325
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

Successfully merging a pull request may close this issue.

2 participants