Fix DataSourceAnalysisEvent.getDataSource NPEs

This commit is contained in:
Richard Cordovano 2018-12-14 12:27:51 -05:00
parent 5b0e8526e2
commit 2fb1409e4a

View File

@ -39,6 +39,7 @@ public abstract class DataSourceAnalysisEvent extends AutopsyEvent implements Se
private final long ingestJobId;
private final long dataSourceIngestJobId;
private transient Content dataSource;
private final long dataSourceObjectId;
/**
* Constructs an instance of the base class for events published in
@ -56,6 +57,7 @@ public abstract class DataSourceAnalysisEvent extends AutopsyEvent implements Se
this.ingestJobId = ingestJobId;
this.dataSourceIngestJobId = dataSourceIngestJobId;
this.dataSource = dataSource;
this.dataSourceObjectId = dataSource.getId();
}
/**
@ -81,7 +83,8 @@ public abstract class DataSourceAnalysisEvent extends AutopsyEvent implements Se
/**
* Gets the data source associated with this event.
*
* @return The data source.
* @return The data source or null if there is an error getting the data
* source from an event published by a remote node.
*/
public Content getDataSource() {
/**
@ -96,11 +99,10 @@ public abstract class DataSourceAnalysisEvent extends AutopsyEvent implements Se
return dataSource;
}
try {
long id = (Long) super.getNewValue();
dataSource = Case.getCurrentCaseThrows().getSleuthkitCase().getContentById(id);
dataSource = Case.getCurrentCaseThrows().getSleuthkitCase().getContentById(dataSourceObjectId);
return dataSource;
} catch (NoCurrentCaseException | TskCoreException ex) {
logger.log(Level.SEVERE, "Error doing lazy load for remote event", ex); //NON-NLS
logger.log(Level.SEVERE, String.format("Error doing lazy load of data source (objId=%d) for remote event", this.dataSourceObjectId), ex); //NON-NLS
return null;
}
}