Commit Graph

20 Commits

Author SHA1 Message Date
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 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 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
Marcono1234 5e1005ea27
Disallow `JsonObject` `Entry.setValue(null)` (#2167)
* Disallow JsonObject Entry.setValue(null)

* Adjust comments in JsonObjectTest
2022-08-18 13:10:43 -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 e6fae590cf
Prevent Java deserialization of internal classes (#1991)
Adversaries might be able to forge data which can be abused for DoS attacks.
These classes are already writing a replacement JDK object during serialization
for a long time, so this change should not cause any issues.
2021-10-13 10:14:57 -07:00
Jake Wharton 7a1c94f986 Remove synthetic accessors from being generated. 2015-12-27 01:39:19 -05:00
Inderjeet Singh 14ba59fa88 code review fixes. Moved getFirstArgument() method from $Gson$Types to GsonTypesTest. 2014-05-19 17:34:25 +00:00
Joel Leitch f29d5bc37b Create a LinkedTreeMap based on the LinkedHashTreeMap; however, removed all the hashing from it as resorted to a single tree. The insertion order is still preserved. 2013-05-03 16:11:16 +00:00
Joel Leitch af6aa5f782 Use the LinkedHashTreeMap instead of LinkedTreeMap and delete the LinkedTreeMap version. 2013-04-04 21:31:23 +00:00
Joel Leitch edf326e756 Tag member fields as transient since a LinkedHashMap is used for serialization. 2013-01-15 20:04:26 +00:00
Joel Leitch 3f2efac95e Stop blowing up on a null key, but rather return that the element is not found. 2013-01-09 23:37:38 +00:00
Joel Leitch 14f16e2d0c Adding Red-Black Tree implementation and tying it into the Gson bindings. 2012-10-11 03:15:49 +00:00
Jesse Wilson 2fef83799d Optimizations and bug fixes for LinkedHashTreeMap.
The most interesting optimization is to replace ArrayDeque with a manual linked list that reuses the nodes 'parent' field. These optimizations save about 20%.
2012-09-17 03:30:20 +00:00
Jesse Wilson aceadaecf1 Add a hashing layer to LinkedTreeMap. Instead of having 1 root node, the class now has several root nodes, one for each hash bucket in a hash table.
Compared to LinkedTreeMap, this is slower for small (size=5) maps: 124% slower to get() and 33% slower to create and populate. It's a win for large (size=500) maps: 46% faster to get() but 8% slower to create and populate. And it's a big win for very large (size=50,000) maps: 81% faster to get() and 46% faster to create and populate.

http://microbenchmarks.appspot.com/run/limpbizkit@gmail.com/com.google.common.collect.MapBenchmark

I'm going to follow this up with some simple optimizations: caching local fields and simplifying access. That should narrow the performance gap.
2012-09-17 00:19:44 +00:00
Jesse Wilson a0493b9732 New code that can split an AVL tree into two AVL trees.
This is in preparation for a new feature where LinkedTreeMap will have multiple roots, each in its own hash bucket.
2012-09-15 06:13:33 +00:00
Jesse Wilson 01bd0d92e2 Tests for LinkedTreeMap with incompatible keys. 2012-09-12 05:06:48 +00:00
Jesse Wilson a6ab854302 Fix a bug where we were unlinking nodes that shouldn't have been unlinked.
Found by Guava's awesome collections test suite!
2012-09-12 04:41:58 +00:00
Jesse Wilson 93e38901df Draft of LinkedTreeMap. Its ordered like a LinkedHashMap but it doesn't do any hashing for DoS resistance.
Not yet adopted in our code.

Known critical bugs:
 - throws ClassCastException when get() is called with a non-comparable key
 - throws NullPointerException on get(null)
2012-09-10 20:04:38 +00:00