Skip to content

Commit 4c7accd

Browse files
committed
---
yaml --- r: 5843 b: refs/heads/tswast-patch-1 c: e7ce4ea h: refs/heads/master i: 5841: 41f7b84 5839: 5e4d20d
1 parent ffb05e4 commit 4c7accd

10 files changed

Lines changed: 52 additions & 63 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: bf4f0351afc8431891f5243a6d627359571e638d
60+
refs/heads/tswast-patch-1: e7ce4ead8e76dc06dfe9dd6f2aa9ea73ad9c3ccc
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<RobustaSettings><ProjectDetect FolderName="java" enable="true" /><ProjectDetect FolderName="resources" enable="true" /></RobustaSettings>
2+
<RobustaSettings><ProjectDetect FolderName="java" enable="true" /><ProjectDetect FolderName="resources" enable="false" /></RobustaSettings>

branches/tswast-patch-1/pmd.xml

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,16 @@
66
<description>PMD Plugin preferences rule set</description>
77
<rule ref="rulesets/java/design.xml/AbstractClassWithoutAbstractMethod"/>
88
<rule ref="rulesets/java/design.xml/AbstractClassWithoutAnyMethod"/>
9-
<rule ref="rulesets/java/naming.xml/AbstractNaming"/>
10-
<rule ref="rulesets/java/design.xml/AccessorClassGeneration"/>
119
<rule ref="rulesets/java/optimizations.xml/AddEmptyString"/>
1210
<rule ref="rulesets/java/strings.xml/AppendCharacterWithChar"/>
1311
<rule ref="rulesets/java/sunsecure.xml/ArrayIsStoredDirectly"/>
14-
<rule ref="rulesets/ecmascript/basic.xml/AssignmentInOperand"/>
15-
<rule ref="rulesets/java/controversial.xml/AssignmentInOperand"/>
1612
<rule ref="rulesets/java/design.xml/AssignmentToNonFinalStatic"/>
17-
<rule ref="rulesets/java/controversial.xml/AtLeastOneConstructor"/>
1813
<rule ref="rulesets/java/controversial.xml/AvoidAccessibilityAlteration"/>
1914
<rule ref="rulesets/java/optimizations.xml/AvoidArrayLoops"/>
2015
<rule ref="rulesets/java/migrating.xml/AvoidAssertAsIdentifier"/>
2116
<rule ref="rulesets/xsl/xpath.xml/AvoidAxisNavigation"/>
2217
<rule ref="rulesets/java/basic.xml/AvoidBranchingStatementAsLastInLoop"/>
2318
<rule ref="rulesets/java/finalizers.xml/AvoidCallingFinalize"/>
24-
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingGenericException"/>
2519
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingNPE"/>
2620
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingThrowable"/>
2721
<rule ref="rulesets/java/design.xml/AvoidConstantsInterface"/>
@@ -31,12 +25,9 @@
3125
<rule ref="rulesets/java/naming.xml/AvoidDollarSigns"/>
3226
<rule ref="rulesets/java/strings.xml/AvoidDuplicateLiterals"/>
3327
<rule ref="rulesets/java/migrating.xml/AvoidEnumAsIdentifier"/>
34-
<rule ref="rulesets/java/naming.xml/AvoidFieldNameMatchingMethodName"/>
35-
<rule ref="rulesets/java/naming.xml/AvoidFieldNameMatchingTypeName"/>
3628
<rule ref="rulesets/java/controversial.xml/AvoidFinalLocalVariable"/>
3729
<rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause"/>
3830
<rule ref="rulesets/java/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>
39-
<rule ref="rulesets/java/controversial.xml/AvoidLiteralsInIfCondition"/>
4031
<rule ref="rulesets/java/strictexception.xml/AvoidLosingExceptionInformation"/>
4132
<rule ref="rulesets/java/basic.xml/AvoidMultipleUnaryOperators"/>
4233
<rule ref="rulesets/java/controversial.xml/AvoidPrefixingMethodParameters"/>
@@ -59,15 +50,13 @@
5950
<rule ref="rulesets/java/controversial.xml/AvoidUsingShortType"/>
6051
<rule ref="rulesets/java/controversial.xml/AvoidUsingVolatile"/>
6152
<rule ref="rulesets/java/design.xml/BadComparison"/>
62-
<rule ref="rulesets/java/javabeans.xml/BeanMembersShouldSerialize"/>
6353
<rule ref="rulesets/java/basic.xml/BigIntegerInstantiation"/>
6454
<rule ref="rulesets/java/naming.xml/BooleanGetMethodName"/>
6555
<rule ref="rulesets/java/basic.xml/BooleanInstantiation"/>
6656
<rule ref="rulesets/java/controversial.xml/BooleanInversion"/>
6757
<rule ref="rulesets/java/basic.xml/BrokenNullCheck"/>
6858
<rule ref="rulesets/java/migrating.xml/ByteInstantiation"/>
6959
<rule ref="rulesets/java/android.xml/CallSuperFirst"/>
70-
<rule ref="rulesets/java/controversial.xml/CallSuperInConstructor"/>
7160
<rule ref="rulesets/java/android.xml/CallSuperLast"/>
7261
<rule ref="rulesets/java/basic.xml/CheckResultSet"/>
7362
<rule ref="rulesets/java/basic.xml/CheckSkipResult"/>
@@ -80,19 +69,24 @@
8069
<rule ref="rulesets/java/basic.xml/CollapsibleIfStatements"/>
8170
<rule ref="rulesets/vm/basic.xml/CollapsibleIfStatements"/>
8271
<rule ref="rulesets/java/comments.xml/CommentContent"/>
83-
<rule ref="rulesets/java/comments.xml/CommentSize"/>
72+
<rule ref="rulesets/java/comments.xml/CommentSize">
73+
<properties>
74+
<property name="maxLineLength" value="100"/>
75+
</properties>
76+
</rule>
8477
<rule ref="rulesets/java/design.xml/CompareObjectsWithEquals"/>
85-
<rule ref="rulesets/java/design.xml/ConfusingTernary"/>
8678
<rule ref="rulesets/java/strings.xml/ConsecutiveAppendsShouldReuse"/>
8779
<rule ref="rulesets/java/strings.xml/ConsecutiveLiteralAppends"/>
8880
<rule ref="rulesets/ecmascript/basic.xml/ConsistentReturn"/>
8981
<rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod"/>
9082
<rule ref="rulesets/java/coupling.xml/CouplingBetweenObjects"/>
91-
<rule ref="rulesets/plsql/codesize.xml/CyclomaticComplexity"/>
83+
<rule ref="rulesets/plsql/codesize.xml/CyclomaticComplexity">
84+
<properties>
85+
<property name="reportLevel" value="14"/>
86+
</properties>
87+
</rule>
9288
<rule ref="rulesets/java/codesize.xml/CyclomaticComplexity"/>
93-
<rule ref="rulesets/java/controversial.xml/DataflowAnomalyAnalysis"/>
9489
<rule ref="rulesets/java/design.xml/DefaultLabelNotLastInSwitchStmt"/>
95-
<rule ref="rulesets/java/controversial.xml/DefaultPackage"/>
9690
<rule ref="rulesets/java/controversial.xml/DoNotCallGarbageCollectionExplicitly"/>
9791
<rule ref="rulesets/java/j2ee.xml/DoNotCallSystemExit"/>
9892
<rule ref="rulesets/java/strictexception.xml/DoNotExtendJavaLangError"/>
@@ -107,7 +101,6 @@
107101
<rule ref="rulesets/java/basic.xml/DoubleCheckedLocking"/>
108102
<rule ref="rulesets/java/imports.xml/DuplicateImports"/>
109103
<rule ref="rulesets/jsp/basic.xml/DuplicateJspImports"/>
110-
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock"/>
111104
<rule ref="rulesets/java/finalizers.xml/EmptyFinalizer"/>
112105
<rule ref="rulesets/java/empty.xml/EmptyFinallyBlock"/>
113106
<rule ref="rulesets/vm/basic.xml/EmptyForeachStmt"/>
@@ -149,10 +142,8 @@
149142
<rule ref="rulesets/ecmascript/braces.xml/ForLoopsMustUseBraces"/>
150143
<rule ref="rulesets/java/naming.xml/GenericsNaming"/>
151144
<rule ref="rulesets/ecmascript/basic.xml/GlobalVariable"/>
152-
<rule ref="rulesets/java/design.xml/GodClass"/>
153145
<rule ref="rulesets/java/logging-jakarta-commons.xml/GuardDebugLogging"/>
154146
<rule ref="rulesets/java/logging-jakarta-commons.xml/GuardLogStatement"/>
155-
<rule ref="rulesets/java/logging-java.xml/GuardLogStatementJavaUtil"/>
156147
<rule ref="rulesets/java/design.xml/IdempotentOperations"/>
157148
<rule ref="rulesets/java/braces.xml/IfElseStmtsMustUseBraces"/>
158149
<rule ref="rulesets/ecmascript/braces.xml/IfElseStmtsMustUseBraces"/>
@@ -171,25 +162,20 @@
171162
<rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseAfterAnnotation"/>
172163
<rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseBeforeAnnotation"/>
173164
<rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseTestAnnotation"/>
174-
<rule ref="rulesets/java/junit.xml/JUnitAssertionsShouldIncludeMessage"/>
175165
<rule ref="rulesets/java/junit.xml/JUnitSpelling"/>
176166
<rule ref="rulesets/java/junit.xml/JUnitStaticSuite"/>
177-
<rule ref="rulesets/java/junit.xml/JUnitTestContainsTooManyAsserts"/>
178167
<rule ref="rulesets/java/junit.xml/JUnitTestsShouldIncludeAssert"/>
179168
<rule ref="rulesets/java/migrating.xml/JUnitUseExpected"/>
180169
<rule ref="rulesets/jsp/basic.xml/JspEncoding"/>
181170
<rule ref="rulesets/java/basic.xml/JumbledIncrementer"/>
182-
<rule ref="rulesets/java/coupling.xml/LawOfDemeter"/>
183171
<rule ref="rulesets/java/j2ee.xml/LocalHomeNamingConvention"/>
184172
<rule ref="rulesets/java/j2ee.xml/LocalInterfaceSessionNamingConvention"/>
185173
<rule ref="rulesets/java/logging-java.xml/LoggerIsNotStaticFinal"/>
186174
<rule ref="rulesets/java/design.xml/LogicInversion"/>
187175
<rule ref="rulesets/java/migrating.xml/LongInstantiation"/>
188-
<rule ref="rulesets/java/naming.xml/LongVariable"/>
189176
<rule ref="rulesets/java/coupling.xml/LooseCoupling"/>
190177
<rule ref="rulesets/java/coupling.xml/LoosePackageCoupling"/>
191178
<rule ref="rulesets/java/j2ee.xml/MDBAndSessionBeanNamingConvention"/>
192-
<rule ref="rulesets/java/optimizations.xml/MethodArgumentCouldBeFinal"/>
193179
<rule ref="rulesets/java/naming.xml/MethodNamingConventions"/>
194180
<rule ref="rulesets/java/sunsecure.xml/MethodReturnsInternalArray"/>
195181
<rule ref="rulesets/java/naming.xml/MethodWithSameNameAsEnclosingClass"/>
@@ -222,9 +208,7 @@
222208
<rule ref="rulesets/java/design.xml/NonCaseLabelInSwitchStatement"/>
223209
<rule ref="rulesets/java/design.xml/NonStaticInitializer"/>
224210
<rule ref="rulesets/java/design.xml/NonThreadSafeSingleton"/>
225-
<rule ref="rulesets/java/controversial.xml/NullAssignment"/>
226211
<rule ref="rulesets/java/controversial.xml/OneDeclarationPerLine"/>
227-
<rule ref="rulesets/java/controversial.xml/OnlyOneReturn"/>
228212
<rule ref="rulesets/java/design.xml/OptimizableToArrayCall"/>
229213
<rule ref="rulesets/java/basic.xml/OverrideBothEqualsAndHashcode"/>
230214
<rule ref="rulesets/java/naming.xml/PackageCase"/>
@@ -243,10 +227,13 @@
243227
<rule ref="rulesets/java/design.xml/ReturnEmptyArrayRatherThanNull"/>
244228
<rule ref="rulesets/java/basic.xml/ReturnFromFinallyBlock"/>
245229
<rule ref="rulesets/ecmascript/basic.xml/ScopeForInVariable"/>
246-
<rule ref="rulesets/java/naming.xml/ShortClassName"/>
230+
<rule ref="rulesets/java/naming.xml/ShortClassName">
231+
<properties>
232+
<property name="minimum" value="3"/>
233+
</properties>
234+
</rule>
247235
<rule ref="rulesets/java/migrating.xml/ShortInstantiation"/>
248236
<rule ref="rulesets/java/naming.xml/ShortMethodName"/>
249-
<rule ref="rulesets/java/naming.xml/ShortVariable"/>
250237
<rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException"/>
251238
<rule ref="rulesets/java/design.xml/SimpleDateFormatNeedsLocale"/>
252239
<rule ref="rulesets/java/junit.xml/SimplifyBooleanAssertion"/>
@@ -276,9 +263,6 @@
276263
<rule ref="rulesets/plsql/codesize.xml/TooManyFields"/>
277264
<rule ref="rulesets/java/codesize.xml/TooManyFields"/>
278265
<rule ref="rulesets/plsql/codesize.xml/TooManyMethods"/>
279-
<rule ref="rulesets/java/codesize.xml/TooManyMethods"/>
280-
<rule ref="rulesets/java/imports.xml/TooManyStaticImports"/>
281-
<rule ref="rulesets/java/design.xml/UncommentedEmptyConstructor"/>
282266
<rule ref="rulesets/java/design.xml/UncommentedEmptyMethod"/>
283267
<rule ref="rulesets/java/basic.xml/UnconditionalIfStatement"/>
284268
<rule ref="rulesets/ecmascript/unnecessary.xml/UnnecessaryBlock"/>
@@ -312,7 +296,6 @@
312296
<rule ref="rulesets/ecmascript/basic.xml/UseBaseWithParseInt"/>
313297
<rule ref="rulesets/java/design.xml/UseCollectionIsEmpty"/>
314298
<rule ref="rulesets/xsl/xpath.xml/UseConcatOnce"/>
315-
<rule ref="rulesets/java/controversial.xml/UseConcurrentHashMap"/>
316299
<rule ref="rulesets/java/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>
317300
<rule ref="rulesets/java/strings.xml/UseEqualsToCompareStrings"/>
318301
<rule ref="rulesets/java/strings.xml/UseIndexOfChar"/>
@@ -328,7 +311,6 @@
328311
<rule ref="rulesets/java/basic.xml/UselessOverridingMethod"/>
329312
<rule ref="rulesets/java/basic.xml/UselessParentheses"/>
330313
<rule ref="rulesets/java/strings.xml/UselessStringValueOf"/>
331-
<rule ref="rulesets/java/naming.xml/VariableNamingConventions"/>
332314
<rule ref="rulesets/java/braces.xml/WhileLoopsMustUseBraces"/>
333315
<rule ref="rulesets/ecmascript/braces.xml/WhileLoopsMustUseBraces"/>
334316
</ruleset>

branches/tswast-patch-1/src/main/java/com/google/gcloud/RetryHelper.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import java.util.logging.Logger;
1919

2020
/**
21-
* Utility class for retrying operations. For more details about the parameters, see
22-
* {@link RetryParams}. If the request is never successful, a {@link RetriesExhaustedException} will
23-
* be thrown.
21+
* Utility class for retrying operations.
22+
* For more details about the parameters, see {@link RetryParams}.
23+
* If the request is never successful, a {@link RetriesExhaustedException} will be thrown.
2424
*
2525
* @param <V> return value of the closure that is being run with retries
2626
*/
@@ -99,8 +99,8 @@ public static final class NonRetriableException extends RetryHelperException {
9999

100100
private static final long serialVersionUID = -2331878521983499652L;
101101

102-
NonRetriableException(Throwable ex) {
103-
super(ex);
102+
NonRetriableException(Throwable throwable) {
103+
super(throwable);
104104
}
105105
}
106106

@@ -164,12 +164,13 @@ private V doRetry() throws RetryHelperException {
164164
log.fine(this + ": attempt #" + attemptNumber + " succeeded");
165165
}
166166
return value;
167+
} catch (InterruptedException | InterruptedIOException | ClosedByInterruptException e) {
168+
if (!exceptionHandler.shouldRetry(e)) {
169+
RetryInterruptedException.propagate();
170+
}
171+
exception = e;
167172
} catch (Exception e) {
168173
if (!exceptionHandler.shouldRetry(e)) {
169-
if (e instanceof InterruptedException || e instanceof InterruptedIOException
170-
|| e instanceof ClosedByInterruptException) {
171-
RetryInterruptedException.propagate();
172-
}
173174
throw new NonRetriableException(e);
174175
}
175176
exception = e;

branches/tswast-patch-1/src/main/java/com/google/gcloud/datastore/Cursor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public String toUrlSafe() {
6565
try {
6666
return URLEncoder.encode(toPb().toString(), UTF_8.name());
6767
} catch (UnsupportedEncodingException e) {
68-
throw new RuntimeException("Unxpeced encoding exception", e);
68+
throw new IllegalStateException("Unxpeced encoding exception", e);
6969
}
7070
}
7171

@@ -77,7 +77,7 @@ public static Cursor fromUrlSafe(String urlSafe) {
7777
String utf8Str = URLDecoder.decode(urlSafe, UTF_8.name());
7878
return fromPb(DatastoreV1.Value.parseFrom(utf8Str.getBytes()));
7979
} catch (UnsupportedEncodingException | InvalidProtocolBufferException e) {
80-
throw new RuntimeException("Unxpeced decoding exception", e);
80+
throw new IllegalStateException("Unxpeced decoding exception", e);
8181
}
8282
}
8383

branches/tswast-patch-1/src/main/java/com/google/gcloud/datastore/DatastoreServiceOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static class Builder extends ServiceOptions.Builder<Builder> {
3535

3636
private String dataset;
3737
private String namespace;
38-
private boolean force = false;
38+
private boolean force;
3939
private Datastore datastore;
4040

4141
private Builder() {

branches/tswast-patch-1/src/main/java/com/google/gcloud/datastore/TransactionOption.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public IsolationLevel(Level level) {
6161
public Level level() {
6262
return level;
6363
}
64+
65+
@Override
66+
BatchWriteOption toBatchWriteOption() {
67+
return null;
68+
}
6469
}
6570

6671
TransactionOption() {
@@ -89,7 +94,5 @@ static Map<Class<? extends TransactionOption>, TransactionOption> asImmutableMap
8994
return builder.build();
9095
}
9196

92-
BatchWriteOption toBatchWriteOption() {
93-
return null;
94-
}
97+
abstract BatchWriteOption toBatchWriteOption();
9598
}

branches/tswast-patch-1/src/main/java/com/google/gcloud/datastore/Validator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
/**
1010
* Utility to validate Datastore type/values.
1111
*/
12-
class Validator {
12+
final class Validator {
1313

1414
private static final Pattern DATASET_PATTERN = Pattern.compile(
1515
"([a-z\\d\\-]{1,100}~)?([a-z\\d][a-z\\d\\-\\.]{0,99}\\:)?([a-z\\d][a-z\\d\\-]{0,99})");
1616
private static final int MAX_NAMESPACE_LENGTH = 100;
1717
private static final Pattern NAMESPACE_PATTERN =
1818
Pattern.compile(String.format("[0-9A-Za-z\\._\\-]{0,%d}", MAX_NAMESPACE_LENGTH));
1919

20+
private Validator() {
21+
// utility class
22+
}
2023

2124
static String validateDataset(String dataset) {
2225
checkArgument(!Strings.isNullOrEmpty(dataset), "dataset can't be empty or null");

branches/tswast-patch-1/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void start() throws IOException, InterruptedException {
106106
File datasetFolder = new File(gcdFolder, GCD + "/" + dataset);
107107
datasetFolder.delete();
108108

109-
// TODO: When System.getProperty("os.name").startsWith("Windows") use cmd.exe /c and gcd.cmd
109+
// TODO: if System.getProperty("os.name").startsWith("Windows") use cmd.exe /c and gcd.cmd
110110
Process temp = new ProcessBuilder()
111111
.redirectErrorStream(true)
112112
.directory(new File(gcdFolder, GCD))
@@ -159,7 +159,6 @@ public void stop() throws IOException, InterruptedException {
159159
}
160160
if (gcdPath != null) {
161161
deleteRecurse(gcdPath);
162-
gcdPath = null;
163162
}
164163
}
165164

branches/tswast-patch-1/src/test/java/com/google/gcloud/datastore/SerializationTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.ByteArrayInputStream;
1919
import java.io.ByteArrayOutputStream;
20+
import java.io.IOException;
2021
import java.io.ObjectInputStream;
2122
import java.io.ObjectOutputStream;
2223

@@ -97,7 +98,8 @@ public class SerializationTest {
9798
private static final ProjectionEntity PROJECTION_ENTITY = ProjectionEntity.fromPb(ENTITY1.toPb());
9899

99100
@SuppressWarnings("rawtypes")
100-
private Multimap<Type, Value> typeToValues = ImmutableMultimap.<Type, Value>builder()
101+
private static final Multimap<Type, Value> TYPE_TO_VALUES =
102+
ImmutableMultimap.<Type, Value>builder()
101103
.put(Type.NULL, NULL_VALUE)
102104
.put(Type.KEY, KEY_VALUE)
103105
.put(Type.STRING, STRING_VALUE)
@@ -115,7 +117,7 @@ public class SerializationTest {
115117
@Test
116118
public void testValues() throws Exception {
117119
for (Type type : Type.values()) {
118-
for (Value<?> value : typeToValues.get(type)) {
120+
for (Value<?> value : TYPE_TO_VALUES.get(type)) {
119121
Value<?> copy = serialiazeAndDeserialize(value);
120122
assertEquals(value, value);
121123
assertEquals(value, copy);
@@ -141,15 +143,14 @@ public void testTypes() throws Exception {
141143
}
142144

143145
@SuppressWarnings("unchecked")
144-
private <T> T serialiazeAndDeserialize(T obj) throws Exception {
145-
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
146-
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)) {
147-
objectOutputStream.writeObject(obj);
146+
private <T> T serialiazeAndDeserialize(T obj) throws IOException, ClassNotFoundException {
147+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
148+
try (ObjectOutputStream output = new ObjectOutputStream(bytes)) {
149+
output.writeObject(obj);
148150
}
149-
byte[] bytes = byteArrayOutputStream.toByteArray();
150-
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
151-
try (ObjectInputStream in = new ObjectInputStream(byteArrayInputStream)) {
152-
return (T) in.readObject();
151+
try (ObjectInputStream input =
152+
new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
153+
return (T) input.readObject();
153154
}
154155
}
155156
}

0 commit comments

Comments
 (0)