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

ALS-4751: Clean up excepetion handling, per checkmarx #70

Merged
merged 3 commits into from
Jul 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public BucketIndexBySample(VariantStore variantStore, String storageDir) throws
}
});
} catch (IOException e) {
e.printStackTrace();
throw new UncheckedIOException(e);
}

// For each patient set the patientBucketCharMask entry to 0 or 1 if they have a variant in the bucket.
Expand Down Expand Up @@ -135,7 +135,7 @@ public void run() {
try {
Thread.sleep(5 * 1000 * 60); //log a message every 5 minutes
} catch (InterruptedException e) {
e.printStackTrace();
log.error("Thread interrupted", e);
}
log.info("wrote " + processedPatients[0] + " patient bucket masks");
}
Expand All @@ -149,7 +149,7 @@ public void run() {
}catch(NumberFormatException e) {
log.error("NFE caught for " + patientId, e);
} catch (IOException e) {
e.printStackTrace();
throw new UncheckedIOException(e);
}
processedPatients[0] += 1;
});
Expand Down Expand Up @@ -178,9 +178,9 @@ public Collection<String> filterVariantSetForPatientSet(Set<String> variantSet,
try {
return patientBucketMasks.get(patientNum);
} catch (IOException e) {
e.printStackTrace();
throw new UncheckedIOException(e);
}
return _defaultMask;
//return _defaultMask;
}).collect(Collectors.toList());
for(BigInteger patientMask : patientBucketmasksForSet) {
patientBucketMask = patientMask.or(patientBucketMask);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package edu.harvard.hms.dbmi.avillach.hpds.data.genotype;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -22,13 +18,16 @@
import com.google.common.collect.Range;

import edu.harvard.hms.dbmi.avillach.hpds.storage.FileBackedByteIndexedStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CompressedIndex implements Serializable {

/**
*
*/
private static final long serialVersionUID = 5089713203903957829L;
private static final Logger log = LoggerFactory.getLogger(CompressedIndex.class);
public Float min = Float.MAX_VALUE, max = Float.MIN_VALUE;
private HashMap<Range<Float>, byte[]> compressedRangeMap;
private int valueCount;
Expand Down Expand Up @@ -61,7 +60,7 @@ public TreeMap<Float, TreeSet<String>> buildContinuousValuesMap(FileBackedByteIn
continuousValueMap.put(DoubleValue, currentValues);
setMinAndMax(DoubleValue);
}catch(NumberFormatException e3) {
System.out.println("Unable to parse value : " + value.trim());
log.info("Unable to parse value : " + value.trim());
}
}
}
Expand Down Expand Up @@ -114,8 +113,7 @@ public void buildIndex(TreeMap<Float, TreeSet<String>> continuousValueMap) {
gzos.close();
compressed = baos.toByteArray();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new UncheckedIOException(e);
}
return compressed;
})
Expand Down Expand Up @@ -174,11 +172,9 @@ private TreeMap<Double, TreeSet<String>> retrieveRangeMap(Range<Double> range) {
){
continousValueMap = (TreeMap<Double, TreeSet<String>>)ois.readObject();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new UncheckedIOException(e);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException(e);
}
return continousValueMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,6 @@ public static VariantStore deserializeInstance(String genomicDataDirectory) thro
}
}

public ArrayList<String> listVariants() {
ArrayList<String> allVariants = new ArrayList<>();
for (String key : variantMaskStorage.keySet()) {
FileBackedByteIndexedStorage<Integer, ConcurrentHashMap<String, VariantMasks>> storage = variantMaskStorage
.get(key);
storage.keys().stream().forEach((Integer bucket) -> {
try {
for (String variant : storage.get(bucket).keySet()) {
allVariants.add(variant);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
}
return allVariants;
}

public Map<String, int[]> countVariants() {
HashMap<String, Integer> countOffsetMap = new HashMap<String, Integer>();
TreeMap<String, int[]> counts = new TreeMap<>();
Expand Down Expand Up @@ -105,8 +86,7 @@ public Map<String, int[]> countVariants() {
|| masks.heterozygousNoCallMask != null || masks.homozygousNoCallMask != null ? 1 : 0;
}));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new UncheckedIOException(e);
}
});
}
Expand Down Expand Up @@ -156,8 +136,7 @@ public void open() {
try {
fbbis.open();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new UncheckedIOException(e);
}
}
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.harvard.hms.dbmi.avillach.hpds.data.genotype.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
Expand All @@ -20,40 +19,27 @@
public class HideAnnotationCategoryValue {
protected static LoadingCache<String, PhenoCube<?>> store;

protected static TreeMap<String, ColumnMeta> metaStoreSource;

protected static TreeSet<Integer> allIds;

public static void main(String[] args) throws ClassNotFoundException, FileNotFoundException, IOException {
public static void main(String[] args) throws ClassNotFoundException, IOException {
String infoStoreToModify = args[0];
String valueToScrub = args[1];

String infoStoreFilename = "/opt/local/hpds/all/" + infoStoreToModify.trim();
try (
FileInputStream fis = new FileInputStream(infoStoreFilename);
GZIPInputStream gis = new GZIPInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(gis)
){
FileBackedByteIndexedInfoStore infoStore = (FileBackedByteIndexedInfoStore) ois.readObject();
infoStore.getAllValues().keys().remove(valueToScrub);
try(
FileOutputStream fos = new FileOutputStream(infoStoreFilename);
GZIPOutputStream gos = new GZIPOutputStream(fos);
ObjectOutputStream oos = new ObjectOutputStream(gos);
){
oos.writeObject(infoStore);
oos.flush();oos.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

FileInputStream fis = new FileInputStream(infoStoreFilename);
GZIPInputStream gis = new GZIPInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(gis);

FileBackedByteIndexedInfoStore infoStore = (FileBackedByteIndexedInfoStore) ois.readObject();
infoStore.getAllValues().keys().remove(valueToScrub);

FileOutputStream fos = new FileOutputStream(infoStoreFilename);
GZIPOutputStream gos = new GZIPOutputStream(fos);
ObjectOutputStream oos = new ObjectOutputStream(gos);

oos.writeObject(infoStore);
oos.flush();oos.close();
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package edu.harvard.hms.dbmi.avillach.hpds.data.phenotype.util;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.RandomAccessFile;
import java.io.*;
import java.util.ArrayList;
import java.util.Set;
import java.util.TreeMap;
Expand Down Expand Up @@ -68,10 +62,10 @@ public static void main(String[] args) throws ClassNotFoundException, FileNotFou
cubeLines.add(line);
}
writer.printRecords(cubeLines);
}catch(ExecutionException e) {
e.printStackTrace();
} catch(ExecutionException e) {
throw new RuntimeException(e);
} catch (IOException e) {
e.printStackTrace();
throw new UncheckedIOException(e);
}
});
writer.flush();
Expand All @@ -90,7 +84,6 @@ protected static Object[] loadMetadata() {
Set<Integer> allIds = (TreeSet<Integer>) objectInputStream.readObject();
return new Object[] {metastoreScrubbed, allIds};
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
throw new RuntimeException("Could not load metastore");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static void processRecord(final PhenoCube[] currentConcept, List<String>
store.allIds.add(Integer.parseInt(record.get(PATIENT_NUM)));
}
} catch (ExecutionException e) {
e.printStackTrace();
log.error("Error processing record", e);
}
}

Expand Down Expand Up @@ -174,10 +174,9 @@ protected static Object[] loadMetadata() {
Set<Integer> allIds = (TreeSet<Integer>) objectInputStream.readObject();
return new Object[] {metastoreScrubbed, allIds};
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
log.warn("************************************************");
log.warn("************************************************");
log.warn("Could not load metastore");
log.warn("Could not load metastore", e);
log.warn("If you meant to include phenotype data of any kind, please check that the file /opt/local/source/columnMeta.javabin exists and is readable by the service.");
log.warn("************************************************");
log.warn("************************************************");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ protected static Object[] loadMetadata() {
Set<Integer> allIds = (TreeSet<Integer>) objectInputStream.readObject();
return new Object[] {metastoreScrubbed, allIds};
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
log.warn("************************************************");
log.warn("************************************************");
log.warn("Could not load metastore");
log.warn("Could not load metastore", e);
log.warn("If you meant to include phenotype data of any kind, please check that the file /opt/local/source/columnMeta.javabin exists and is readable by the service.");
log.warn("************************************************");
log.warn("************************************************");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static void processRecord(final PhenoCube[] currentConcept, List<String>
store.allIds.add(patientId);
}
} catch (ExecutionException e) {
e.printStackTrace();
log.error("Error processing record", e);
}
}

Expand Down Expand Up @@ -177,10 +177,9 @@ protected static Object[] loadMetadata() {
Set<Integer> allIds = (TreeSet<Integer>) objectInputStream.readObject();
return new Object[] {metastoreScrubbed, allIds};
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
log.warn("************************************************");
log.warn("************************************************");
log.warn("Could not load metastore");
log.warn("Could not load metastore", e);
log.warn("If you meant to include phenotype data of any kind, please check that the file /opt/local/source/columnMeta.javabin exists and is readable by the service.");
log.warn("************************************************");
log.warn("************************************************");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ protected static TreeMap<String, ColumnMeta> removeMetadata(Path filePath) {

return metastore;
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
throw new RuntimeException("Could not load metastore");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public static void main(String[] args) throws ClassNotFoundException, FileNotFou
try {
loadingStoreTarget.store.put(key, store.get(key));
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException(e);
}
});
}
Expand All @@ -67,7 +66,6 @@ protected static Object[] loadMetadata() {
Set<Integer> allIds = (TreeSet<Integer>) objectInputStream.readObject();
return new Object[] {metastoreScrubbed, allIds};
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
throw new RuntimeException("Could not load metastore");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package edu.harvard.hms.dbmi.avillach.hpds.etl.genotype;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.*;
import java.util.ArrayList;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -46,8 +43,7 @@ public static void main(String[] args) throws ClassNotFoundException, FileNotFou
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new UncheckedIOException(e);
}
System.out.println("Completed bucket : " + offsetBucket);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package edu.harvard.hms.dbmi.avillach.hpds.etl.genotype;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.*;
import java.util.ArrayList;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -34,8 +31,7 @@ public static void main(String[] args) throws ClassNotFoundException, FileNotFou
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new UncheckedIOException(e);
}
});
System.out.println(contig + "," + countOfVariants[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ private static void processRecord(final PhenoCube[] currentConcept, CSVRecord re
store.allIds.add(patientId);
}
} catch (ExecutionException e) {
e.printStackTrace();
// todo: do we really want to ignore this?
log.error("Error processing record", e);
}
}
}
Loading