Refactor DrawableFile NPE fix

This commit is contained in:
apriestman 2021-03-10 10:48:21 -05:00
parent a962ab34c5
commit d1dabed82e

View File

@ -100,20 +100,9 @@ public abstract class DrawableFile {
private String model; private String model;
private final CategoryManager categoryManager;
protected DrawableFile(AbstractFile file, Boolean analyzed) { protected DrawableFile(AbstractFile file, Boolean analyzed) {
this.analyzed = new SimpleBooleanProperty(analyzed); this.analyzed = new SimpleBooleanProperty(analyzed);
this.file = file; 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(); public abstract boolean isVideo();
@ -253,18 +242,18 @@ public abstract class DrawableFile {
* Update the category property. * Update the category property.
*/ */
private void updateCategory() { private void updateCategory() {
// This only happens when a DrawableFile is created while the case is closing. No need try {
// to display the error message. ImageGalleryController controllerForCase = ImageGalleryController.getController(Case.getCurrentCaseThrows());
if (categoryManager == null) { if (controllerForCase == null) {
// This can only happen during case closing, so return without generating an error.
return; return;
} }
try {
List<ContentTag> contentTags = getContentTags(); List<ContentTag> contentTags = getContentTags();
TagName tag = null; TagName tag = null;
for (ContentTag ct : contentTags) { for (ContentTag ct : contentTags) {
TagName tagName = ct.getName(); TagName tagName = ct.getName();
if (categoryManager.isCategoryTagName(tagName)) { if (controllerForCase.getCategoryManager().isCategoryTagName(tagName)) {
tag = tagName; tag = tagName;
break; break;
} }
@ -272,7 +261,7 @@ public abstract class DrawableFile {
categoryTagName.set(tag); categoryTagName.set(tag);
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
LOGGER.log(Level.WARNING, "problem looking up category for " + this.getContentPathSafe(), ex); //NON-NLS 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. // We get here many times if the case is closed during ingest, so don't print out a ton of warnings.
} }
} }