Fix nullpointer exception when debugging with poodinisVerbose

This commit is contained in:
Mike Bierlee 2016-12-06 23:14:19 +01:00
parent f1bd2260d1
commit 2a52fc9af4
2 changed files with 21 additions and 2 deletions

View file

@ -1,5 +1,8 @@
Poodinis Changelog Poodinis Changelog
================== ==================
**Version NEXT**
* FIX nullpointer exception in instance factory when debugging with poodinisVerbose
**Version 7.0.1** **Version 7.0.1**
* FIX codegeneration of constructor injection factories for constructors with dependencies from foreign modules, * FIX codegeneration of constructor injection factories for constructors with dependencies from foreign modules,
such as modules from other libraries (Issue #12). such as modules from other libraries (Issue #12).

View file

@ -67,20 +67,36 @@ class InstanceFactory {
public Object getInstance() { public Object getInstance() {
if (_factoryParameters.createsSingleton && instance !is null) { if (_factoryParameters.createsSingleton && instance !is null) {
debug(poodinisVerbose) { debug(poodinisVerbose) {
writeln(format("DEBUG: Existing instance returned of type %s", _factoryParameters.instanceType.toString())); printDebugUseExistingInstance();
} }
return instance; return instance;
} }
debug(poodinisVerbose) { debug(poodinisVerbose) {
writeln(format("DEBUG: Creating new instance of type %s", _factoryParameters.instanceType.toString())); printDebugCreateNewInstance();
} }
instance = _factoryParameters.factoryMethod(); instance = _factoryParameters.factoryMethod();
return instance; 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() { protected Object createInstance() {
enforce!InstanceCreationException(_factoryParameters.instanceType, "Instance type is not defined, cannot create instance without knowing its type."); enforce!InstanceCreationException(_factoryParameters.instanceType, "Instance type is not defined, cannot create instance without knowing its type.");
return _factoryParameters.instanceType.create(); return _factoryParameters.instanceType.create();