Skip to content

Commit bec628f

Browse files
committed
Respond to most deprecation warnings from Java runtime (up to Java 9).
The motivation is to reduce noise in the build so we can see when things go wrong. Although widespread, all are one of 2 simple types. Class.newInstance becomes Class.getDeclaredConstructor().newInstance(), and for a primitive wrapper T.valueOf(x) is preferred to new T(x).
1 parent 6a42d17 commit bec628f

28 files changed

+83
-93
lines changed

src/com/ziclix/python/sql/DataHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,14 @@ public PyObject getPyObject(ResultSet set, int col, int type) throws SQLExceptio
331331
throw createUnsupportedTypeSQLException("STRUCT", col);
332332

333333
default :
334-
throw createUnsupportedTypeSQLException(new Integer(type), col);
334+
throw createUnsupportedTypeSQLException(Integer.valueOf(type), col);
335335
}
336336

337337
return set.wasNull() || obj == null ? Py.None : obj;
338338
}
339339

340340
protected final SQLException createUnsupportedTypeSQLException(Object type, int col) {
341-
Object[] vals = {type, new Integer(col)};
341+
Object[] vals = {type, Integer.valueOf(col)};
342342
String msg = zxJDBC.getString("unsupportedTypeForColumn", vals);
343343
return new SQLException(msg);
344344
}

src/com/ziclix/python/sql/Jython22DataHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public PyObject getPyObject(ResultSet set, int col, int type) throws SQLExceptio
313313
break;
314314

315315
default :
316-
throw createUnsupportedTypeSQLException(new Integer(type), col);
316+
throw createUnsupportedTypeSQLException(Integer.valueOf(type), col);
317317
}
318318

319319
return (set.wasNull() || (obj == null)) ? Py.None : obj;
@@ -401,7 +401,7 @@ public PyObject getPyObject(CallableStatement stmt, int col, int type) throws SQ
401401
break;
402402

403403
default :
404-
throw createUnsupportedTypeSQLException(new Integer(type), col);
404+
throw createUnsupportedTypeSQLException(Integer.valueOf(type), col);
405405
}
406406

407407
return (stmt.wasNull() || (obj == null)) ? Py.None : obj;

src/com/ziclix/python/sql/connect/Connectx.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public PyObject __call__(PyObject[] args, String[] keywords) {
5858

5959
try {
6060
String klass = (String) parser.arg(0).__tojava__(String.class);
61-
datasource = Class.forName(klass).newInstance();
61+
datasource = Class.forName(klass).getDeclaredConstructor().newInstance();
6262
} catch (Exception e) {
6363
throw zxJDBC.makeException(zxJDBC.DatabaseError, "unable to instantiate datasource");
6464
}

src/com/ziclix/python/sql/pipe/Pipe.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public PyObject pipe(Source source, Sink sink) {
8787
// the purpose of the assert, but there's no need to create the buffer if I don't need it and I still
8888
// want to throw the AssertionError if required
8989
if ((sourceRunner.getCount() - sinkRunner.getCount()) != 0) {
90-
Integer[] counts = {new Integer(sourceRunner.getCount()),
91-
new Integer(sinkRunner.getCount())};
90+
Integer[] counts = {Integer.valueOf(sourceRunner.getCount()),
91+
Integer.valueOf(sinkRunner.getCount())};
9292
String msg = zxJDBC.getString("inconsistentRowCount", counts);
9393

9494
Py.assert_(Py.Zero, Py.newString(msg));

src/com/ziclix/python/sql/zxJDBC.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ protected static void _addConnectors(PyObject dict) throws PyException {
223223
String className = props.getProperty(name).trim();
224224

225225
try {
226-
connector = (PyObject) Class.forName(className).newInstance();
226+
connector =
227+
(PyObject) Class.forName(className).getDeclaredConstructor().newInstance();
227228
dict.__setitem__(name, connector);
228229
Py.writeComment("zxJDBC", "loaded connector [" + className + "] as [" + name
229230
+ "]");

src/org/python/compiler/ClassFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ public void write(OutputStream stream)
243243
AnnotationVisitor av = cw.visitAnnotation("Lorg/python/compiler/APIVersion;", true);
244244
// XXX: should imp.java really house this value or should imp.java point into
245245
// org.python.compiler?
246-
av.visit("value", new Integer(imp.getAPIVersion()));
246+
av.visit("value", Integer.valueOf(imp.getAPIVersion()));
247247
av.visitEnd();
248248

249249
av = cw.visitAnnotation("Lorg/python/compiler/MTime;", true);
250-
av.visit("value", new Long(mtime));
250+
av.visit("value", Long.valueOf(mtime));
251251
av.visitEnd();
252252

253253
if (sfilenameShort != null) {

src/org/python/compiler/CodeCompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105

106106
public class CodeCompiler extends Visitor implements Opcodes, ClassConstants {
107107

108-
private static final Object Exit = new Integer(1);
108+
private static final Object Exit = Integer.valueOf(1);
109109
private static final Object NoExit = null;
110110
private Module module;
111111
private Code code;

src/org/python/compiler/LineNumberTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void write(DataOutputStream stream) throws IOException {
3232
}
3333

3434
public void addLine(int startpc, int lineno) {
35-
lines.addElement(new Short((short) startpc));
36-
lines.addElement(new Short((short) lineno));
35+
lines.addElement(Short.valueOf((short) startpc));
36+
lines.addElement(Short.valueOf((short) lineno));
3737
}
3838

3939
public int length() {

src/org/python/compiler/Module.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class PyFloatConstant extends Constant implements ClassConstants, Opcodes {
9797

9898
@Override
9999
void get(Code c) throws IOException {
100-
c.ldc(new Double(value));
100+
c.ldc(Double.valueOf(value));
101101
c.invokestatic(p(Py.class), "newFloat", sig(PyFloat.class, Double.TYPE));
102102
}
103103

@@ -132,7 +132,7 @@ class PyComplexConstant extends Constant implements ClassConstants, Opcodes {
132132

133133
@Override
134134
void get(Code c) throws IOException {
135-
c.ldc(new Double(value));
135+
c.ldc(Double.valueOf(value));
136136
c.invokestatic(p(Py.class), "newImaginary", sig(PyComplex.class, Double.TYPE));
137137
}
138138

src/org/python/core/JavaProxyList.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
package org.python.core;
22

3-
/**
4-
* Proxy Java objects implementing java.util.List with Python methods
5-
* corresponding to the standard list type
6-
*/
7-
8-
import org.python.util.Generic;
9-
103
import java.util.ArrayList;
114
import java.util.Collection;
125
import java.util.Collections;
@@ -16,7 +9,12 @@
169
import java.util.List;
1710
import java.util.ListIterator;
1811

12+
import org.python.util.Generic;
1913

14+
/**
15+
* Proxy Java objects implementing java.util.List with Python methods corresponding to the standard
16+
* list type
17+
*/
2018
class JavaProxyList {
2119

2220
@Untraversable
@@ -35,10 +33,9 @@ protected List asList() {
3533

3634
protected List newList() {
3735
try {
38-
return (List) asList().getClass().newInstance();
39-
} catch (IllegalAccessException e) {
40-
throw Py.JavaError(e);
41-
} catch (InstantiationException e) {
36+
return (List) asList().getClass().getDeclaredConstructor().newInstance();
37+
} catch (ReflectiveOperationException | SecurityException
38+
| IllegalArgumentException e) {
4239
throw Py.JavaError(e);
4340
}
4441
}
@@ -131,8 +128,9 @@ public PyObject getSlice(int start, int stop, int step) {
131128
int n = PySequence.sliceLength(start, stop, step);
132129
List newList;
133130
try {
134-
newList = list.getClass().newInstance();
135-
} catch (Exception e) {
131+
newList = list.getClass().getDeclaredConstructor().newInstance();
132+
} catch (ReflectiveOperationException | SecurityException
133+
| IllegalArgumentException e) {
136134
throw Py.JavaError(e);
137135
}
138136
int j = 0;
@@ -556,10 +554,9 @@ public PyObject __call__(PyObject obj) {
556554
List jList = asList();
557555
List jClone;
558556
try {
559-
jClone = (List) jList.getClass().newInstance();
560-
} catch (IllegalAccessException e) {
561-
throw Py.JavaError(e);
562-
} catch (InstantiationException e) {
557+
jClone = (List) jList.getClass().getDeclaredConstructor().newInstance();
558+
} catch (ReflectiveOperationException | SecurityException
559+
| IllegalArgumentException e) {
563560
throw Py.JavaError(e);
564561
}
565562
for (Object entry : jList) {

0 commit comments

Comments
 (0)