Skip to content

Commit

Permalink
IPROTO-227 Better errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tristantarrant authored and anistor committed Feb 4, 2022
1 parent 47924d9 commit 08d8a44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ public void scanMemberAnnotations() {
}
int number = getNumber(annotation, ec);
if (membersByNumber.containsKey(number)) {
throw new ProtoSchemaBuilderException("Found duplicate definition of Protobuf enum tag " + number + " on enum constant: " + getAnnotatedClassName() + '.' + ec.getName());
throw new ProtoSchemaBuilderException("Found duplicate definition of Protobuf enum tag " + number + " on enum constant: " + getAnnotatedClassName() + '.' + ec.getName()
+ " clashes with " + membersByNumber.get(number).getJavaEnumName());
}
String name = annotation.name();
if (name.isEmpty()) {
name = ec.getName();
}
if (membersByName.containsKey(name)) {
throw new ProtoSchemaBuilderException("Found duplicate definition of Protobuf enum constant " + name + " on enum constant: " + getAnnotatedClassName() + '.' + ec.getName());
throw new ProtoSchemaBuilderException("Found duplicate definition of Protobuf enum constant " + name + " on enum constant: " + getAnnotatedClassName() + '.' + ec.getName()
+ " clashes with " + membersByName.get(name).getJavaEnumName());
}
ProtoEnumValueMetadata pevm = new ProtoEnumValueMetadata(number, name,
ec.getOrdinal(), getJavaClassName() + '.' + ec.getName(), ec.getProtoDocs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,26 +357,26 @@ private void discoverFields(XClass clazz, Set<XClass> examinedClasses) {
for (XField field : clazz.getDeclaredFields()) {
if (field.getAnnotation(ProtoUnknownFieldSet.class) != null) {
if (isAdapter) {
throw new ProtoSchemaBuilderException("No ProtoStream annotations should be present on fields when @ProtoAdapter is present on a class : " + field);
throw new ProtoSchemaBuilderException("No ProtoStream annotations should be present on fields when @ProtoAdapter is present on a class : " + clazz.getCanonicalName() + '.' + field);
}
if (unknownFieldSetField != null || unknownFieldSetGetter != null || unknownFieldSetSetter != null) {
throw new ProtoSchemaBuilderException("The @ProtoUnknownFieldSet annotation should not occur more than once in a class and its superclasses and superinterfaces : " + field);
throw new ProtoSchemaBuilderException("The @ProtoUnknownFieldSet annotation should not occur more than once in a class and its superclasses and superinterfaces : " + clazz.getCanonicalName() + '.' + field);
}
unknownFieldSetField = field;
} else {
ProtoField annotation = field.getAnnotation(ProtoField.class);
if (annotation != null) {
if (isAdapter) {
throw new ProtoSchemaBuilderException("No ProtoStream annotations should be present on fields when @ProtoAdapter is present on a class : " + field);
throw new ProtoSchemaBuilderException("No ProtoStream annotations should be present on fields when @ProtoAdapter is present on a class : " + clazz.getCanonicalName() + '.' + field);
}
if (field.isStatic()) {
throw new ProtoSchemaBuilderException("Static fields cannot be @ProtoField annotated: " + field);
throw new ProtoSchemaBuilderException("Static fields cannot be @ProtoField annotated: " + clazz.getCanonicalName() + '.' + field);
}
if (factory == null && field.isFinal()) { //todo [anistor] maybe allow this
throw new ProtoSchemaBuilderException("Final fields cannot be @ProtoField annotated: " + field);
throw new ProtoSchemaBuilderException("Final fields cannot be @ProtoField annotated: " + clazz.getCanonicalName() + '.' + field);
}
if (field.isPrivate()) {
throw new ProtoSchemaBuilderException("Private fields cannot be @ProtoField annotated: " + field);
throw new ProtoSchemaBuilderException("Private fields cannot be @ProtoField annotated: " + clazz.getCanonicalName() + '.' + field);
}
int number = getNumber(annotation, field);
String fieldName = annotation.name();
Expand Down

0 comments on commit 08d8a44

Please # to comment.