You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/06/20 16:43:42 UTC

[GitHub] [avro] RyanSkraba commented on a diff in pull request #1624: AVRO-3473: ServiceLoader for Conversion

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!



-- 
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: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org