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

Perform minor code clean-up #2544

Merged
merged 5 commits into from
Nov 19, 2023

Conversation

Marcono1234
Copy link
Collaborator

@Marcono1234 Marcono1234 commented Nov 18, 2023

Purpose

Performs some minor code clean-up, which should not noticeably (or at all) change functionality

Description

Notable changes:

  • Replace most usages of <code> with {@code ...} in Javadoc
  • Add proper summary sentence to GsonBuilder.enableComplexMapKeySerialization
  • Extend documentation for GsonBuilder.setDateFormat methods
  • Fix TypeToken.isAssignableFrom(Type) throwing AssertionError in some cases
    Maybe the method should not throw an exception in the first place, but it might not matter much since it is deprecated already anyway.
  • Remove outdated throws NumberFormatException from internal JsonReader.nextQuotedValue; the behavior had been changed by 85ebaf7
  • Fix incorrect documentation on JsonScope fields
  • Fix unit tests having 'expected' and 'actual' switched
    For that I removed the .getType() call from TypeToken to use <T> Gson.fromJson(..., TypeToken<T>) instead of <T> Gson.fromJson(..., Type) because otherwise the call to assertThat(...) would have been ambiguous.
  • Use dedicated Truth methods instead of isTrue() / isFalse()
  • Use common helper methods in JsonWriterTest to avoid duplication
  • Implement toString() for ReflectionAccessFilter constants

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

Notable changes:
- Replace most usages of `<code>` with `{@code ...}` in Javadoc
- Add proper summary sentence to `GsonBuilder.enableComplexMapKeySerialization`
- Extend documentation for `GsonBuilder.setDateFormat` methods
- Fix `TypeToken.isAssignableFrom(Type)` throwing AssertionError in some cases
  Maybe the method should not throw an exception in the first place, but it
  might not matter much since it is deprecated already anyway.
- Remove outdated `throws NumberFormatException` from internal
  `JsonReader.nextQuotedValue`; the behavior had been changed by
  85ebaf7
- Fix incorrect documentation on JsonScope fields
- Fix unit tests having 'expected' and 'actual' switched
- Use dedicated Truth methods instead of `isTrue()` / `isFalse()`
- Use common helper methods in JsonWriterTest to avoid duplication
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.

Very nice! Just a few comments.

Actually it looks like the warning is not actually caused by usage of
`HEAD` as value, but rather because the project has a snapshot version
during development (which is expected though), see
https://github.com/apache/maven-artifact-plugin/blob/maven-artifact-plugin-3.5.0/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java#L140

But this is not a problem either since during release a non-snapshot
version is used.
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.

Looking good! Just one small thing...

@@ -117,6 +117,11 @@ public FilterResult check(Class<?> rawClass) {
? FilterResult.BLOCK_INACCESSIBLE
: FilterResult.INDECISIVE;
}

@Override
Copy link
Member

Choose a reason for hiding this comment

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

Can you mention these in the PR description?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Have included it now; sorry that I added this in a follow-up commit and not in the original changes of this PR. I just remembered that this change was something I wanted to do for quite some time because the default toString() during debugging makes it difficult to understand which filter is used.

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 again. This is a big improvement!

@eamonnmcmanus eamonnmcmanus merged commit 08174e2 into google:main Nov 19, 2023
10 checks passed
@Marcono1234 Marcono1234 deleted the marcono1234/minor-code-cleanup branch November 19, 2023 17:12
tibor-universe pushed a commit to getuniverse/gson that referenced this pull request Sep 14, 2024
* Perform minor code clean-up

Notable changes:
- Replace most usages of `<code>` with `{@code ...}` in Javadoc
- Add proper summary sentence to `GsonBuilder.enableComplexMapKeySerialization`
- Extend documentation for `GsonBuilder.setDateFormat` methods
- Fix `TypeToken.isAssignableFrom(Type)` throwing AssertionError in some cases
  Maybe the method should not throw an exception in the first place, but it
  might not matter much since it is deprecated already anyway.
- Remove outdated `throws NumberFormatException` from internal
  `JsonReader.nextQuotedValue`; the behavior had been changed by
  85ebaf7
- Fix incorrect documentation on JsonScope fields
- Fix unit tests having 'expected' and 'actual' switched
- Use dedicated Truth methods instead of `isTrue()` / `isFalse()`
- Use common helper methods in JsonWriterTest to avoid duplication

* Implement `toString()` for ReflectionAccessFilter constants

* Address most of the review comments

* Add comment about `source.scm.tag=HEAD` warning

Actually it looks like the warning is not actually caused by usage of
`HEAD` as value, but rather because the project has a snapshot version
during development (which is expected though), see
https://github.com/apache/maven-artifact-plugin/blob/maven-artifact-plugin-3.5.0/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java#L140

But this is not a problem either since during release a non-snapshot
version is used.
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.

2 participants