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

Stack overflow when generating Protobuf schema on class containing cyclic type definition #140

Closed
acommuni opened this issue Jun 25, 2018 · 4 comments
Labels

Comments

@acommuni
Copy link

I'm trying to generate schema from class on the following class :

 class B {
        public boolean isC() {
            return c;
        }

        public void setC(boolean c) {
            this.c = c;
        }

        private boolean c = true;

    }

    class A {
        private OffsetDateTime date;
        private List<B> b = Arrays.asList(new B[] { new B(), new B() });
        private B[] b2 = new B[] { new B(), new B() };

        public List<B> getB() {
            return b;
        }

        public void setB(List<B> b) {
            this.b = b;
        }

        public B[] getB2() {
            return b2;
        }

        public void setB2(B[] b2) {
            this.b2 = b2;
        }

        public OffsetDateTime getDate() {
            return date;
        }

        public void setDate(OffsetDateTime date) {
            this.date = date;
        }
    }

I generate the class with this :

private JsonProvider provider = new JacksonProvider();
    private ProtobufMapper mapper = new ProtobufMapper();

Class<?> cls = A.class;
        ProtobufSchema schemaWrapper = protoBuffCache.get(cls);
        schemaWrapper = mapper.generateSchemaFor(cls);

The stack loops on OffsetDatetime resolution


TypeResolver._resolve(MessageElement) line: 134	
TypeResolver._findAnyResolved(FieldElement, String) line: 182	
TypeResolver._resolve(MessageElement) line: 134	
TypeResolver._findAnyResolved(FieldElement, String) line: 182	
TypeResolver._resolve(MessageElement) line: 134	
TypeResolver._findAnyResolved(FieldElement, String) line: 182	
TypeResolver._resolve(MessageElement) line: 134	
TypeResolver._findAnyResolved(FieldElement, String) line: 182	
TypeResolver._resolve(MessageElement) line: 134	
TypeResolver._findAnyResolved(FieldElement, String) line: 182	
TypeResolver._resolve(MessageElement) line: 134	
TypeResolver.resolve(MessageElement) line: 93	
NativeProtobufSchema.forFirstType() line: 81	
ProtobufSchemaGenerator.getGeneratedSchema(boolean) line: 49	
ProtobufSchemaGenerator.getGeneratedSchema() line: 32	
ProtobufMapper.generateSchemaFor(Class<?>) line: 111	
@cowtowncoder
Copy link
Member

Quick question: are you registering Java 8 date/time module (jackson-datatype-jsr310)? Without it, your schema generation would probably not work as expected, as Java 8 datatypes would not be supported explicitly.

@acommuni
Copy link
Author

It works better now. Thanks ! It would be nice to have loop detection and a log notifying which class or field is the root of the loop

@cowtowncoder
Copy link
Member

@acommuni I agree, loop should be detected and gracefully handled. If I have time, I hope to figure out a simple reproduction, using simple POJO (to avoid Java 8 dependency for 2.x)

@cowtowncoder cowtowncoder changed the title Stack overflow when generating protobuff schema on class containing OffsetDatetime field Stack overflow when generating Protobuf schema on class containing OffsetDatetime field Nov 28, 2018
@cowtowncoder
Copy link
Member

Interesting. Direct self-reference is fine, and did not cause issue. It's only loop through at least one class. At least I can reproduce it now, initially had some issues.

cowtowncoder added a commit that referenced this issue Nov 29, 2018
@cowtowncoder cowtowncoder changed the title Stack overflow when generating Protobuf schema on class containing OffsetDatetime field Stack overflow when generating Protobuf schema on class containing cyclic type definition Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants