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

address static analysis findings #144

Merged
merged 2 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,11 @@ private byte[] copyValueToDocument() {
@Override
public Decoder decodeBuffer() throws IOException {
byte[] documentBytes = decodeCustom(p -> ((BsonReaderDecoder) p).copyValueToDocument());
BsonReaderDecoder topDecoder = new BsonReaderDecoder(new BsonBinaryReader(ByteBuffer.wrap(documentBytes)));
Decoder objectDecoder = topDecoder.decodeObject();
objectDecoder.decodeKey(); // skip key
return objectDecoder;
try (BsonReaderDecoder topDecoder = new BsonReaderDecoder(new BsonBinaryReader(ByteBuffer.wrap(documentBytes)))) {
Decoder objectDecoder = topDecoder.decodeObject();
objectDecoder.decodeKey(); // skip key
return objectDecoder;
}
}

private static void transfer(BsonReader src, BsonWriter dest, BsonType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public <T> BeanIntrospection<T> getSerializableIntrospection(Argument<T> type) {
if (candidates.size() == 1) {
result = (BeanIntrospection<T>) candidates.iterator().next();
} else {
result = (BeanIntrospection<T>) OrderUtil.sort(candidates.stream()).findFirst().get();
result = (BeanIntrospection<T>) OrderUtil.sort(candidates.stream()).findFirst().orElse(null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.NoSuchElementException;

/**
* Implementation for deserialization of objects that uses introspection metadata.
Expand Down Expand Up @@ -790,12 +791,15 @@ public boolean hasNext() {
}

@Override
public SpecificObjectDeserializer.TokenBuffer next() {
public SpecificObjectDeserializer.TokenBuffer next() throws NoSuchElementException {
if (thisBuffer == null) {
thisBuffer = SpecificObjectDeserializer.TokenBuffer.this;
} else {
thisBuffer = thisBuffer.next;
}
if (thisBuffer == null) {
throw new NoSuchElementException();
}
return thisBuffer;
}
};
Expand Down Expand Up @@ -835,12 +839,16 @@ public boolean hasNext() {
}

@Override
public SpecificObjectDeserializer.PropertyBuffer next() {
public SpecificObjectDeserializer.PropertyBuffer next() throws NoSuchElementException {
if (thisBuffer == null) {
thisBuffer = SpecificObjectDeserializer.PropertyBuffer.this;
} else {
thisBuffer = thisBuffer.next;
}

if (thisBuffer == null) {
throw new NoSuchElementException();
}
return thisBuffer;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@ public void serialize(Encoder encoder, EncoderContext context, Argument<?> type,
throws IOException {
if (value == null) {
encoder.encodeNull();
} else {
Argument<Object> arg = Argument.of((Class) value.getClass());
getSerializer(context, value).serialize(encoder, context, arg, value);
}
Argument<Object> arg = Argument.of((Class) value.getClass());
getSerializer(context, value).serialize(encoder, context, arg, value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void serialize(Encoder encoder, EncoderContext context, Argument<? extend
encoder.encodeNull();
continue;
}
if (lastValueClass != t.getClass()) {
if (lastValueClass != t.getClass() || componentSerializer == null) {
generic = (Argument<T>) Argument.of(t.getClass());
componentSerializer = context.findSerializer(generic).createSpecific(context, generic);
lastValueClass = t.getClass();
Expand Down