From 2a52fc9af45a69b1f4b8dc19c8110e0be2d44626 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Tue, 6 Dec 2016 23:14:19 +0100 Subject: [PATCH] Fix nullpointer exception when debugging with poodinisVerbose --- CHANGES.md | 3 +++ source/poodinis/factory.d | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0488f01..f9ec50e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ Poodinis Changelog ================== +**Version NEXT** +* FIX nullpointer exception in instance factory when debugging with poodinisVerbose + **Version 7.0.1** * FIX codegeneration of constructor injection factories for constructors with dependencies from foreign modules, such as modules from other libraries (Issue #12). diff --git a/source/poodinis/factory.d b/source/poodinis/factory.d index 01375e1..4341d88 100644 --- a/source/poodinis/factory.d +++ b/source/poodinis/factory.d @@ -67,20 +67,36 @@ class InstanceFactory { public Object getInstance() { if (_factoryParameters.createsSingleton && instance !is null) { debug(poodinisVerbose) { - writeln(format("DEBUG: Existing instance returned of type %s", _factoryParameters.instanceType.toString())); + printDebugUseExistingInstance(); } return instance; } debug(poodinisVerbose) { - writeln(format("DEBUG: Creating new instance of type %s", _factoryParameters.instanceType.toString())); + printDebugCreateNewInstance(); } instance = _factoryParameters.factoryMethod(); return instance; } + private void printDebugUseExistingInstance() { + if (_factoryParameters.instanceType !is null) { + writeln(format("DEBUG: Existing instance returned of type %s", _factoryParameters.instanceType.toString())); + } else { + writeln("DEBUG: Existing instance returned from custom factory method"); + } + } + + private void printDebugCreateNewInstance() { + if (_factoryParameters.instanceType !is null) { + writeln(format("DEBUG: Creating new instance of type %s", _factoryParameters.instanceType.toString())); + } else { + writeln("DEBUG: Creating new instance from custom factory method"); + } + } + protected Object createInstance() { enforce!InstanceCreationException(_factoryParameters.instanceType, "Instance type is not defined, cannot create instance without knowing its type."); return _factoryParameters.instanceType.create();