[JIRA] (HSEARCH-4714) Early sanity checks for property names
by Yoann Rodière (JIRA)
Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate Search ( https://hibernate.atlassian.net/browse/HSEARCH?atlOrigin=eyJpIjoiYjhlNDU1... ) / Improvement ( https://hibernate.atlassian.net/browse/HSEARCH-4714?atlOrigin=eyJpIjoiYjh... ) HSEARCH-4714 ( https://hibernate.atlassian.net/browse/HSEARCH-4714?atlOrigin=eyJpIjoiYjh... ) Early sanity checks for property names ( https://hibernate.atlassian.net/browse/HSEARCH-4714?atlOrigin=eyJpIjoiYjh... )
Issue Type: Improvement Assignee: Unassigned Components: mapper-pojo-base Created: 10/Oct/2022 04:59 AM Fix Versions: 6.2-backlog Priority: Minor Reporter: Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
It’s possible for users to write this by mistake:
@IndexingDependency(derivedFrom = { @ObjectPath({ @PropertyValue(propertyName = "audit.username") }) })
When they should be writing this:
@IndexingDependency(derivedFrom = { @ObjectPath({ @PropertyValue(propertyName = "audit"), @PropertyValue(propertyName = "username") }) })
The mistake is understandable, given the syntax is a bit obscure and cumbersome (we’ll address that in https://hibernate.atlassian.net/browse/HSEARCH-4392 ( https://hibernate.atlassian.net/browse/HSEARCH-4392 ) ).
However, this mistake currently produces the following error, which is itself quite puzzling at first sight:
- HSEARCH700078: No readable property named 'audit.username' on type .....
We could improve the developer experience slightly by validating property names when they are extracted from PropertyValue.propertyName , checking in particular that the property name doesn’t contain any dot or any metacharacter that org.hibernate.search.mapper.pojo.model.path.PojoModelPath#parse understands, throwing an exception saying something like Property names must not contain dots. It wouldn't be perfect, but at least would give some hint of what's going on.
Suggestion of implementation:
I would personally put this validation code in org.hibernate.search.mapper.pojo.model.path.PojoModelPath.Builder#property , or (perhaps better) in org.hibernate.search.mapper.pojo.model.path.PojoModelPathPropertyNode#PojoModelPathPropertyNode.
Perhaps we could also add something like this to org.hibernate.search.mapper.pojo.mapping.definition.annotation.processing.impl.AbstractMappingAnnotationProcessorContext#toPojoModelPathValueNode , to provide a bit more context:
try {
...
} catch (SearchException e) {
throw log.invalidObjectPath( objectPath, e.getMessage(), e );
}
( https://hibernate.atlassian.net/browse/HSEARCH-4714#add-comment?atlOrigin... ) Add Comment ( https://hibernate.atlassian.net/browse/HSEARCH-4714#add-comment?atlOrigin... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:591c2ef )
2 years, 3 months