Commit Graph

35 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
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
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
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
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
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
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
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
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
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
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
46e65a77c5 Convert RuntimeTypeAdapter to a TypeAdapterFactory; this avoids the need for serializeDefault() 2011-09-28 19:14:46 +00:00
Jesse Wilson
60e6ed912d Promote MiniGson to gson.internal.bind 2011-08-03 00:25:10 +00:00
Jesse Wilson
4b042671af Cleanup after experimenting with specializing BoundField by type (ie. Field.setInt() to avoid autoboxing) 2011-07-15 14:37:05 +00:00
Jesse Wilson
041d499a7c Fix serialization where one type depends (possibly indireclty) on itself! 2011-07-12 19:39:27 +00:00
Jesse Wilson
c6bef30057 Array support. 2011-07-11 22:26:53 +00:00
Jesse Wilson
95a345234f MiniGSON Map adapters and support for nulls. 2011-07-11 21:45:09 +00:00
Jesse Wilson
c5f1df1017 MiniGSON prototype! 2011-07-11 16:46:52 +00:00
Inderjeet Singh
62675b7f46 Added serializeDefault and deserializeDefault methods in contexts that only invoke system type adapters on the top-level object.
With this, the RuntimeTypeAdapterTest passes.
2011-07-01 21:29:20 +00:00
Jesse Wilson
9ad3358728 Document RuntimeTypeAdapter 2011-06-06 05:40:13 +00:00
Jesse Wilson
3d50a6b72a New failing test for RuntimeTypeAdapters! 2011-05-27 18:47:31 +00:00
Jesse Wilson
d93825ba72 First draft of RuntimeTypeAdapters 2011-05-14 02:04:17 +00:00