Skip to content
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

enhance type-checked result effect during the call to createQuery() #8152

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

FULaBUla
Copy link

@FULaBUla FULaBUla commented Apr 11, 2024

I have provided an implementation for HH-17926, please check it out.

https://hibernate.atlassian.net/browse/HHH-17926

@FULaBUla FULaBUla changed the title HHH-17926 enhance type-checked result effect during the call to createQuery() enhance type-checked result effect during the call to createQuery() Apr 11, 2024
if ( dynamicInstantiation.isFullyAliased() ) {
throw new SemanticException( "Missing constructor or attributes for injection into type '" + typeName + "'", query );
throw new SemanticException("Missing constructor or attributes for injection into type [" + type + "]." +
Copy link
Member

Choose a reason for hiding this comment

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

Please back out this change and the other one like it.

  • we don't need punctuation at the end of exception messages, that's quite nonstandard, and
  • I have been gradually migrating to the use of single quotes for quoting the names of program elements, since square brackets have more visual weight than is needed for this purpose.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for reminding me, I have finished the modification

@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Apr 12, 2024

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

# change
1. remove punctuation at the end of exception messages
2. replace square brackets with single quotes
if ( dynamicInstantiation.isFullyAliased() ) {
throw new SemanticException( "Missing constructor or attributes for injection into type '" + typeName + "'", query );
throw new SemanticException("Missing constructor or attributes for injection into type '" + type + "'" +
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
throw new SemanticException("Missing constructor or attributes for injection into type '" + type + "'" +
throw new SemanticException("Missing constructor or attributes for injection into type '" + type.getSimpleName() + "'" +

Copy link
Author

Choose a reason for hiding this comment

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

I think a type description like com.excemple.A would be clearer than just
showing A, especially if there are classes with duplicate names, and
would make it easier to find problematic classes more quickly.

Copy link
Member

@gavinking gavinking Apr 13, 2024

Choose a reason for hiding this comment

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

I'm not certain I agree, but anyway that's not what you have there. You are calling Class.toString(), which does not just return the qualified name.

Copy link
Author

@FULaBUla FULaBUla Apr 13, 2024

Choose a reason for hiding this comment

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

I understand your concern, I've used Class.getName() replace Class.toString().

# change
1. using Class.getName() replace Class.toString()
Comment on lines 1515 to 1516
.map(InstantiationHelper.MismatchConstructorFieldPositionInfo::toString)
.collect(Collectors.joining(","));
Copy link
Member

Choose a reason for hiding this comment

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

You can use StringHelper.join() for this.

Copy link
Author

Choose a reason for hiding this comment

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

I have finished the modification

List<InstantiationHelper.MismatchConstructorFieldPositionInfo> list = dynamicInstantiation.findMismatchConstructorFieldPositions(creationContext.getTypeConfiguration());

String conjecture = "";
if (list != null && list.isEmpty() == false) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (list != null && list.isEmpty() == false) {
if ( list != null && !list.isEmpty() ) {

Copy link
Author

Choose a reason for hiding this comment

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

I have finished the modification

Comment on lines 1519 to 1520
throw new SemanticException("Unable to locate appropriate constructor on class '" + qualifiedName + "'. " +
"Expected arguments are: " + dynamicInstantiation.argumentTypes() + conjecture, query);
Copy link
Member

@gavinking gavinking Apr 18, 2024

Choose a reason for hiding this comment

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

Suggested change
throw new SemanticException("Unable to locate appropriate constructor on class '" + qualifiedName + "'. " +
"Expected arguments are: " + dynamicInstantiation.argumentTypes() + conjecture, query);
throw new SemanticException( "Missing constructor for class '" + qualifiedName + "' with parameter types ["
+ dynamicInstantiation.argumentTypes() + "] (" + conjecture + ")", query );

Copy link
Author

Choose a reason for hiding this comment

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

I have finished the modification


String conjecture = "";
if (list != null && list.isEmpty() == false) {
conjecture = " The presumed mismatch field position is: " +
Copy link
Member

@gavinking gavinking Apr 18, 2024

Choose a reason for hiding this comment

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

Suggested change
conjecture = " The presumed mismatch field position is: " +
conjecture = "mismatch at position " +

Copy link
Author

Choose a reason for hiding this comment

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

I have finished the modification

Comment on lines 1505 to 1506
throw new SemanticException("Missing constructor or attributes for injection into type '" + qualifiedName + "'" +
"Expected arguments are: " + dynamicInstantiation.argumentTypes(), query);
Copy link
Member

@gavinking gavinking Apr 18, 2024

Choose a reason for hiding this comment

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

Suggested change
throw new SemanticException("Missing constructor or attributes for injection into type '" + qualifiedName + "'" +
"Expected arguments are: " + dynamicInstantiation.argumentTypes(), query);
throw new SemanticException( "Missing constructor or attributes for injection into class '" + qualifiedName + "'" +
" of selected types [" + dynamicInstantiation.argumentTypes() + "]", query );

Copy link
Author

Choose a reason for hiding this comment

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

I have finished the modification

# change
1. modify code format
2. modify the format of exception information
# change
1. use StringHelper.join() instead of stream processing
@FULaBUla
Copy link
Author

Is there anything I would like to change about this branch? @gavinking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants