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

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

                Author: ASF GitHub Bot
            Created on: 20/Jun/22 16:43
            Start Date: 20/Jun/22 16:43
    Worklog Time Spent: 10m 
      Work Description: RyanSkraba commented on code in PR #1624:
URL: https://github.com/apache/avro/pull/1624#discussion_r901815988


##########
lang/java/avro/src/main/java/org/apache/avro/Conversions.java:
##########
@@ -106,11 +106,12 @@ public GenericFixed toFixed(BigDecimal value, Schema 
schema, LogicalType type) {
       byte fillByte = (byte) (value.signum() < 0 ? 0xFF : 0x00);
       byte[] unscaled = value.unscaledValue().toByteArray();
       byte[] bytes = new byte[schema.getFixedSize()];
-      int offset = bytes.length - unscaled.length;
+      int unscaledLength = unscaled.length;
+      int offset = bytes.length - unscaledLength;
 
-      // Fill the front of the array and copy remaining with unscaled values
+      // Fill the front with the filler and copy the unscaled value into the 
remainder
       Arrays.fill(bytes, 0, offset, fillByte);
-      System.arraycopy(unscaled, 0, bytes, offset, bytes.length - offset);
+      System.arraycopy(unscaled, 0, bytes, offset, unscaledLength);

Review Comment:
   nice catch!



##########
lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java:
##########
@@ -184,11 +195,11 @@ public <T> Conversion<T> getConversionByClass(Class<T> 
datumClass, LogicalType l
    * @return the conversion for the logical type, or null
    */
   @SuppressWarnings("unchecked")
-  public Conversion<Object> getConversionFor(LogicalType logicalType) {

Review Comment:
   Do you have any idea if changing this signature is backwards 
binary-compatible ?  If not, we might need to bump these lines of code to a 
major release.



##########
lang/java/avro/src/test/java/org/apache/avro/CustomType.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+public final class CustomType {
+  private final String name;
+
+  public CustomType(CharSequence name) {
+    this.name = name.toString();
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  @Override
+  public int hashCode() {
+    return super.hashCode();

Review Comment:
   ```suggestion
       return Objects.hashCode(name);
   ```
   Just a nitpick to meet the hashCode contract!





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

    Worklog Id:     (was: 783076)
    Time Spent: 50m  (was: 40m)

> 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
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 1.11.1
>
>          Time Spent: 50m
>  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