Commit Graph

65 Commits

Author SHA1 Message Date
Maicol
dc20b7561a
Fix error prone warns (#2320)
* Adds `@SuppressWarnings("NarrowingCompoundAssignment")`

* Adds `@SuppressWarnings("TypeParameterUnusedInFormals")`

* Adds `@SuppressWarnings("JavaUtilDate")`

* Adds a limit to `String.split()`

* Add `error_prone_annotations` to the `pom.xml`

* Adds `@InlineMe(...)` to deprecated methods

* Adds `@SuppressWarnings("ImmutableEnumChecker")`

* Adds `@SuppressWarnings("ModifiedButNotUsed")`

* Adds `@SuppressWarnings("MixedMutabilityReturnType")`

* Removes an unused import

* Adds `requires` to `module-info.java`

* Adds ErrorProne `link` into `pom.xml`

* Remove unused imports

Removed from:
- ParseBenchmark

* Adds `@SuppressWarnings("EqualsGetClass")`

* Excludes from `proto` just the generated code.

Replaces `.*proto.*` with `.*/generated-test-sources/protobuf/.*` in such way will be excluded just the generated code and not the whole `proto` directory

* Removes an unused variable

Removes the `descriptor` variable because is unused.

* Fixes the `BadImport` warn into `ProtosWithAnnotationsTest`

* Fixes the `BadImport` warns into `ProtosWithAnnotationsTest`

* Enables ErrorProne in `gson/src/test.*`

Removes the `gson/src/test.*` path from the `-XepExcludedPaths` parameter of the ErrorProne plugin

* Fixes `UnusedVariable` warns

This commit fix all `UnusedVariable` warns given by ErrorProne in the `gson/src/test.*` path.

Some field is annotated with `@Keep` that means is used by reflection.
In some other case the record is annotated with `@SuppressWarnings("unused")`

* Fixes `JavaUtilDate` warns

This commit fix all `JavaUtilDate` warns given by ErrorProne in the `gson/src/test.*` path.

Classes/Methods are annotated with `@SuppressWarnings("JavaUtilDate")` because it's not possible use differente Date API.

* Fixes `EqualsGetClass` warns

This commit fix all `EqualsGetClass` warns given by ErrorProne in the `gson/src/test.*` path.

I have rewrite the `equals()` methods to use `instanceof`

* Replaces pattern matching for instanceof with casts

* Fixes `JdkObsolete` warns

This commit fix all `JdkObsolete` warns given by ErrorProne in the `gson/src/test.*` path.

In some cases I have replaced the obsolete JDK classes with the newest alternatives.  In other cases, I have added the `@SuppressWarnings("JdkObsolete")`

* Fixes `ClassCanBeStatic` warns

This commit fix all `ClassCanBeStatic` warns given by ErrorProne in the `gson/src/test.*` path.

I have added the `static` keyword, or I have added `@SuppressWarnings("ClassCanBeStatic")`

* Fixes `UndefinedEquals` warns

This commit fix all `UndefinedEquals` warns given by ErrorProne in the `gson/src/test.*` path.

I have added `@SuppressWarnings("UndefinedEquals")` or fixed the asserts

Note: In this commit I have also renamed a test from `testRawCollectionDeserializationNotAlllowed` to `testRawCollectionDeserializationNotAllowed`

* Fixes `GetClassOnEnum` warns

This commit fix all `GetClassOnEnum` warns given by ErrorProne in the `gson/src/test.*` path.

I have replaced the `.getClass()` with `.getDeclaringClass()`

* Fixes `ImmutableEnumChecker` warns

This commit fix all `ImmutableEnumChecker` warns given by ErrorProne in the `gson/src/test.*` path.

I have added the `final` keyword, or I have added the `@SuppressWarnings("ImmutableEnumChecker")` annotation

* Fixes `StaticAssignmentOfThrowable` warns

This commit fix all `StaticAssignmentOfThrowable` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `AssertionFailureIgnored` warns

This commit fix all `AssertionFailureIgnored` warns given by ErrorProne in the `gson/src/test.*` path.

I have added the `@SuppressWarnings("AssertionFailureIgnored")` annotation

* Fixes `ModifiedButNotUsed` warns

This commit fix all `ModifiedButNotUsed` warns given by ErrorProne in the `gson/src/test.*` path.

I have added the `@SuppressWarnings("ModifiedButNotUsed")` annotation

* Fixes `MissingSummary` warns

This commit fix all `MissingSummary` warns given by ErrorProne in the `gson/src/test.*` path.

I have remove the Javadoc `@author`

* Fixes `FloatingPointLiteralPrecision` warns

This commit fix all `FloatingPointLiteralPrecision` warns given by ErrorProne in the `gson/src/test.*` path.

I have added the `@SuppressWarnings("FloatingPointLiteralPrecision")` annotation

* Fixes `StringSplitter` warns

This commit fix all `StringSplitter` warns given by ErrorProne in the `gson/src/test.*` path.

I have replaced the `String.split(...)` with `Splitter`

* Fixes `EmptyCatch` warns

This commit fix all `EmptyCatch` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `UnicodeEscape` warns

This commit fix all `UnicodeEscape` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `EmptyBlockTag` warns

This commit fix all `EmptyBlockTag` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `LongFloatConversion` warns

This commit fix all `LongFloatConversion` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `LongDoubleConversion` warns

This commit fix all `LongDoubleConversion` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `TruthAssertExpected` warns

This commit fix all `TruthAssertExpected` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `UnusedMethod` warns

This commit fix all `UnusedMethod` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `UnusedTypeParameter` warns

This commit fix all `UnusedTypeParameter` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `CatchFail` warns

This commit fix all `CatchFail` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `MathAbsoluteNegative` warns

This commit fix all `MathAbsoluteNegative` warns given by ErrorProne in the `gson/src/test.*` path.

* Fixes `LoopOverCharArray` warns

This commit fix all `LoopOverCharArray` warns given by ErrorProne in the `gson/src/test.*` path.

`toCharArray` allocates a new array, using `charAt` is more efficient

* Fixes `HidingField` warns

This commit fix all `HidingField` warns given by ErrorProne in the `gson/src/test.*` path.

* Implements code review feedback

* Implements code review feedback

This commit implements some other code review feedback

* Enable ErrorProne in `extra`

Thi commit removes the `.*extras/src/test.*` path from the `-XepExcludedPaths` parameter of ErrorProne.

* Fix the `JavaUtilDate` warns

This commit fix all `JavaUtilDate` warns given by ErrorProne in the `extras/src/test.*` path.

* Implements code review feedback

* Removes redundant new-line

* Implements code review feedback

* Adds `JDK11` to run test with `--release 11`

* Revert "Adds `JDK11` to run test with `--release 11`"

This reverts commit a7cca386098ae847a10a31c09c3ab9b11eee5920.
2023-03-01 14:23:27 -08:00
Maicol
2658aca66a
Fix error prone warnings (#2316)
* Fix `OperatorPrecedence` warn in `JsonWriter#close`

* Fix `ReferenceEquality` warn in `LinkedTreeMap#replaceInParent`

* Fix `UnnecessaryParentheses` warn in `LinkedTreeMap#replaceInParent`

* Fix `ReferenceEquality` warn in `LinkedTreeMap#hasNext`

* Fix `ReferenceEquality` warn in `LinkedTreeMap#nextNode`

* Adds `error_prone_annotations` to the `pom.xml` of `gson`

* Fix `InlineMeSuggester` warns in `JsonParser`

* Fix `UnnecessaryParentheses` warns in `ConstructorConstructor#newDefaultImplementationConstructor`

* Fix `ThreadLocalUsage` warn in `Gson`

* Fix `JdkObsolete` warn in `GsonBuilder`

* Fix `ReferenceEquality` warn in `LazilyParsedNumber#equals`

* Fix `OperatorPrecedence` warn in `TreeTypeAdapter#create`

* Fix `OperatorPrecedence` warn in `ArrayTypeAdapter`

* Fix `UnnecessaryParentheses` warn in `TypeAdapters`

* Adds `-XepExcludedPaths` flag to ErrorProne plugin to exclude tests and proto path

* Fix `ClassNewInstance` warn in `InterceptorAdapter`

* Fix `ThreadLocalUsage` warn in `GraphAdapterBuilder`

* Fix `JdkObsolete` warn in `GraphAdapterBuilder`

* Revert "Adds `error_prone_annotations` to the `pom.xml` of `gson`"

This reverts commit 14af14dfa23b46a54f4855a70ccf2b0a2cdc3e3f.

* Revert "Fix `InlineMeSuggester` warns in `JsonParser`"

This reverts commit 095bfd517e06510e4cc9cc6b1aac58ad9bf3038a.

* Adds `@SuppressWarnings("ThreadLocalUsage")`

* Fix `OperatorPrecedence` in `JsonWriter`

* Revert "Fix `ReferenceEquality` warn in `LinkedTreeMap#nextNode`"

This reverts commit 387746c7f7e3d0943c8f80501f5d9c3710f4862e.

* Adds `@SuppressWarnings("ReferenceEquality")`

* Adds `guava-testlib` to the gson `pom.xml`

* `@SuppressWarnings("TruthSelfEquals")` removed to use `EqualsTester()`
2023-02-15 05:18:43 -08:00
Maicol
9f26679e7a
Adds Error Prone to the maven-compiler-plugin (#2308)
* Adds Error Prone to the `pom.xml`

* Adds Error Prone annotations to avoid compiling errors

* Adds profile to run Error Prone in JDK8

* Revert "Adds profile to run Error Prone in JDK8"

This reverts commit 61771d0da55003ea5bc8c6f086d925aec583c9a2.

* Fix Error Prone warn

* Add comment to `pom.xml`

* Fix the `@SuppressWarnings("GetClassOnClass")`

* Replace the Error Prone link in the `pom.xml`

* Disable Error Prone with jdk-15`

* Remove a new-line in `pom.xml`
2023-02-06 06:13:28 -08:00
Éamonn McManus
0d22e5d205
Add copyright notices to files that were missing them. (#2307)
In each case the copyright year is the year in which the file was first added.
2023-01-31 14:05:12 -08:00
Maicol
1a2170b99c
Port tests from JUnit 3 to JUnit 4 (#2294)
* Port tests from JUnit 3 to JUnit 4

* Port tests from JUnit 3 to JUnit 4

* Add `@Test` above `@Ignore`
2022-12-22 06:04:16 -08:00
Maicol
0a42c31efe
Code cleanup (#2282)
* Simplify `if` condition in JsonReader.peekNumber()

* Remove `if` to simplify a `return` in Excluder.excludeClassChecks()

* Remove redundant variable in Gson.fromJson()

* equal condition replace by `Objects.equals()` in $Gson$Types.equal()

* equal condition replace by `Objects.equals()` in LinkedTreeMap.equal()

* Replace `switch` with `if` in UtcDateTypeAdapter.read()

* Remove redundant `throws` clause in GraphAdapterBuilder.read()

* Remove redundant `throws` clause in JsonTreeReader.UNREADABLE_READER

* Remove redundant `throws` clause in JsonTreeWriter.UNREADABLE_READER

* Remove unnecessary `.initCause()` call

* Remove redundant cast in TreeTypeAdapter.GsonContextImpl.deserialize

* Replace `StringBuilder` with `String`

* Fix the import and restore the `switch`

* Fix the import

* Add the `util.Objects` import

* Fix indentation

* Add a comment to clarify the condition

* Fix indentation

* Fix imports

* Fix indentation

* Fix indentation

* Fix indentation
2022-12-13 08:50:25 -08:00
Marcono1234
2591ede59b
Fix incorrect HTML headings in Javadoc (#2200) 2022-09-24 17:02:11 -07:00
Éamonn McManus
0864a02e86
Build on JDK 17 as well as 11. (#2198)
* Build on JDK 8 and 17 as well as 11.

* Remove JDK 8 for now.

`DefaultDateTypeAdapterTest` fails.

* Tweak javadoc to avoid warnings.

Mostly these are about using `<h3>` when the previous tag was `<h1>`,
and the like. This previous tag might be implicit (part of what javadoc
itself outputs rather than the HTML in doc comments).

Apparently JDK 11 puts method javadoc inside `<h2>` while JDK 11 puts it
inside `<h3>`. Or something like that. Anyway it doesn't appear to be
possible to use `<h3>` _or_ `<h4>` and please both.
2022-09-23 14:33:28 -07:00
Marcono1234
f7a164d98b
Fail Maven build on compiler warnings; remove some warning suppressions (#2183)
* Fail Maven build on compiler warnings; remove some warning suppressions

* Fix compiler warnings causing failure for newer JDK

* Improve placement of "raw" and "unchecked" warning suppressions

* Adjust javac documentation link

* Fix compilation error on newer JDKs
2022-08-26 17:36:18 -07:00
Éamonn McManus
2deb2099d3
Make RuntimeTypeAdapterFactory recognize subclasses only conditionally. (#2160)
PR #2139 changed this factory so that if given a certain baseType, it will also
recognize any subtype of that type. That is often the right thing to do, but it
is a change in behaviour, and does in fact break at least one current client of
this code. So instead we introduce a new `recognizeSubclasses()` method that
triggers this behaviour. When the method is not called, we revert to the old
behaviour of only recognizing instances of the exact class `baseType`.
2022-07-27 12:18:20 -07:00
Thomas Oster
2eb37589b5
Fix RuntimeTypeAdapterFactory (#2139)
* Change the RuntimeTypeAdapterFactoryTest, so it fails because of #712

* Fix RuntimeTypeAdapterFactory

Trying to use this class as is results in the type-property not being serialized into the JSON, thus it is not present on deserialization.
The fix from https://github.com/google/gson/issues/712#issuecomment-148955110 works. No idea why this is not merged yet.
2022-07-21 10:28:48 -07:00
Marcono1234
4dda4ec5ba
Use diamond operator when creating generic instances (#2104) 2022-04-17 15:27:21 -07:00
Marcono1234
e82637c485
Add support for reflection access filter (#1905)
* Add support for reflection access filter

* Improve documentation

* Fix compilation errors

* Relax handling for BLOCK_ALL when invoking default constructor

* Improve handling for inherited fields

* Fix accessible test failing for static fields

* Simplify ReflectiveTypeAdapterFactory field writing

* Fix GsonBuilder changes affecting created Gson instances

* Improve documentation

* Improve handling for IllegalAccessException

For Java < 9, AccessibleObject.canAccess is not available and therefore checks
might pass even if object is not accessible, causing IllegalAccessException
later.

* Fix incorrect GsonBuilder.addReflectionAccessFilter documentation
2022-04-17 09:05:18 -07:00
Marcono1234
49ddab9eeb
Add CodeQL GitHub code scanning workflow (#2076)
* Add CodeQL GitHub code scanning workflow

* Only compile main sources for code scanning

* Move test .proto  files to test sources

`annotations.proto` also seems to be only relevant for tests because the test
explicitly registers them as extensions. By default the Proto adapter does not
consider them.

* Address some code scanning findings

* Fix some more findings
2022-02-17 18:40:40 -08:00
Marcono1234
615c8835d3
Add GsonBuilder.disableJdkUnsafe() (#1904)
* Add GsonBuilder.disableJdkUnsafe()

* Address review feedback
2021-12-30 15:08:18 -08:00
Marcono1234
6ffcdf3029
Fix Javadoc warnings and errors (#2040) 2021-12-26 15:30:21 -08:00
Marcono1234
26a1928277
Fix RuntimeTypeAdapterFactory depending on internal Streams class (#1959)
* Fix RuntimeTypeAdapterFactory depending on internal Streams class

* Clean up gson-extras project, make it Maven module of gson-parent

* Remove broken test from GraphAdapterBuilderTest
2021-09-17 17:21:37 -07:00
Z
ebe4b581dd
update RawCollectionsExample.java (#1953)
use static method instead deprecated method
2021-09-07 08:02:04 -07:00
Lyubomyr Shaydariv
47b28d99a1 The JavaDoc is now more accurate about the type adapter serialization and deserialization (#1441) 2019-10-28 16:11:15 -07:00
hmble
b046ea28ee
Typo in JavaDoc example 2018-10-10 20:28:10 +05:30
Eric Cochran
d8d8ccb98a Simplify maintainType logic
When we maintain the label value, we do not need to make a new JsonObject and copy over the keys and values when writing. The ordering will change, though. Before this change, it always put the label first.
2018-07-30 13:43:52 -04:00
lucalas
c1e7e2d280 Add possibility to maintain type variable in created pojo (#1342)
Instead of completely remove type variable, give the possibility to decide if maintain type value (if pojo has type variable declaration) or not.
2018-07-20 14:34:45 -07:00
Stefan M
1c09b3f928 Fix well formed exception (#1105)
The previous exception was styled in the following way:
... ["DATE']...
This commit will fix the different quote marks and replace the " with '
2017-06-23 09:32:04 -07:00
Niv Singer
74e37110e5 Avoid NPE in PostConstructAdapterFactory (#1103)
* Avoid NPE in PostConstructAdapterFactory

The RawType's Superclass might be null. This happens, for example, when the type is a collection.

* Add test case for NPE in PostConstructAdapterFactory

* Improve the code quality of PostConstructAdapterFactoryTest

* Improve the code quality of PostConstructAdapterFactoryTest

* Improve the code quality of PostConstructAdapterFactoryTest
2017-06-19 18:04:19 -07:00
Inderjeet Singh
4512f31c69 Added PostConstruct Factory sample in Extras. 2016-09-16 17:35:34 -07:00
Juan Andrés Diana
86d88c32cf The method registerTypeAdapterFactory accepts a TypeAdapterFactory instance only. 2016-05-25 15:49:39 -03:00
Juan Andrés Diana
d4a9eb4e7b Docs fix for the RuntimeTypeAdapterFactory class.
Instances of classes that implement RuntimeTypeAdapterFactory should be registered using the registerTypeAdapterFactory method instead of registerTypeAdapter.
2016-05-24 16:45:55 -03:00
Egor N
edaf59e178 Fix RuntimeTypeAdapterFactory javadoc 2016-02-19 16:14:55 +02:00
Lachlan Coote
1867457030 fix #680 - make RuntimeTypeAdapterFactory null-safe 2015-08-05 16:27:18 -07:00
Inderjeet Singh
0c3b9670f0 Ensuring that UTC date adapter serializes nulls correctly 2014-12-05 22:12:54 +00:00
Inderjeet Singh
f0f9ce42f4 using only Jackson iso8601 implementation for UTC date adapter 2014-12-05 08:28:25 +00:00
Inderjeet Singh
0e3708be82 updated UTC type adapter to support JDK 1.6 using Jackson ISO8601 parsing util 2014-12-05 07:41:08 +00:00
Inderjeet Singh
255f2e2847 added a sample Date type adapter for UTC 2014-12-05 00:16:24 +00:00
Inderjeet Singh
1d9e86e27c fixed extras build 2014-12-04 22:07:13 +00:00
Jesse Wilson
af4879dbb7 Move interceptors from 'alpha' to 'extras'.
This makes the feature less risky to use! It now uses our
TypeAdapterFactory infrastructure rather than relying on
parallel infrastructure.
2012-10-23 17:36:30 +00:00
Inderjeet Singh
42e35e9f90 updated oss-parent version to 7 in gson-extras pom.
fixed some eclipse warnings.
2012-08-01 20:57:51 +00:00
Inderjeet Singh
7a5cef9305 Revised to the new name getDelegateAdapter. 2012-04-14 19:04:14 +00:00
Jesse Wilson
2e6b22fa2e Test that GraphAdapterBuilder works with multiple entity types. 2012-01-01 15:57:29 +00:00
Jesse Wilson
efde6674e1 Test that GraphAdapterBuilder works with collections. 2012-01-01 15:48:01 +00:00
Jesse Wilson
6cca23c172 Get GraphAdapterBuilder working for serialization and deserialization using InstanceCreators to get a sneak peek at a value under construction. 2012-01-01 13:42:44 +00:00
Jesse Wilson
796a381279 Kill GsonInternalAccess. Clients to this were all broken because nobody was ever assigning INSTANCE. 2012-01-01 12:42:20 +00:00
Jesse Wilson
ecdf9150f6 Hide Gson.getNextAdapter() for the current release. 2011-12-31 05:30:40 +00:00
Jesse Wilson
4057b98bab Implement all but the most difficult part of graph type adapter's deserialization. The catch is we want to return an instance that we don't have yet. It's on the stack, but we don't have a handle to it because it's inside the 'nextTypeAdapter' who is busy populating its fields. 2011-12-30 08:27:24 +00:00
Jesse Wilson
6ec6caa49d New extension: handle circular references.
Serialize graphs of objects by assigning each instance a generated ID and writing the complete graph out as a list. The output for a cycle of Rock/Scissors/Paper looks like this:

{
  '0x1':{'name':'ROCK','beats':'0x2'},
  '0x2':{'name':'SCISSORS','beats':'0x3'},
  '0x3':{'name':'PAPER','beats':'0x1'}
}

This is work towards issue 137. The hard part is going to be deserializing that back into a graph.
2011-12-30 07:34:43 +00:00
Jesse Wilson
bcaf56079c Register runtime type adapters using the proper factory-specific APIs. 2011-12-30 06:55:56 +00:00
Jesse Wilson
d7fbac0384 Rename TypeAdapter.Factory to TypeAdapterFactory. 2011-12-23 18:27:13 +00:00
Jesse Wilson
dce4e463d9 Apply variable name improvement from issue 385.
Fixes issue 385.
2011-12-16 04:55:54 +00:00
Jesse Wilson
f602bce9f5 Nice documentation for TypeAdapter. 2011-12-03 19:46:25 +00:00
Jesse Wilson
26ab404599 Cleanup names for TypeAdapters. 2011-12-02 22:57:30 +00:00
Jesse Wilson
f39ac8d946 Update extras to build after today's Gson/MiniGson refactoring. 2011-11-21 05:09:14 +00:00