Skip to content

Commit 05da92b

Browse files
committed
AVRO-4261: [Java] Replace deprecated Class.newInstance() calls
Replace Class.newInstance() (deprecated since Java 9) with getDeclaredConstructor().newInstance() in Perf.java and ThriftData.java. Also remove stale 'Java 8' qualifier from SpecificCompiler javadoc.
1 parent 3c323e7 commit 05da92b

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ public static String generateGetMethod(Schema schema, Field field) {
12251225
}
12261226

12271227
/**
1228-
* Generates the name of a field accessor method that returns a Java 8 Optional.
1228+
* Generates the name of a field accessor method that returns an Optional.
12291229
*
12301230
* @param schema the schema in which the field is defined.
12311231
* @param field the field for which to generate the accessor name.

lang/java/ipc/src/test/java/org/apache/avro/io/Perf.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ public static void main(String[] args) throws Exception {
194194
String a = args[i];
195195
TestDescriptor t = ALL_TESTS.get(a);
196196
if (null != t) {
197-
tests.add(t.test.newInstance());
197+
tests.add(t.test.getDeclaredConstructor().newInstance());
198198
continue;
199199
}
200200
List<TestDescriptor> lt = BATCHES.get(a);
201201
if (null != lt) {
202202
for (TestDescriptor td : lt) {
203-
tests.add(td.test.newInstance());
203+
tests.add(td.test.getDeclaredConstructor().newInstance());
204204
}
205205
continue;
206206
}
@@ -257,7 +257,7 @@ public static void main(String[] args) throws Exception {
257257
if (tests.isEmpty()) {
258258
for (Map.Entry<String, TestDescriptor> entry : ALL_TESTS.entrySet()) {
259259
TestDescriptor t = entry.getValue();
260-
Test test = t.test.newInstance();
260+
Test test = t.test.getDeclaredConstructor().newInstance();
261261
tests.add(test);
262262
}
263263
}

lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public Object newRecord(Object old, Schema schema) {
163163
return super.newRecord(old, schema); // punt to generic
164164
if (c.isInstance(old))
165165
return old; // reuse instance
166-
return c.newInstance(); // create new instance
166+
return c.getDeclaredConstructor().newInstance(); // create new instance
167167
} catch (Exception e) {
168168
throw new RuntimeException(e);
169169
}

0 commit comments

Comments
 (0)