You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And the default value of pkg is protected Package pkg = Package.DEFAULT;, meanwhile the implements of getValue in Package.DEFAULT return ""(empty string).
So when use ImportImpl to parse a proto file without a "package" declared, the Message and other elements in the proto file will be registered as a fullyQualifiedName starts with double point(".."):
As that, When proto file "A" which declares "package" as "aaaa.bbb", imports another proto file "B" which no "package" declared, it will not be able to found Message XXX declared in B, because the XXX is registered as "..XXX", and the look up for XXX is only for ".aaa.bbb.XXX", ".aaa.XXX", ".XXX":
// io.protostuff.compiler.parser.TypeResolverPostProcessorpublicstaticDeque<String> createScopeLookupList(UserTypeContainercontainer) {
Stringnamespace = container.getNamespace();
Deque<String> scopeLookupList = newArrayDeque<>();
intend = 0;
while (end >= 0) {
end = namespace.indexOf('.', end);
if (end >= 0) {
end++;
Stringscope = namespace.substring(0, end);
scopeLookupList.addFirst(scope);
}
}
returnscopeLookupList;
}
privateUserTyperesolveUserType(Elementsource, ProtoContextcontext, Deque<String> scopeLookupList, StringtypeName) {
UserTypefieldType = null;
// A leading '.' (for example, .foo.bar.Baz) means to start from the outermost scopeif (typeName.startsWith(".")) {
UserTypetype = (UserType) context.resolve(typeName);
if (type != null) {
fieldType = type;
}
} else {
for (Stringscope : scopeLookupList) {
StringfullTypeName = scope + typeName;
UserTypetype = (UserType) context.resolve(fullTypeName);
if (type != null) {
fieldType = type;
break;
}
}
}
if (fieldType == null) {
Stringformat = "Unresolved reference: '%s'";
thrownewParserException(source, format, typeName);
}
returnfieldType;
}
I think it is legal to create a proto file without "package". So I wonder:
If there are a bug with proto file no "package" declared?
Is it more rational to make the pkg of Proto as null or change the implement of getNamespace to return "." when pkg == Package.DEFAULT?
The text was updated successfully, but these errors were encountered:
When I use protostuff-parser to parse proto file, A
io.protostuff.compiler.parser.ParserException
raised.I read the code and found the reason:
The io.protostuff.compiler.model.Proto.getNamespace() implements as this:
And the default value of
pkg
isprotected Package pkg = Package.DEFAULT;
, meanwhile the implements ofgetValue
in Package.DEFAULT return ""(empty string).So when use
ImportImpl
to parse a proto file without a "package" declared, the Message and other elements in the proto file will be registered as a fullyQualifiedName starts with double point(".."):As that, When proto file "A" which declares "package" as "aaaa.bbb", imports another proto file "B" which no "package" declared, it will not be able to found Message XXX declared in B, because the XXX is registered as "..XXX", and the look up for XXX is only for ".aaa.bbb.XXX", ".aaa.XXX", ".XXX":
I think it is legal to create a proto file without "package". So I wonder:
pkg
of Proto asnull
or change the implement ofgetNamespace
to return "." when pkg == Package.DEFAULT?The text was updated successfully, but these errors were encountered: