Skip to content

Commit

Permalink
ALS-4751: Clean up excepetion handling, per checkmarx
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Jul 12, 2023
1 parent a3e90ab commit 7b7165f
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 183 deletions.
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) {
log.error("Error getting bucket", e);
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 @@ -149,7 +149,7 @@ public void run() {
}catch(NumberFormatException e) {
log.error("NFE caught for " + patientId, e);
} catch (IOException e) {
log.error("Error writing patient bucket masks", e);
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) {
log.error("Error getting mask for patient", e);
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 Down Expand Up @@ -64,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 @@ -117,7 +113,7 @@ public void buildIndex(TreeMap<Float, TreeSet<String>> continuousValueMap) {
gzos.close();
compressed = baos.toByteArray();
} catch (IOException e) {
log.error("Error writing range map", e);
throw new UncheckedIOException(e);
}
return compressed;
})
Expand Down Expand Up @@ -176,9 +172,9 @@ private TreeMap<Double, TreeSet<String>> retrieveRangeMap(Range<Double> range) {
){
continousValueMap = (TreeMap<Double, TreeSet<String>>)ois.readObject();
} catch (IOException e) {
log.error("Error reading range map from file", e);
throw new UncheckedIOException(e);
} catch (ClassNotFoundException e) {
log.error("Error deserializing range map", e);
throw new RuntimeException(e);
}
return continousValueMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,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 @@ -137,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 @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,17 @@ public void onRemoval(RemovalNotification<String, PhenoCube> arg0) {
columnMeta.setMax(max);
}
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
try {

ObjectOutputStream out = new ObjectOutputStream(byteStream);
out.writeObject(arg0.getValue());
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}

ObjectOutputStream out = new ObjectOutputStream(byteStream);
out.writeObject(arg0.getValue());
out.flush();
out.close();

allObservationsStore.write(Crypto.encryptData(byteStream.toByteArray()));
columnMeta.setAllObservationsLength(allObservationsStore.getFilePointer());
metadataMap.put(columnMeta.getName(), columnMeta);
} catch (IOException e1) {
e1.printStackTrace();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
import edu.harvard.hms.dbmi.avillach.hpds.data.phenotype.PhenoCube;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

public class SQLLoader {

private static final Logger log = LoggerFactory.getLogger(SQLLoader.class);

private static final SimpleDateFormat ORACLE_DATE_FORMAT = new SimpleDateFormat("dd-MMM-yy");

static JdbcTemplate template;
Expand Down Expand Up @@ -157,8 +161,7 @@ public void processRow(ResultSet arg0) throws SQLException {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error("Thread interrupted", e);
}
// stillProcessingRecords[0] = false;
// chunkWriteEx.shutdown();
Expand Down Expand Up @@ -223,11 +226,9 @@ private static void processRecord(final PhenoCube[] currentConcept, ResultSet ar
currentConcept[0].add(patientId, isAlpha ? value : Double.parseDouble(value), arg0.getDate(DATETIME));
store.allIds.add(patientId);
}
} catch (ExecutionException e) {
e.printStackTrace();
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (ExecutionException | SQLException e) {
// todo: do we really want to ignore these?
log.error("Exception processing record", e);
}
}
}
Loading

0 comments on commit 7b7165f

Please sign in to comment.