Skip to content
Snippets Groups Projects
Commit d1dabed8 authored by apriestman's avatar apriestman
Browse files

Refactor DrawableFile NPE fix

parent a962ab34
No related branches found
No related tags found
No related merge requests found
......@@ -100,20 +100,9 @@ public static DrawableFile create(Long fileID, boolean analyzed) throws TskCoreE
private String model;
private final CategoryManager categoryManager;
protected DrawableFile(AbstractFile file, Boolean analyzed) {
this.analyzed = new SimpleBooleanProperty(analyzed);
this.file = file;
ImageGalleryController controllerForCase = ImageGalleryController.getController(Case.getCurrentCase());
if (controllerForCase != null) {
categoryManager = ImageGalleryController.getController(Case.getCurrentCase()).getCategoryManager();
} else {
// If getting the controller fails it means the case is currently closing. No need to
// print an error.
categoryManager = null;
}
}
public abstract boolean isVideo();
......@@ -252,19 +241,19 @@ public SimpleObjectProperty<TagName> categoryProperty() {
/**
* Update the category property.
*/
private void updateCategory() {
// This only happens when a DrawableFile is created while the case is closing. No need
// to display the error message.
if (categoryManager == null) {
return;
}
private void updateCategory() {
try {
ImageGalleryController controllerForCase = ImageGalleryController.getController(Case.getCurrentCaseThrows());
if (controllerForCase == null) {
// This can only happen during case closing, so return without generating an error.
return;
}
List<ContentTag> contentTags = getContentTags();
TagName tag = null;
for (ContentTag ct : contentTags) {
TagName tagName = ct.getName();
if (categoryManager.isCategoryTagName(tagName)) {
if (controllerForCase.getCategoryManager().isCategoryTagName(tagName)) {
tag = tagName;
break;
}
......@@ -272,7 +261,7 @@ private void updateCategory() {
categoryTagName.set(tag);
} catch (TskCoreException ex) {
LOGGER.log(Level.WARNING, "problem looking up category for " + this.getContentPathSafe(), ex); //NON-NLS
} catch (IllegalStateException ex) {
} catch (IllegalStateException | NoCurrentCaseException ex) {
// We get here many times if the case is closed during ingest, so don't print out a ton of warnings.
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment