From 24020e0f1b6e1cef2b68a33c607da87272100d5c Mon Sep 17 00:00:00 2001 From: markpollack Date: Sat, 14 Jun 2008 12:28:37 +0000 Subject: [PATCH] SPRNET-961 - Exception handling advice throws NullReferenceException when using swallow action on methods that return value types (introduced error when handling method with void return type --- .../Spring.Aop/Aspects/Exceptions/ExceptionHandlerAdvice.cs | 2 +- .../Exception/ExceptionHandlerAspectIntegrationTests.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Spring/Spring.Aop/Aspects/Exceptions/ExceptionHandlerAdvice.cs b/src/Spring/Spring.Aop/Aspects/Exceptions/ExceptionHandlerAdvice.cs index f089ebb3..5d0cf6d6 100644 --- a/src/Spring/Spring.Aop/Aspects/Exceptions/ExceptionHandlerAdvice.cs +++ b/src/Spring/Spring.Aop/Aspects/Exceptions/ExceptionHandlerAdvice.cs @@ -185,7 +185,7 @@ namespace Spring.Aspects.Exceptions else { Type returnType = invocation.Method.ReturnType; - return returnType.IsValueType ? Activator.CreateInstance(returnType) : null; + return returnType.IsValueType && !returnType.Equals(typeof(void))? Activator.CreateInstance(returnType) : null; } } } diff --git a/test/Spring/Spring.Aop.Tests/Aspects/Exception/ExceptionHandlerAspectIntegrationTests.cs b/test/Spring/Spring.Aop.Tests/Aspects/Exception/ExceptionHandlerAspectIntegrationTests.cs index ba6fbed6..d6e89750 100644 --- a/test/Spring/Spring.Aop.Tests/Aspects/Exception/ExceptionHandlerAspectIntegrationTests.cs +++ b/test/Spring/Spring.Aop.Tests/Aspects/Exception/ExceptionHandlerAspectIntegrationTests.cs @@ -309,9 +309,9 @@ namespace Spring.Aspects.Exceptions try { to.Exceptional(new ArithmeticException("Bad Math")); - } catch (Exception) + } catch (Exception e) { - Assert.Fail("Should not have thrown exception"); + Assert.Fail("Should not have thrown exception" + e); } }