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/07/04 17:03:00 UTC
[jira] [Work logged] (AVRO-3520) CustomEncoding doesn't expose the read schema
[ https://issues.apache.org/jira/browse/AVRO-3520?focusedWorklogId=787663&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-787663 ]
ASF GitHub Bot logged work on AVRO-3520:
----------------------------------------
Author: ASF GitHub Bot
Created on: 04/Jul/22 17:02
Start Date: 04/Jul/22 17:02
Worklog Time Spent: 10m
Work Description: github-code-scanning[bot] commented on code in PR #1692:
URL: https://github.com/apache/avro/pull/1692#discussion_r913153611
##########
lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectCustomEncoderFieldAccess.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.reflect;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.apache.avro.Schema;
+import org.apache.avro.file.CodecFactory;
+import org.apache.avro.file.DataFileStream;
+import org.apache.avro.file.DataFileWriter;
+import org.apache.avro.io.DatumReader;
+import org.apache.avro.io.Decoder;
+import org.apache.avro.io.Encoder;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Arrays;
+import java.util.Collections;
+
+public class TestReflectCustomEncoderFieldAccess {
+
+ @Test
+ public void testReadSchemaIsSet() throws IOException {
+ Custom in = new Custom("hello", "world");
+ byte[] encoded = write(in);
+
+ CustomEncoder.SCHEMA = CustomEncoder.v2Schema;
+ Custom decoded = read(encoded);
+ assertNotNull(decoded);
+ assertEquals("hello", decoded.v1Field);
+ assertNull(decoded.v2Field);
+
+ ReflectData.get().removeFromSchemaClassCache(Wrapper.class);
+ encoded = write(in);
+
+ decoded = read(encoded);
+ assertNotNull(decoded);
+ assertEquals("hello", decoded.v1Field);
+ assertEquals("world", decoded.v2Field);
+ }
+
+ private Custom read(byte[] toDecode) throws IOException {
+ DatumReader<Wrapper> datumReader = new ReflectDatumReader<>();
+ DataFileStream<Wrapper> dataFileReader = new DataFileStream<>(
+ new ByteArrayInputStream(toDecode, 0, toDecode.length), datumReader);
+ Wrapper wrapper = null;
+ if (dataFileReader.hasNext()) {
+ wrapper = dataFileReader.next();
+ }
+ return wrapper.custom;
Review Comment:
## Dereferenced variable may be null
Variable [wrapper](1) may be null here because of [this](2) assignment.
[Show more details](https://github.com/apache/avro/security/code-scanning/2725)
Issue Time Tracking
-------------------
Worklog Id: (was: 787663)
Time Spent: 20m (was: 10m)
> CustomEncoding doesn't expose the read schema
> ---------------------------------------------
>
> Key: AVRO-3520
> URL: https://issues.apache.org/jira/browse/AVRO-3520
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.11.0
> Reporter: Colin
> Priority: Major
> Labels: pull-request-available
> Attachments: patchTest.txt
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> Currently it is not possible to detect a schema change when using `CustomEncoding<T>`.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)