Issue 577 in protobuf: too strict check on .proto file path in Descriptors.java

145 views
Skip to first unread message

prot...@googlecode.com

unread,
Nov 15, 2013, 1:12:07 PM11/15/13
to prot...@googlegroups.com
Status: New
Owner: liu...@google.com
Labels: Type-Defect Priority-Medium

New issue 577 by li...@yahoo-inc.com: too strict check on .proto file path
in Descriptors.java
http://code.google.com/p/protobuf/issues/detail?id=577

What steps will reproduce the problem?
1. prepare files
$ cat a/aa.proto
message A {
optional string name = 1;
}

$ cat b/bb.proto
import "aa.proto";

message B {
optional string name = 1;
optional A a = 2;
}

$ cat A.java
import com.google.protobuf.*;

public class A {
public static void main(String[] args) {
Bb.B b = Bb.B.newBuilder().build();
System.out.println(TextFormat.printToUnicodeString(b));
}
}

2. compile files

$ protoc a/aa.proto --java_out .
$ protoc -Ia -I. b/bb.proto --java_out .
$ javac -cp 'protobuf-java-2.5.0.jar' *.java

3. run

java -cp 'protobuf-java-2.5.0.jar:.' A
Exception in thread "main" java.lang.ExceptionInInitializerError
at Bb$B.internalGetFieldAccessorTable(Bb.java:129)
at
com.google.protobuf.GeneratedMessage.getAllFieldsMutable(GeneratedMessage.java:105)
at
com.google.protobuf.GeneratedMessage.getAllFields(GeneratedMessage.java:153)
at com.google.protobuf.TextFormat$Printer.print(TextFormat.java:272)
at com.google.protobuf.TextFormat$Printer.access$400(TextFormat.java:248)
at com.google.protobuf.TextFormat.printToUnicodeString(TextFormat.java:146)
at A.main(A.java:6)
Caused by: java.lang.IllegalArgumentException: Invalid embedded descriptor
for "b/bb.proto".
at
com.google.protobuf.Descriptors$FileDescriptor.internalBuildGeneratedFileFrom(Descriptors.java:301)
at Bb.<clinit>(Bb.java:703)
... 7 more
Caused by: com.google.protobuf.Descriptors$DescriptorValidationException:
b/bb.proto: Dependencies passed to FileDescriptor.buildFrom() don't match
those listed in the FileDescriptorProto.
at
com.google.protobuf.Descriptors$FileDescriptor.buildFrom(Descriptors.java:246)
at
com.google.protobuf.Descriptors$FileDescriptor.internalBuildGeneratedFileFrom(Descriptors.java:299)
... 8 more


What is the expected output? What do you see instead?

I expect A.java will run successfully without exception thrown. The cause
is strict check at
http://code.google.com/p/protobuf/source/browse/trunk/java/src/main/java/com/google/protobuf/Descriptors.java?spec=svn514&r=425#245

Possible solutions:
(1) change protoc's code, not embed the file path of .proto files in
command line into generated Java source code, only embed the base file name.

or
(2) change Descriptors.java to only compare the base file name.


What version of the product are you using? On what operating system?

2.5.0, Mac OS X.

Please provide any additional information below.

It's hard to ask all .proto files to be put in same directory, currently my
workaround is to compile under each sub directory:
$ cd a; protoc --java_out .. aa.proto
$ cd ../b; protoc --java_out .. -I../a -I. bb.proto

This works but looks not intuitive.



--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

prot...@googlecode.com

unread,
Nov 15, 2013, 2:14:36 PM11/15/13
to prot...@googlegroups.com

Comment #1 on issue 577 by xiaof...@google.com: too strict check on .proto
The commands you used to compile the protos are faulty. You should use:
$ protoc -Ia a/aa.proto --java_out .
$ protoc -Ia -Ib b/bb.proto --java_out .
Let me know if you still experience problems after compiling protos like
the above.

prot...@googlecode.com

unread,
Nov 15, 2013, 11:05:40 PM11/15/13
to prot...@googlegroups.com

Comment #2 on issue 577 by li...@yahoo-inc.com: too strict check on .proto
Oh, I thought it should be "protoc -Ia aa.proto --java_out ." but it
reports "aa.proto: No such file or directory".

The command usage is a little weird, but it does work, thanks!
Reply all
Reply to author
Forward
0 new messages