Skip to content
Merged
Changes from all commits
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
17 changes: 2 additions & 15 deletions java/core/src/main/java/com/google/protobuf/Protobuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ <T> Schema<T> schemaFor(Class<T> messageType) {
Schema<T> schema = (Schema<T>) schemaCache.get(messageType);
if (schema == null) {
schema = schemaFactory.createSchema(messageType);
checkNotNull(schema, "schema");
@SuppressWarnings("unchecked")
Schema<T> previous = (Schema<T>) registerSchema(messageType, schema);
Schema<T> previous = (Schema<T>) schemaCache.putIfAbsent(messageType, schema);
if (previous != null) {
// A new schema was registered by another thread.
schema = previous;
Expand All @@ -68,20 +69,6 @@ <T> Schema<T> schemaFor(T message) {
return schemaFor((Class<T>) message.getClass());
}

/**
* Registers the given schema for the message type only if a schema was not already registered.
*
* @param messageType the type of message on which the schema operates.
* @param schema the schema for the message type.
* @return the previously registered schema, or {@code null} if the given schema was successfully
* registered.
*/
private Schema<?> registerSchema(Class<?> messageType, Schema<?> schema) {
checkNotNull(messageType, "messageType");
checkNotNull(schema, "schema");
return schemaCache.putIfAbsent(messageType, schema);
}

private Protobuf() {
schemaFactory = new ManifestSchemaFactory();
}
Expand Down
Loading