Skip to content

Commit ee9c3ce

Browse files
committed
null for attribute's array-typed ctor param causes NullReferenceException
1 parent 323c03f commit ee9c3ce

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/Castle.Core.Tests/DynamicProxy.Tests/ClassWithAttributesTestCase.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace Castle.DynamicProxy.Tests
1616
{
17+
using System;
1718
using System.IO;
1819
using System.Linq;
1920
using System.Reflection;
@@ -178,5 +179,22 @@ public void Can_proxy_type_with_non_inheritable_attribute_depending_on_array_of_
178179
.Cast<NonInheritableWithArray2Attribute>().Single();
179180
CollectionAssert.AreEqual(attribute.Values, new[] { "1", "2", "3" });
180181
}
182+
183+
[TestCase(typeof(HasAttributeWithNullAsPositionalArgument))]
184+
[TestCase(typeof(HasAttributeWithEmptyArrayAsPositionalArgument))]
185+
[TestCase(typeof(HasAttributeWithNullInArrayAsPositionalArgument))]
186+
public void Can_proxy_type_with_attribute_with_positional_array_parameter(Type classType)
187+
{
188+
_ = generator.CreateClassProxy(classType);
189+
}
190+
191+
[NonInheritableAttributeWithPositionalArrayParameter(null)]
192+
public class HasAttributeWithNullAsPositionalArgument{ }
193+
194+
[NonInheritableAttributeWithPositionalArrayParameter(new object[0])]
195+
public class HasAttributeWithEmptyArrayAsPositionalArgument { }
196+
197+
[NonInheritableAttributeWithPositionalArrayParameter(new object[1] { null })]
198+
public class HasAttributeWithNullInArrayAsPositionalArgument { }
181199
}
182200
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2004-2022 Castle Project - http://www.castleproject.org/
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace Castle.DynamicProxy.Tests.Classes
16+
{
17+
using System;
18+
19+
#if FEATURE_SERIALIZATION
20+
[Serializable]
21+
#endif
22+
[AttributeUsage(AttributeTargets.All, Inherited = false)]
23+
public class NonInheritableAttributeWithPositionalArrayParameterAttribute : Attribute
24+
{
25+
public NonInheritableAttributeWithPositionalArrayParameterAttribute(object[] arg)
26+
{
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)