Skip to content

Commit

Permalink
IPROTO-233 Fix MarshallerByteCodeGenerator on JDK 8 and 9+
Browse files Browse the repository at this point in the history
  • Loading branch information
tristantarrant authored and pruivo committed Apr 26, 2022
1 parent 0103ab9 commit 189a2f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.infinispan.protostream.EnumMarshaller;
import org.infinispan.protostream.ProtobufTagMarshaller;
import org.infinispan.protostream.SerializationContext;
import org.infinispan.protostream.annotations.impl.types.XClass;
import org.infinispan.protostream.annotations.impl.types.XTypeFactory;
import org.infinispan.protostream.containers.IndexedElementContainerAdapter;
import org.infinispan.protostream.containers.IterableElementContainerAdapter;
Expand Down Expand Up @@ -144,12 +145,20 @@ private Class<EnumMarshaller> generateEnumMarshaller(ProtoEnumTypeMetadata petm)
ctEncodeMethod.setBody(encodeSrc);
marshallerImpl.addMethod(ctEncodeMethod);

Class<EnumMarshaller> generatedMarshallerClass = (Class<EnumMarshaller>) marshallerImpl.toClass(petm.getAnnotatedClass().asClass());
Class<EnumMarshaller> generatedMarshallerClass = (Class<EnumMarshaller>) toClass(marshallerImpl, petm.getAnnotatedClass());
marshallerImpl.detach();

return generatedMarshallerClass;
}

private Class<?> toClass(CtClass marshallerImpl, XClass petm) throws CannotCompileException {
if (System.getProperty("java.version").startsWith("1.8")) {
return marshallerImpl.toClass();
} else {
return marshallerImpl.toClass(petm.asClass());
}
}

/**
* Generates an implementation of {@link ProtobufTagMarshaller} as a static nested class in the message class to be
* marshalled. The InnerClasses attribute of the outer class is not altered, so this is not officially considered a
Expand Down Expand Up @@ -219,7 +228,7 @@ private Class<ProtobufTagMarshaller> generateMessageMarshaller(ProtoMessageTypeM
ctWriteMethod.setBody(writeBody);
marshallerImpl.addMethod(ctWriteMethod);

Class<ProtobufTagMarshaller> generatedMarshallerClass = (Class<ProtobufTagMarshaller>) marshallerImpl.toClass(pmtm.getAnnotatedClass().asClass());
Class<ProtobufTagMarshaller> generatedMarshallerClass = (Class<ProtobufTagMarshaller>) toClass(marshallerImpl, pmtm.getAnnotatedClass());
marshallerImpl.detach();

return generatedMarshallerClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
}

private void ensureRequiredEnv() {
if (getJavaMajorVersion() < 9) {
if (getJavaMajorVersion() < 9 && !Boolean.getBoolean("org.infinispan.protostream.skipAnnotationCompilerCheck")) {
reportWarning(null, "Please ensure you use at least Java ver. 9 for compilation in order to avoid various " +
"compiler related bugs from older Java versions that impact the AutoProtoSchemaBuilder annotation " +
"processor (you can still set the output target to 8 or above).");
"processor (you can still set the output target to 8 or above). To hide this warning set the " +
"`org.infinispan.protostream.skipAnnotationCompilerCheck` system property");
}

Version procVersion = Version.getVersion(AutoProtoSchemaBuilder.class);
Expand Down

0 comments on commit 189a2f5

Please sign in to comment.