Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Java 11 deprecation warnings #6145

Merged
merged 3 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/java/org/broadinstitute/hellbender/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.PrintStream;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
Expand Down Expand Up @@ -346,12 +347,12 @@ private CommandLineProgram extractCommandLineProgram( final String[] args,
if (simpleNameToClass.containsKey(args[0])) {
final Class<?> clazz = simpleNameToClass.get(args[0]);
try {
final Object commandLineProgram = clazz.newInstance();
final Object commandLineProgram = clazz.getDeclaredConstructor().newInstance();
// wrap Picard CommandLinePrograms in a PicardCommandLineProgramExecutor
return commandLineProgram instanceof picard.cmdline.CommandLineProgram ?
new PicardCommandLineProgramExecutor((picard.cmdline.CommandLineProgram) commandLineProgram) :
(CommandLineProgram) commandLineProgram;
} catch (final InstantiationException | IllegalAccessException e) {
} catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -395,8 +396,8 @@ private void printUsage(final PrintStream destinationStream, final Set<Class<?>>
CommandLineProgramGroup programGroup = programGroupClassToProgramGroupInstance.get(property.programGroup());
if (null == programGroup) {
try {
programGroup = property.programGroup().newInstance();
} catch (final InstantiationException | IllegalAccessException e) {
programGroup = property.programGroup().getDeclaredConstructor().newInstance();
} catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new RuntimeException(e);
}
programGroupClassToProgramGroupInstance.put(property.programGroup(), programGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public String getDisplayName()
* @throws InstantiationException if thrown when calling the {@code pluginClass} constructor
*/
@Override
@SuppressWarnings("deprecation")
public Annotation createInstanceForPlugin(Class<?> pluggableClass) throws IllegalAccessException, InstantiationException {
Annotation annot = null;
final String simpleName = pluggableClass.getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public boolean includePluginClass(Class<?> c) {

// Instantiate a new ReadFilter derived object and save it in the list
@Override
@SuppressWarnings("deprecation")
public ReadFilter createInstanceForPlugin(final Class<?> pluggableClass) throws IllegalAccessException, InstantiationException {
ReadFilter readFilter = null;
final String simpleName = pluggableClass.getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -347,8 +348,8 @@ private static <T extends Feature> FeatureReader<T> getFeatureReader(final Featu
featureInput.setFeatureCodecClass((Class<FeatureCodec<T, ?>>) codec.getClass());
} else {
try {
codec = codecClass.newInstance();
} catch (final InstantiationException | IllegalAccessException e) {
codec = codecClass.getDeclaredConstructor().newInstance();
} catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new GATKException("Unable to automatically instantiate codec " + codecClass.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.file.Files;
Expand Down Expand Up @@ -519,12 +520,12 @@ private <T extends Feature> FeatureDataSource<T> lookupDataSource( final Feature

for ( final Class<?> codecClass : DISCOVERED_CODECS ) {
try {
final FeatureCodec<? extends Feature, ?> codec = (FeatureCodec<? extends Feature, ?>)codecClass.newInstance();
final FeatureCodec<? extends Feature, ?> codec = (FeatureCodec<? extends Feature, ?>)codecClass.getDeclaredConstructor().newInstance();
if ( codec.canDecode(featureFile.toAbsolutePath().toUri().toString()) ) {
candidateCodecs.add(codec);
}
}
catch ( InstantiationException | IllegalAccessException e ) {
catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e ) {
throw new GATKException("Unable to automatically instantiate codec " + codecClass.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public VariantContext finalizeGenotype(final VariantContext variant, final Varia

for (final Class c : allASAnnotations) {
try {
final InfoFieldAnnotation annotation = (InfoFieldAnnotation) c.newInstance();
final InfoFieldAnnotation annotation = (InfoFieldAnnotation) c.getDeclaredConstructor().newInstance();
if (annotation instanceof AS_StandardAnnotation && annotation instanceof ReducibleAnnotation) {
final ReducibleAnnotation ann = (ReducibleAnnotation) annotation;
if (variant.hasAttribute(ann.getRawKeyName())) {
Expand All @@ -222,7 +222,7 @@ public VariantContext finalizeGenotype(final VariantContext variant, final Varia
if (!keepAllSites) {
for (final Class c : allASAnnotations) {
try {
final InfoFieldAnnotation annotation = (InfoFieldAnnotation) c.newInstance();
final InfoFieldAnnotation annotation = (InfoFieldAnnotation) c.getDeclaredConstructor().newInstance();
if (annotation instanceof AS_StandardAnnotation && annotation instanceof ReducibleAnnotation) {
final ReducibleAnnotation ann = (ReducibleAnnotation) annotation;
if (variant.hasAttribute(ann.getRawKeyName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.broadinstitute.hellbender.tools.walkers.varianteval.VariantEval;
import org.broadinstitute.hellbender.tools.walkers.varianteval.evaluators.VariantEvaluator;
import org.broadinstitute.hellbender.tools.walkers.varianteval.stratifications.manager.StratificationManager;
import org.broadinstitute.hellbender.utils.ClassUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand All @@ -30,15 +32,9 @@ private EvaluationContext(final VariantEval walker, final Set<Class<? extends Va
this.evaluationInstances = new ArrayList<>(evaluationClasses.size());

for ( final Class<? extends VariantEvaluator> c : evaluationClasses ) {
try {
final VariantEvaluator eval = c.newInstance();
if ( doInitialize ) eval.initialize(walker);
evaluationInstances.add(eval);
} catch (InstantiationException e) {
throw new GATKException("Unable to instantiate eval module '" + c.getSimpleName() + "'", e);
} catch (IllegalAccessException e) {
throw new GATKException("Illegal access error when trying to instantiate eval module '" + c.getSimpleName() + "'", e);
}
final VariantEvaluator eval = ClassUtils.makeInstanceOf(c);
if ( doInitialize ) eval.initialize(walker);
evaluationInstances.add(eval);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.broadinstitute.hellbender.tools.walkers.varianteval.stratifications.RequiredStratification;
import org.broadinstitute.hellbender.tools.walkers.varianteval.stratifications.StandardStratification;
import org.broadinstitute.hellbender.tools.walkers.varianteval.stratifications.VariantStratifier;
import org.broadinstitute.hellbender.utils.ClassUtils;
import org.broadinstitute.hellbender.utils.samples.Sample;
import org.reflections.Reflections;

Expand Down Expand Up @@ -120,17 +121,10 @@ public List<VariantStratifier> initializeStratificationObjects(boolean noStandar
if (stratifierClasses.containsKey(module)) {
Class<? extends VariantStratifier> c = stratifierClasses.get(module);

try {
VariantStratifier vs = c.newInstance();
vs.setVariantEvalWalker(variantEvalWalker);
vs.initialize();

strats.add(vs);
} catch (InstantiationException e) {
throw new GATKException("Unable to instantiate stratification module '" + c.getSimpleName() + "'");
} catch (IllegalAccessException e) {
throw new GATKException("Illegal access error when trying to instantiate stratification module '" + c.getSimpleName() + "'");
}
VariantStratifier vs = ClassUtils.makeInstanceOf(c);
vs.setVariantEvalWalker(variantEvalWalker);
vs.initialize();
strats.add(vs);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.broadinstitute.barclay.argparser.ClassFinder;
import org.broadinstitute.hellbender.exceptions.GATKException;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -68,8 +69,8 @@ public static <T> List<T> makeInstancesOfSubclasses(final Class<? extends T> cla
public static <T> T makeInstanceOf(final Class<T> clazz) {
if (canMakeInstances(clazz)) {
try {
return clazz.newInstance();
} catch (final InstantiationException | IllegalAccessException e) {
return clazz.getDeclaredConstructor().newInstance();
} catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new GATKException("Problem making an instance of " + clazz + " Do check that the class has a non-arg constructor", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.broadinstitute.hellbender.utils.help;

import com.sun.javadoc.ClassDoc;
import org.broadinstitute.barclay.help.DocWorkUnit;
import org.broadinstitute.barclay.help.DocWorkUnitHandler;
import org.broadinstitute.barclay.help.DocumentedFeature;
Expand All @@ -15,12 +14,13 @@
* by methods that are used by the GATK runtime. This class has a dependency on com.sun.javadoc classes,
* which may not be present since they're not provided as part of the normal GATK runtime classpath.
*/
@SuppressWarnings("removal")
public class GATKDocWorkUnit extends DocWorkUnit {

public GATKDocWorkUnit(
final DocWorkUnitHandler workUnitHandler,
final DocumentedFeature documentedFeatureAnnotation,
final ClassDoc classDoc,
final com.sun.javadoc.ClassDoc classDoc,
final Class<?> clazz) {
super(workUnitHandler, documentedFeatureAnnotation, classDoc, clazz);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.broadinstitute.hellbender.utils.help;

import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.RootDoc;

import org.broadinstitute.barclay.help.DocumentedFeature;
import org.broadinstitute.barclay.help.DocWorkUnit;
import org.broadinstitute.barclay.help.GSONWorkUnit;
Expand All @@ -19,6 +16,7 @@
* by methods that are used by the GATK runtime. This class has a dependency on com.sun.javadoc classes,
* which may not be present since they're not provided as part of the normal GATK runtime classpath.
*/
@SuppressWarnings("removal")
public class GATKHelpDoclet extends HelpDoclet {

private final static String GATK_FREEMARKER_INDEX_TEMPLATE_NAME = "generic.index.template.html";
Expand All @@ -29,7 +27,7 @@ public class GATKHelpDoclet extends HelpDoclet {
* @param rootDoc
* @throws IOException
*/
public static boolean start(final RootDoc rootDoc) throws IOException {
public static boolean start(final com.sun.javadoc.RootDoc rootDoc) throws IOException {
return new GATKHelpDoclet().startProcessDocs(rootDoc);
}

Expand All @@ -55,7 +53,7 @@ public String getIndexTemplateName() {
@Override
protected DocWorkUnit createWorkUnit(
final DocumentedFeature documentedFeature,
final ClassDoc classDoc,
final com.sun.javadoc.ClassDoc classDoc,
final Class<?> clazz)
{
return new GATKDocWorkUnit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public Process getProcess() {
abstract void tryCleanShutdown();

@Override
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
tryCleanShutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testDetectCorrectFileFormat( final File file, final Class<? extends

// We should also get the correct codec if we pass in the explicit expected Feature type to getCodecForFile()
@SuppressWarnings("unchecked")
final Class<? extends Feature> expectedCodecFeatureType = expectedCodecClass.newInstance().getFeatureType();
final Class<? extends Feature> expectedCodecFeatureType = expectedCodecClass.getDeclaredConstructor().newInstance().getFeatureType();
Assert.assertEquals(FeatureManager.getCodecForFile(file, expectedCodecFeatureType).getClass(), expectedCodecClass,
"Wrong codec selected for file " + file.getAbsolutePath() + " after subsetting to the expected Feature type");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public void testNormalizeScientificNotation(Object toNormalize, Object expected)
public Object[][] getIntegerValuesToNormalize(){
final Object aSpecificObject = new Object();
return new Object[][] {
{"27", new Integer(27)},
{"-27", new Integer(-27)},
{"0", new Integer(0)},
{"-27014", new Integer(-27014)},
{"27", 27},
{"-27", -27},
{"0", 0},
{"-27014", -27014},
{1, 1},
{1, 1},
{-1, -1},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1143,10 +1143,10 @@ public void testVcfMafConcordance(final String inputVcf,
mafFieldValues = maf.getRecords().stream().map(AnnotatedInterval::getContig).collect(Collectors.toList());
}
else if ( annotationsToCheckMaf.get(i).equals(MafOutputRendererConstants.FieldName_Start_Position) ) {
mafFieldValues = maf.getRecords().stream().map(AnnotatedInterval::getStart).map(x -> new Integer(x)).map(Object::toString).collect(Collectors.toList());
mafFieldValues = maf.getRecords().stream().map(AnnotatedInterval::getStart).map(Object::toString).collect(Collectors.toList());
}
else if ( annotationsToCheckMaf.get(i).equals(MafOutputRendererConstants.FieldName_End_Position) ) {
mafFieldValues = maf.getRecords().stream().map(AnnotatedInterval::getEnd).map(x -> new Integer(x)).map(Object::toString).collect(Collectors.toList());
mafFieldValues = maf.getRecords().stream().map(AnnotatedInterval::getEnd).map(Object::toString).collect(Collectors.toList());
}
else if ( annotationsToCheckMaf.get(i).equals(MafOutputRendererConstants.FieldName_Hugo_Symbol) ) {
mafFieldValues = maf.getRecords().stream().map(x -> x.getAnnotationValue(MafOutputRendererConstants.FieldName_Hugo_Symbol)).map(a -> a.isEmpty() ? "Unknown" : a).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ private static Map<String, PSPathogenTaxonScore> getScores(final String[] lines)
final PSPathogenTaxonScore score = new PSPathogenTaxonScore();
final String taxonId = tok[0];
score.setKingdomTaxonId(Math.abs(tok[4].hashCode()));
score.addSelfScore(new Double(tok[5]));
score.addScoreNormalized(new Double(tok[6]));
score.addTotalReads(new Integer(tok[7]));
score.addUnambiguousReads(new Integer(tok[8]));
score.setReferenceLength(new Long(tok[9]));
score.addSelfScore(Double.parseDouble(tok[5]));
score.addScoreNormalized(Double.parseDouble(tok[6]));
score.addTotalReads(Integer.parseInt(tok[7]));
score.addUnambiguousReads(Integer.parseInt((tok[8])));
score.setReferenceLength(Long.parseLong(tok[9]));
Assert.assertFalse(scores.containsKey(taxonId), "Found more than one entry for taxon ID " + taxonId);
scores.put(taxonId, score);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void testRandomMaskedKmers() {
//Generate random indices to mask
List<Byte> maskIndices = new ArrayList<>(K);
for (int j = 0; j < K; j++) {
maskIndices.add(new Byte((byte) j));
maskIndices.add((byte) j);
}
Collections.shuffle(maskIndices);
int maskSize = rand.nextInt(K - 3) + 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void resizeTest() {
Assert.assertTrue(hopscotchSet.size() == hashSet.size());
LongIterator itrL = hopscotchSet.iterator();
while (itrL.hasNext()) {
Assert.assertTrue(hashSet.contains(new Long(itrL.next())));
Assert.assertTrue(hashSet.contains(itrL.next()));
}
for (Long val : hashSet) {
Assert.assertTrue(hopscotchSet.contains(val.longValue()));
Expand All @@ -155,7 +155,7 @@ void loadRandomLongsTest() {
for (int valNo = 0; valNo != HHASH_NVALS; ++valNo) {
final long randLong = randomLong(rng);
hopscotchSet.add(randLong);
hashSet.add(new Long(randLong));
hashSet.add(randLong);
}
Assert.assertEquals(hashSet.size(), hopscotchSet.size());
for (final Long val : hashSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void testRandomLongs() {
final LongBloomFilter bloomFilter = new LongBloomFilter(HHASH_NVALS, FPP);
for (int valNo = 0; valNo != HHASH_NVALS; ++valNo) {
final long randLong = randomLong(rng);
hashSet.add(new Long(randLong));
hashSet.add(randLong);
bloomFilter.add(randLong);
}
for (final Long val : hashSet) {
Expand All @@ -94,7 +94,7 @@ void testRandomLongs() {
int num_total = 0;
for (int valNo = 0; valNo != FPR_NVALS; ++valNo) {
final long randLong = randomLong(rng);
if (!hashSet.contains(new Long(randLong))) {
if (!hashSet.contains(randLong)) {
num_total++;
if (bloomFilter.contains(randLong)) {
num_false_pos++;
Expand Down
Loading