Skip to content

Conversation

@MukjepScarlet
Copy link
Contributor

Purpose

Part of #2864

Description

lambda -> method reference (reduce synthetic methods)
duplicated lambdas -> a class

Checklist

  • New code follows the Google Java Style Guide
    This is automatically checked by mvn verify, but can also be checked on its own using mvn spotless:check.
    Style violations can be fixed using mvn spotless:apply; this can be done in a separate commit to verify that it did not cause undesired changes.
  • If necessary, new public API validates arguments, for example rejects null
  • New public API has Javadoc
    • Javadoc uses @since $next-version$
      ($next-version$ is a special placeholder which is automatically replaced during release)
  • If necessary, new unit tests have been added
    • Assertions in unit tests use Truth, see existing tests
    • No JUnit 3 features are used (such as extending class TestCase)
    • If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
  • mvn clean verify javadoc:jar passes without errors

@MukjepScarlet
Copy link
Contributor Author

MukjepScarlet commented Nov 25, 2025

@eamonnmcmanus Please review this. Because I'm not Android developer, I'm not sure if these are benificial with Proguard/R8.

Copy link
Contributor

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

The idea to add an ExceptionObjectConstructor is really good to reduce the code duplication. I have just a few small suggestions.

The project members might have additional change requests though.

MukjepScarlet and others added 2 commits November 26, 2025 11:25
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
Copy link
Member

@eamonnmcmanus eamonnmcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I checked that it passes all of Google's internal tests.

@eamonnmcmanus eamonnmcmanus merged commit e28fdb9 into google:main Nov 26, 2025
16 checks passed
@MukjepScarlet MukjepScarlet deleted the refactor/constructorconstructor branch November 27, 2025 02:21
eamonnmcmanus pushed a commit to eamonnmcmanus/gson that referenced this pull request Dec 19, 2025
* refactor: slightly optimize ConstructorConstructor

* Update comments

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>

* spotless apply

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>

---------

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
eamonnmcmanus added a commit that referenced this pull request Dec 23, 2025
* Add type adapters for `java.time` classes.

These adapters essentially freeze the JSON representation that
`ReflectiveTypeAdapterFactory` established by default, based on the
private fields of `java.time` classes. That's not a great
representation, but it is understandable. Changing it to anything else
would break compatibility with systems that are expecting the current
format.

If Gson had been updated with `java.time` adapters at the time the
`java.time` API was added, the representation would surely have been
something else, probably ISO standard formats. We can still supply
non-default adapters for that, but we'll still need to have these legacy
adapters by default.

I've been meaning to make this change for a while, but the need to do so
becomes more urgent with [this JDK
commit](openjdk/jdk@cc05530)
which makes a number of `java.time` fields `transient`. That means that
the reflective-based adapter will no longer work with the classes that
were changed.

* Apply a couple of Error Prone suggestions.

* Reformat a couple of source files.

* Fix another EP warning.

* Fix a particularly annoying EP warning/error.

* Update the Android API level.

I think it is time to do this, but obviously it should be a separate PR.

* Substantial rework.

* Move the new `TypeAdapter` implementations into a new class
  `JavaTimeTypeAdapters`. This allows us to omit that class from Android
  builds where it otherwise triggers warnings about SDK levels.

* Ensure that every `java.time` class that needs a `TypeAdapter` has
  one. This doesn't include "subpackages" `java.time.*` like
  `java.time.chrono`, where it doesn't appear that there are any classes
  that are likely to be serialized to JSON.

* Fix the handling of `ZoneId` and its subclasses.

* refactor: slightly optimize ConstructorConstructor (#2950)

* refactor: slightly optimize ConstructorConstructor

* Update comments

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>

* spotless apply

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>

---------

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>

* Fix outdated comment (#2954)

* Compilation fixes.

I copied the internal version that was running on Google's
infrastructure, and some adjustments were needed.

* Fix lint errors.

* Fix a particularly annoying lint error.

* Fix the fix.

* Further fixes.

This still doesn't pass with a local build, and I may need to debug an
OSGi problem.

* Revert to Android API 23, but with gummy-bears-api.

* Annotate `JavaTimeTypeAdapters` to suppress animal-sniffer errors.

* Update `OSGiManifestIT` not to depend on order.

It appears that sometimes the clauses being checked for appear in the
other order, possibly because of a `HashMap` or the like somewhere in
the guts of OSGi. I haven't seen this on GitHub, but I do see it when
running locally with Google's JDK, which has more hash randomization.

* Fix use of assignment expression.

* Remove the parser, which was overkill.

It's enough just to swap the two clauses of a line when they are not in
the expected order.

Also, unrelatedly, update `protobuf-maven-plugin`.

* Use a local `@IgnoreJRERequirement`.

* Configure the local animal-sniffer annotation.

* Suppress IdentifierName warning.

* Update comments and undo an unnecessary split.

* Restore Math.toIntExact.

---------

Co-authored-by: 木葉 Scarlet <93977077+MukjepScarlet@users.noreply.github.com>
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
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 this pull request may close these issues.

3 participants