Skip to content

Commit

Permalink
Merge pull request #4179 from melissalinkert/tools-warnings
Browse files Browse the repository at this point in the history
Fix Java 9+ deprecation warnings in smaller components
  • Loading branch information
dgault authored Apr 26, 2024
2 parents 7f7c002 + f63aa7b commit 6a0329f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public void createReader() {
// create reader of a specific format type
try {
Class<?> c = Class.forName("loci.formats.in." + format + "Reader");
reader = (IFormatReader) c.newInstance();
reader = (IFormatReader) c.getDeclaredConstructor().newInstance();
}
catch (ClassNotFoundException exc) {
LOGGER.warn("Unknown reader: {}", format);
Expand All @@ -377,7 +377,7 @@ public void createReader() {
LOGGER.warn("Cannot instantiate reader: {}", format);
LOGGER.debug("", exc);
}
catch (IllegalAccessException exc) {
catch (ReflectiveOperationException exc) {
LOGGER.warn("Cannot access reader: {}", format);
LOGGER.debug("", exc);
}
Expand Down
5 changes: 2 additions & 3 deletions components/formats-api/src/loci/formats/ImageReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ public ImageReader(ClassList<IFormatReader> classList) {
for (int i=0; i<c.length; i++) {
IFormatReader reader = null;
try {
reader = c[i].newInstance();
reader = c[i].getDeclaredConstructor().newInstance();
reader.setMetadataOptions(opt);
}
catch (IllegalAccessException exc) { }
catch (InstantiationException exc) { }
catch (ReflectiveOperationException exc) { }
if (reader == null) {
LOGGER.error("{} cannot be instantiated.", c[i].getName());
continue;
Expand Down
5 changes: 2 additions & 3 deletions components/formats-api/src/loci/formats/ImageWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@ public ImageWriter(ClassList<IFormatWriter> classList) {
for (int i=0; i<c.length; i++) {
IFormatWriter writer = null;
try {
writer = c[i].newInstance();
writer = c[i].getDeclaredConstructor().newInstance();
}
catch (IllegalAccessException exc) { }
catch (InstantiationException exc) { }
catch (ReflectiveOperationException exc) { }
if (writer == null) {
LOGGER.error("{} cannot be instantiated.", c[i].getName());
continue;
Expand Down
5 changes: 2 additions & 3 deletions components/formats-api/src/loci/formats/ReaderWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,9 @@ private ReaderWrapper duplicateRecurse(
c = reader.getClass();
}
try {
childCopy = c.newInstance();
childCopy = c.getDeclaredConstructor().newInstance();
}
catch (IllegalAccessException exc) { throw new FormatException(exc); }
catch (InstantiationException exc) { throw new FormatException(exc); }
catch (ReflectiveOperationException exc) { throw new FormatException(exc); }

// preserve reader-specific configuration with original reader
if (reader instanceof DelegateReader) {
Expand Down
5 changes: 2 additions & 3 deletions components/formats-api/src/loci/formats/WriterWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,9 @@ private WriterWrapper duplicateRecurse(
c = writer.getClass();
}
try {
childCopy = (IFormatWriter) c.newInstance();
childCopy = (IFormatWriter) c.getDeclaredConstructor().newInstance();
}
catch (IllegalAccessException exc) { throw new FormatException(exc); }
catch (InstantiationException exc) { throw new FormatException(exc); }
catch (ReflectiveOperationException exc) { throw new FormatException(exc); }
}

// use crazy reflection to instantiate a writer of the proper type
Expand Down
32 changes: 16 additions & 16 deletions components/test-suite/src/loci/tests/testng/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ public boolean doTest() {
if (delim >= 0) {
test = test.substring(0, delim);
}
return new Boolean(test.trim()).booleanValue();
return Boolean.parseBoolean(test.trim());
}

public boolean hasValidXML() {
if (globalTable.get(HAS_VALID_XML) == null) return true;
return new Boolean(globalTable.get(HAS_VALID_XML)).booleanValue();
return Boolean.parseBoolean(globalTable.get(HAS_VALID_XML));
}

public String getReader() {
Expand Down Expand Up @@ -261,19 +261,19 @@ public String getDimensionOrder() {
}

public boolean isInterleaved() {
return new Boolean(currentTable.get(IS_INTERLEAVED)).booleanValue();
return Boolean.parseBoolean(currentTable.get(IS_INTERLEAVED));
}

public boolean isIndexed() {
return new Boolean(currentTable.get(IS_INDEXED)).booleanValue();
return Boolean.parseBoolean(currentTable.get(IS_INDEXED));
}

public boolean isFalseColor() {
return new Boolean(currentTable.get(IS_FALSE_COLOR)).booleanValue();
return Boolean.parseBoolean(currentTable.get(IS_FALSE_COLOR));
}

public boolean isRGB() {
return new Boolean(currentTable.get(IS_RGB)).booleanValue();
return Boolean.parseBoolean(currentTable.get(IS_RGB));
}

public int getThumbSizeX() {
Expand All @@ -289,7 +289,7 @@ public String getPixelType() {
}

public boolean isLittleEndian() {
return new Boolean(currentTable.get(IS_LITTLE_ENDIAN)).booleanValue();
return Boolean.parseBoolean(currentTable.get(IS_LITTLE_ENDIAN));
}

public String getMD5() {
Expand Down Expand Up @@ -324,7 +324,7 @@ public Time getTimeIncrement() {
String timeIncrement = currentTable.get(TIME_INCREMENT);
String timeIncrementUnits = currentTable.get(TIME_INCREMENT_UNIT);
try {
return timeIncrement == null ? null : FormatTools.getTime(new Double(timeIncrement), timeIncrementUnits);
return timeIncrement == null ? null : FormatTools.getTime(Double.parseDouble(timeIncrement), timeIncrementUnits);
}
catch (NumberFormatException e) {
return null;
Expand All @@ -351,7 +351,7 @@ public Time getExposureTime(int channel) {
String exposure = currentTable.get(EXPOSURE_TIME + channel);
String exposureUnits = currentTable.get(EXPOSURE_TIME_UNIT + channel);
try {
return exposure == null ? null : FormatTools.getTime(new Double(exposure), exposureUnits);
return exposure == null ? null : FormatTools.getTime(Double.parseDouble(exposure), exposureUnits);
}
catch (NumberFormatException e) {
return null;
Expand All @@ -360,12 +360,12 @@ public Time getExposureTime(int channel) {

public Double getDeltaT(int plane) {
String deltaT = currentTable.get(DELTA_T + plane);
return deltaT == null ? null : new Double(deltaT);
return deltaT == null ? null : Double.parseDouble(deltaT);
}

public Double getPositionX(int plane) {
String pos = currentTable.get(X_POSITION + plane);
return pos == null ? null : new Double(pos);
return pos == null ? null : Double.parseDouble(pos);
}

public String getPositionXUnit(int plane) {
Expand All @@ -374,7 +374,7 @@ public String getPositionXUnit(int plane) {

public Double getPositionY(int plane) {
String pos = currentTable.get(Y_POSITION + plane);
return pos == null ? null : new Double(pos);
return pos == null ? null : Double.parseDouble(pos);
}

public String getPositionYUnit(int plane) {
Expand All @@ -383,7 +383,7 @@ public String getPositionYUnit(int plane) {

public Double getPositionZ(int plane) {
String pos = currentTable.get(Z_POSITION + plane);
return pos == null ? null : new Double(pos);
return pos == null ? null : Double.parseDouble(pos);
}

public String getPositionZUnit(int plane) {
Expand All @@ -394,7 +394,7 @@ public Length getEmissionWavelength(int channel) {
String wavelength = currentTable.get(EMISSION_WAVELENGTH + channel);
String emissionUnits = currentTable.get(EMISSION_WAVELENGTH_UNIT + channel);
try {
return wavelength == null ? null : FormatTools.getWavelength(new Double(wavelength), emissionUnits);
return wavelength == null ? null : FormatTools.getWavelength(Double.parseDouble(wavelength), emissionUnits);
}
catch (NumberFormatException e) {
return null;
Expand All @@ -405,7 +405,7 @@ public Length getExcitationWavelength(int channel) {
String wavelength = currentTable.get(EXCITATION_WAVELENGTH + channel);
String excitationUnits = currentTable.get(EXCITATION_WAVELENGTH_UNIT + channel);
try {
return wavelength == null ? null : FormatTools.getWavelength(new Double(wavelength), excitationUnits);
return wavelength == null ? null : FormatTools.getWavelength(Double.parseDouble(wavelength), excitationUnits);
}
catch (NumberFormatException e) {
return null;
Expand Down Expand Up @@ -828,7 +828,7 @@ private Length getPhysicalSize(String valueKey, String unitKey) {
String units = currentTable.get(unitKey);
try {
UnitsLength unit = units == null ? UnitsLength.MICROMETER : UnitsLength.fromString(units);
return physicalSize == null ? null : UnitsLength.create(new Double(physicalSize), unit);
return physicalSize == null ? null : UnitsLength.create(Double.parseDouble(physicalSize), unit);
}
catch (NumberFormatException e) { }
catch (EnumerationException e) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ public Object[][] getWriterList() {
String[] compressionTypes = writers[i].getCompressionTypes();
if (compressionTypes == null) {
try {
IFormatWriter w = (IFormatWriter) writers[i].getClass().newInstance();
IFormatWriter w = (IFormatWriter) writers[i].getClass().getDeclaredConstructor().newInstance();
tmp.add(w);
}
catch (InstantiationException ie) { }
catch (IllegalAccessException iae) { }
catch (ReflectiveOperationException roe) { }
continue;
}
for (int q=0; q<compressionTypes.length; q++) {
try {
IFormatWriter w = (IFormatWriter) writers[i].getClass().newInstance();
IFormatWriter w = (IFormatWriter) writers[i].getClass().getDeclaredConstructor().newInstance();
if (DataTools.containsValue(w.getPixelTypes(compressionTypes[q]),
reader.getPixelType()))
{
Expand All @@ -128,8 +127,7 @@ public Object[][] getWriterList() {
}
}
catch (FormatException fe) { }
catch (InstantiationException ie) { }
catch (IllegalAccessException iae) { }
catch (ReflectiveOperationException roe) { }
}
}
IFormatWriter[][] writersToUse = new IFormatWriter[tmp.size()][1];
Expand Down

0 comments on commit 6a0329f

Please sign in to comment.