[ 
https://issues.apache.org/jira/browse/AVRO-2867?focusedWorklogId=685687&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-685687
 ]

ASF GitHub Bot logged work on AVRO-2867:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 24/Nov/21 08:05
            Start Date: 24/Nov/21 08:05
    Worklog Time Spent: 10m 
      Work Description: opwvhk commented on a change in pull request #1412:
URL: https://github.com/apache/avro/pull/1412#discussion_r755784629



##########
File path: 
lang/java/compiler/src/main/java/org/apache/avro/compiler/idl/IsResolvedSchemaVisitor.java
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro.compiler.idl;
+
+import org.apache.avro.Schema;
+import org.apache.avro.compiler.schema.SchemaVisitor;
+import org.apache.avro.compiler.schema.SchemaVisitorAction;
+
+/**
+ * This visitor checks if the current schema is fully resolved.
+ */
+public final class IsResolvedSchemaVisitor implements SchemaVisitor<Boolean> {
+  boolean hasUnresolvedParts;
+
+  IsResolvedSchemaVisitor() {
+    hasUnresolvedParts = false;
+  }
+
+  @Override
+  public SchemaVisitorAction visitTerminal(Schema terminal) {
+    hasUnresolvedParts = SchemaResolver.isUnresolvedSchema(terminal);
+    return hasUnresolvedParts ? SchemaVisitorAction.TERMINATE : 
SchemaVisitorAction.CONTINUE;
+  }
+
+  @Override
+  public SchemaVisitorAction visitNonTerminal(Schema nonTerminal) {
+    hasUnresolvedParts = SchemaResolver.isUnresolvedSchema(nonTerminal);
+    if (hasUnresolvedParts) {
+      return SchemaVisitorAction.TERMINATE;
+    }
+    if (nonTerminal.getType() == Schema.Type.RECORD && 
!nonTerminal.hasFields()) {
+      // We're still initializing the type...
+      return SchemaVisitorAction.SKIP_SUBTREE;
+    }

Review comment:
       This branch is needed to handle cyclic dependencies.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 685687)
    Time Spent: 40m  (was: 0.5h)

> Avro IDL: idl2schemata throws NullPointerException on record-valued defaults
> ----------------------------------------------------------------------------
>
>                 Key: AVRO-2867
>                 URL: https://issues.apache.org/jira/browse/AVRO-2867
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java, tools
>            Reporter: Roger
>            Assignee: Oscar Westra van Holthe - Kind
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.11.1
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> I ran the idl2schemata tool (using avro-tools release-1.10.0-rc1) on this 
> avdl file:
> {code:none}
> protocol p {
>       record R {
>               S S = {"x": 1234};
>       }
>       record S {
>               int x;
>       }
> }
> {code}
> I get the following exception:
> {code:none}
> Exception in thread "main" java.lang.NullPointerException
>       at 
> org.apache.avro.util.internal.JacksonUtils.toObject(JacksonUtils.java:164)
>       at org.apache.avro.Schema$Field.defaultVal(Schema.java:632)
>       at 
> org.apache.avro.compiler.idl.ResolvingVisitor.afterVisitNonTerminal(ResolvingVisitor.java:143)
>       at 
> org.apache.avro.compiler.schema.Schemas.lambda$visitNonTerminal$1(Schemas.java:189)
>       at org.apache.avro.compiler.schema.Schemas.visit(Schemas.java:117)
>       at 
> org.apache.avro.compiler.idl.SchemaResolver.resolve(SchemaResolver.java:99)
>       at org.apache.avro.compiler.idl.Idl.CompilationUnit(Idl.java:135)
>       at org.apache.avro.tool.IdlToSchemataTool.run(IdlToSchemataTool.java:49)
>       at org.apache.avro.tool.Main.run(Main.java:67)
>       at org.apache.avro.tool.Main.main(Main.java:56)
> {code}
> I would expect the following output instead:
> {code:json}
> {
>   "type" : "record",
>   "name" : "R",
>   "fields" : [ {
>     "name" : "S",
>     "default": {"x": 1234},
>     "type" : {
>       "type" : "record",
>       "name" : "S",
>       "fields" : [ {
>         "name" : "x",
>         "type" : "int"
>       } ]
>     }
>   } ]
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to