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

IPROTO-351 TypeId must be parsed before the compatibility check #294

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ private List<FileDescriptor> resolveImports(List<String> dependencies, Resolutio
}

private void collectDescriptors(Descriptor descriptor, ResolutionContext resolutionContext) {
descriptor.setFileDescriptor(this);
fileNamespace.put(descriptor.getFullName(), descriptor);
resolutionContext.addGenericDescriptor(descriptor);

Expand All @@ -301,7 +300,6 @@ private void collectDescriptors(Descriptor descriptor, ResolutionContext resolut
}

private void collectEnumDescriptors(EnumDescriptor enumDescriptor, ResolutionContext resolutionContext) {
enumDescriptor.setFileDescriptor(this);
fileNamespace.put(enumDescriptor.getFullName(), enumDescriptor);
resolutionContext.addGenericDescriptor(enumDescriptor);
}
Expand Down Expand Up @@ -425,6 +423,14 @@ public void checkCompatibility(FileDescriptor that, boolean strict) {
}
}

public void parseAnnotations() {
if (configuration == null) {
throw new IllegalStateException("FileDescriptor.setConfiguration() must be invoked before parsing the annotations");
}
messageTypes.forEach(descriptor -> descriptor.setFileDescriptor(this));
enumTypes.forEach(enumDescriptor -> enumDescriptor.setFileDescriptor(this));
}

@Override
public String toString() {
return "FileDescriptor{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public static ProtoLock readLockFile(InputStream is, Configuration configuration
messageBuilders.values().forEach(fdb::addMessage);
FileDescriptor fd = fdb.build();
fd.setConfiguration(configuration);
fd.parseAnnotations();
descriptors.add(fd);
}
return new ProtoLock(descriptors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public Map<String, FileDescriptor> parse(FileDescriptorSource fileDescriptorSour
try {
FileDescriptor fileDescriptor = ProtoParser.parse(fileName, new StringReader(entry.getValue()), configuration);
fileDescriptor.setConfiguration(configuration);
fileDescriptor.parseAnnotations();
fileDescriptorMap.put(fileName, fileDescriptor);
} catch (DescriptorParserException e) {
reportParsingError(fileDescriptorSource, fileDescriptorMap, fileName, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public void testGenericMessage() {
.hasMessageContaining("IPROTO000008");
}

@Test
public void testRegisterTwice() {
var ctx = ProtobufUtil.newSerializationContext();
MapSchema.INSTANCE.registerSchema(ctx);
MapSchema.INSTANCE.registerMarshallers(ctx);

MapSchema.INSTANCE.registerSchema(ctx);
MapSchema.INSTANCE.registerMarshallers(ctx);
}

@Test
public void testMaps() throws IOException {
var ctx = ProtobufUtil.newSerializationContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.infinispan.protostream.integrationtests.processor.marshaller.model;

import org.infinispan.protostream.annotations.Proto;
import org.infinispan.protostream.annotations.ProtoTypeId;

@ProtoTypeId(111111) // large enough so it does not conflict
@Proto
public enum SimpleEnum {

Expand Down