-
Notifications
You must be signed in to change notification settings - Fork 41
XBEAN-453 - honor Option.CASE_INSENSITIVE_PROPERTIES for ctors #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() : "..."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when can it be null?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tomee passes
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(..., ..., ....)")
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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("..."); | ||
|
|
||
| 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; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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