Skip to content

Commit

Permalink
Using getDeclaredConstructor().newInstance()
Browse files Browse the repository at this point in the history
Since Java 9, newInstance() is deprecated
  • Loading branch information
ata4 committed Dec 31, 2019
1 parent 1f72699 commit bbe61b8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/info/ata4/bsplib/BspFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public void loadStaticProps() {

// check if the size is correct
if (structClass != null) {
int propStaticSizeActual = structClass.newInstance().getSize();
int propStaticSizeActual = structClass.getDeclaredConstructor().newInstance().getSize();
if (propStaticSizeActual != propStaticSize) {
L.log(Level.WARNING, "Static prop struct size mismatch: expected {0}, got {1} (using {2})",
new Object[]{propStaticSize, propStaticSizeActual, structClass.getSimpleName()});
Expand All @@ -443,7 +443,7 @@ public void loadStaticProps() {
bspData.staticProps = new ArrayList<>(propStaticCount);

for (int i = 0; i < propStaticCount; i++) {
DStaticProp sp = structClass.newInstance();
DStaticProp sp = structClass.getDeclaredConstructor().newInstance();
sp.read(in);

if (numFillBytes > 0) {
Expand All @@ -461,7 +461,7 @@ public void loadStaticProps() {
checkRemaining(in);
} catch (IOException ex) {
lumpError(sprpLump, ex);
} catch (InstantiationException | IllegalAccessException ex) {
} catch (ReflectiveOperationException ex) {
L.log(Level.SEVERE, "Lump struct class error", ex);
}
}
Expand Down Expand Up @@ -866,13 +866,13 @@ private <E extends DStruct> List<E> loadLump(LumpType lumpType, Class<E> struct)
DataReader in = DataReaders.forByteBuffer(lump.getBuffer());

try {
final int structSize = struct.newInstance().getSize();
final int structSize = struct.getDeclaredConstructor().newInstance().getSize();
final int packetCount = lump.getLength() / structSize;

List<E> packets = new ArrayList<>(packetCount);

for (int i = 0; i < packetCount; i++) {
E packet = struct.newInstance();
E packet = struct.getDeclaredConstructor().newInstance();

long pos = in.position();
packet.read(in);
Expand All @@ -890,7 +890,7 @@ private <E extends DStruct> List<E> loadLump(LumpType lumpType, Class<E> struct)
return packets;
} catch (IOException ex) {
lumpError(lump, ex);
} catch (IllegalAccessException | InstantiationException ex) {
} catch (ReflectiveOperationException ex) {
L.log(Level.SEVERE, "Lump struct class error", ex);
}

Expand Down

0 comments on commit bbe61b8

Please sign in to comment.