You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/05/24 09:29:00 UTC

[jira] [Work logged] (AVRO-3486) Protocol namespace not parsed correctly if protocol is defined by full name

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

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

                Author: ASF GitHub Bot
            Created on: 24/May/22 09:28
            Start Date: 24/May/22 09:28
    Worklog Time Spent: 10m 
      Work Description: Christophe-LeSaec commented on code in PR #1637:
URL: https://github.com/apache/avro/pull/1637#discussion_r880272632


##########
lang/java/avro/src/main/java/org/apache/avro/Protocol.java:
##########
@@ -275,15 +274,29 @@ public Protocol(Protocol p) {
 
   public Protocol(String name, String doc, String namespace) {
     super(PROTOCOL_RESERVED);
-    this.name = name;
+    setName(name, namespace);
     this.doc = doc;
-    this.namespace = namespace;
   }
 
   public Protocol(String name, String namespace) {
     this(name, null, namespace);
   }
 
+  private void setName(String name, String namespace) {
+    int lastDot = name.lastIndexOf('.');
+    if (lastDot < 0) {
+      this.name = name;
+      this.namespace = namespace;
+    } else {
+      this.name = name.substring(lastDot) + 1;
+      this.namespace = name.substring(0, lastDot);
+    }
+    if ("".equals(this.namespace)) {

Review Comment:
   So
   ```java
   if (this.namespace != null && this.namespace.isEmpty()) {
   ```



##########
lang/java/avro/src/main/java/org/apache/avro/Protocol.java:
##########
@@ -275,15 +274,29 @@ public Protocol(Protocol p) {
 
   public Protocol(String name, String doc, String namespace) {
     super(PROTOCOL_RESERVED);
-    this.name = name;
+    setName(name, namespace);
     this.doc = doc;
-    this.namespace = namespace;
   }
 
   public Protocol(String name, String namespace) {
     this(name, null, namespace);
   }
 
+  private void setName(String name, String namespace) {
+    int lastDot = name.lastIndexOf('.');
+    if (lastDot < 0) {
+      this.name = name;
+      this.namespace = namespace;
+    } else {

Review Comment:
   What if namespace is "java" and name is "lang.String" 
   Here, a suggestion :
   ```java
           StringBuilder namespaceBuilder = new StringBuilder((namespace != null) ? namespace : "");
           if (namespaceBuilder.length() > 0 && namespaceBuilder.charAt(namespaceBuilder.length() - 1) != '.') {
               namespaceBuilder.append('.');
           }
           namespaceBuilder.append(name.substring(0, lastDot));
          this.namespace = namespaceBuilder.toString();
   ```





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

    Worklog Id:     (was: 773935)
    Time Spent: 20m  (was: 10m)

> Protocol namespace not parsed correctly if protocol is defined by full name
> ---------------------------------------------------------------------------
>
>                 Key: AVRO-3486
>                 URL: https://issues.apache.org/jira/browse/AVRO-3486
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.11.1
>            Reporter: Oscar Westra van Holthe - Kind
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 1.12.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> When parsing a protocol with a full name (but no namespace), the namespace is not parsed correctly.
> The spec for [Protocol Declaration|https://avro.apache.org/docs/current/spec.html#Protocol+Declaration] says:
> {quote}The name and namespace qualification rules defined for schema objects apply to protocols as well.
> {quote}
> However, a protocol namespace can only be specified using the {{namespace}} attribute, not by using a full name like {{qualified.Name}} as protocol name.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)