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

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

                Author: ASF GitHub Bot
            Created on: 20/Jun/22 16:45
            Start Date: 20/Jun/22 16:45
    Worklog Time Spent: 10m 
      Work Description: github-code-scanning[bot] commented on code in PR #1624:
URL: https://github.com/apache/avro/pull/1624#discussion_r901853287


##########
lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java:
##########
@@ -131,18 +144,15 @@
 
   /**
    * Registers the given conversion to be used when reading and writing with 
this
-   * data model.
+   * data model. Conversions can also be registered automatically, as 
documented
+   * on the class {@link Conversion Conversion<T>}.
    *
    * @param conversion a logical type Conversion.
    */
   public void addLogicalTypeConversion(Conversion<?> conversion) {
     conversions.put(conversion.getLogicalTypeName(), conversion);
     Class<?> type = conversion.getConvertedType();
-    Map<String, Conversion<?>> conversions = conversionsByClass.get(type);
-    if (conversions == null) {
-      conversions = new LinkedHashMap<>();
-      conversionsByClass.put(type, conversions);
-    }
+    Map<String, Conversion<?>> conversions = 
conversionsByClass.computeIfAbsent(type, k -> new LinkedHashMap<>());

Review Comment:
   ## Possible confusion of local and field
   
   Confusing name: method [addLogicalTypeConversion](1) also refers to field 
[conversions](2) (without qualifying it with 'this').
   
   [Show more 
details](https://github.com/apache/avro/security/code-scanning/2660)





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

    Worklog Id:     (was: 783078)
    Time Spent: 1h  (was: 50m)

> Automatically register Conversion<T> classes
> --------------------------------------------
>
>                 Key: AVRO-3473
>                 URL: https://issues.apache.org/jira/browse/AVRO-3473
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: java, logical types
>            Reporter: Oscar Westra van Holthe - Kind
>            Assignee: Oscar Westra van Holthe - Kind
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 1.11.1
>
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> Manually registering a {{Conversion<T>}} is cumbersome, but necessary if 
> creating the factory requires constructor parameters.
> For most cases though, a {{Conversion<T>}} gets all the information it needs 
> from the schema. This makes it a good candidate for a SPI (using the Java 6 
> {{ServiceLoader}} class).
> This is the addendum to AVRO-3441, which does the same thing for 
> {{{}LogicalTypeFactory{}}}.
>  



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

Reply via email to