diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/VariantAnnotatorEngine.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/VariantAnnotatorEngine.java index fb35549abd7..68a44d7880b 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/VariantAnnotatorEngine.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/VariantAnnotatorEngine.java @@ -1,19 +1,17 @@ package org.broadinstitute.hellbender.tools.walkers.annotator; -import com.google.common.collect.Sets; import htsjdk.variant.variantcontext.*; import htsjdk.variant.vcf.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.broadinstitute.hellbender.engine.*; import org.broadinstitute.hellbender.engine.FeatureContext; +import org.broadinstitute.hellbender.engine.FeatureDataSource; import org.broadinstitute.hellbender.engine.FeatureInput; import org.broadinstitute.hellbender.engine.ReferenceContext; import org.broadinstitute.hellbender.exceptions.GATKException; import org.broadinstitute.hellbender.exceptions.UserException; import org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.ReducibleAnnotation; import org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.ReducibleAnnotationData; -import org.broadinstitute.hellbender.utils.ClassUtils; import org.broadinstitute.hellbender.utils.Utils; import org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods; import org.broadinstitute.hellbender.utils.variant.GATKVariantContextUtils; diff --git a/src/main/java/org/broadinstitute/hellbender/utils/ClassUtils.java b/src/main/java/org/broadinstitute/hellbender/utils/ClassUtils.java index 4dd1af77b34..6a6e12bf06c 100644 --- a/src/main/java/org/broadinstitute/hellbender/utils/ClassUtils.java +++ b/src/main/java/org/broadinstitute/hellbender/utils/ClassUtils.java @@ -49,17 +49,33 @@ public static List makeInstancesOfSubclasses(final Class cla final List results = new ArrayList<>(classes.size()); for (final Class found: classes){ - if (canMakeInstances(found)){ - try { - results.add((T)found.newInstance()); - } catch (InstantiationException | IllegalAccessException e) { - throw new GATKException("Problem making an instance of " + found + " Do check that the class has a non-arg constructor", e); - } + final T instance = (T) makeInstanceOf(found); + if (instance != null) { + results.add(instance); } } return results; } + /** + * Create objects of a concrete class. + * + * The public no-arg constructor is called to create the objects. + * + * @param clazz class to be instantiated + * @return new object or {@code null} if cannot be instantiated. + */ + public static T makeInstanceOf(final Class clazz) { + if (canMakeInstances(clazz)) { + try { + return clazz.newInstance(); + } catch (final InstantiationException | IllegalAccessException e) { + throw new GATKException("Problem making an instance of " + clazz + " Do check that the class has a non-arg constructor", e); + } + } + return null; + } + /** * Finds sub-interfaces of the given interface (in the same package) and returns their simple names. */