Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import org.apache.xbean.propertyeditor.PropertyEditorRegistry;
import org.apache.xbean.recipe.ReflectionUtil.*;
Expand Down Expand Up @@ -270,7 +273,11 @@ protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throw

//
// clone the properties so they can be used again
Map<Property,Object> propertyValues = new LinkedHashMap<Property,Object>(properties);
Map<Property,Object> propertyValues = options.contains(Option.CASE_INSENSITIVE_PROPERTIES)
? new TreeMap<>(Comparator.comparing(property -> property.name, String.CASE_INSENSITIVE_ORDER))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new TreeMap<>(String.CASE_INSENSITIVE_ORDER) should be sufficient

: new LinkedHashMap<>();

propertyValues.putAll(properties);

//
// create the instance
Expand Down Expand Up @@ -567,11 +574,18 @@ private Factory findFactory(Type expectedType) {
consturctorClass = type;
}

Set<String> availableProperties = getProperties().keySet();
if (options.contains(Option.CASE_INSENSITIVE_PROPERTIES)) {
Set<String> caseInsensitiveProperties = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
caseInsensitiveProperties.addAll(availableProperties);
availableProperties = caseInsensitiveProperties;
}

ConstructorFactory constructor = ReflectionUtil.findConstructor(
consturctorClass,
constructorArgNames,
constructorArgTypes,
getProperties().keySet(),
availableProperties,
options);

return constructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ private static String toParameterList(List<? extends Class<?>> parameterTypes) {
for (int i = 0; i < parameterTypes.size(); i++) {
Class type = parameterTypes.get(i);
if (i > 0) buffer.append(", ");
buffer.append(type.getName());
buffer.append(type != null ? type.getName() : "...");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when can it be null?

Copy link
Member Author

@jungm jungm Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tomee passes parameterTypes=null which is then converted to a list of nulls in findConstructor, and toParameterList gets invoked to generate exception messages

for example: https://ci-builds.apache.org/job/Tomee/view/tomee-10.x/job/tomee-10-build-full/org.apache.tomee$arquillian-tomee-webprofile-tests/43/testReport/junit/org.apache.openejb.arquillian.tests.bmp.local/BmpLocalEntityTest/___/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I guessed so but why does it happen now and was not before? Is it about the ServiceProviders, did something changed ?

to be clear I'm not against the change just want to ensure it is not a misusage cause we are loosing information there in user facing error messages, will be less usable ("oh it failed in constructor Foo(..., ..., ....)")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this happened as a side effect of XBEAN-350. Since we fixed that issue, the code path is now reachable with null type parameters through implicit constructor resolution using argument names (in which case the type list is nulled). On the TomEE side, nothing has changed in that regard

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, didn't get a change to check but was my fear, so this sounds like a regression we might want to fix before next release - and therefore not do this change in this PR, wdyt?

Copy link
Contributor

@rzo1 rzo1 Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a regression technically. More or less a bug of this utility method to produce a user facing error messages and don't account for null values.

What we might want to fix is likely another type of error message accounting for the null containing type list in case we fail via implicit ctor arg resolution and no types are available/present. That would be more helpful for the error msg.

I agree - we can change and track it in an other issue and revert it here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposed to use Object instead of ... to explicit it was a loose matching -> #48, feel free to take it back or rework it, it is just a proposal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmannibucau I like the idea to use Object instead (+ the fix regarding the factory method compare); I added some comments + a test since it was breaking in TomEE for the static factory case :)

}
} else {
buffer.append("...");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xbean.recipe;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class XBean353Test {

@Test
public void testCreateObjectCaseInsensitive() {
final Map<String, Object> availableProperties = new HashMap<>();
availableProperties.put("PoolSize", 10);

final String[] paramNames = new String[]{"poolSize"};
ObjectRecipe recipe = new ObjectRecipe(Constructor.class, paramNames);
recipe.setAllProperties(availableProperties);
recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);

final Object o = recipe.create();
assertNotNull(o);
assertTrue(o instanceof Constructor);
assertEquals(10, ((Constructor) o).poolSize);
}

public static class Constructor {

int poolSize;

public Constructor(int poolSize) {
this.poolSize = poolSize;
}
}
}