Uploaded image for project: 'Avro'
  1. Avro
  2. AVRO-2139

Unable to use the copy builder with @java-class annotated generated classes

    Details

    • Type: Bug
    • Status: Open
    • Priority: Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.8.2
    • Fix Version/s: None
    • Component/s: java
    • Labels:
      None

      Description

      Description:

      When I'm using a schema with an @java-class, I can't seem to be using the 'copy' builder.

      I think a piece of code says more than a thousands words:

      .avdl snippet:

      ...
        record Money {
          Currency currency;
          @java-class("java.math.BigDecimal")
          string amount;
        }
      ...
      

      Test:

      @Test
      void test_copy_builder() {
          Money original = Money.newBuilder()
                  .setAmount(BigDecimal.TEN)
                  .setCurrency(Currency.EUR)
                  .build();
      
          Money duplicate = Money.newBuilder(original).build();
      
          assertThat(duplicate, is(equalTo(original)));
      }
      

      Result:

      java.lang.ClassCastException: org.apache.avro.util.Utf8 cannot be cast to java.math.BigDecimal
      
      	at avro.moneyou.midlayer.common.financial.Money$Builder.<init>(Money.java:193)
      	at avro.moneyou.midlayer.common.financial.Money$Builder.<init>(Money.java:155)
      	at avro.moneyou.midlayer.common.financial.Money.newBuilder(Money.java:149)
      	at avro.moneyou.midlayer.common.financial.MoneyTest.test_copy_builder(MoneyTest.java:20)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:389)
      	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
      	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:167)
      	at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
      	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:163)
      ...
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              aukevanleeuwen Auke van Leeuwen
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: