MessageTools.getPropertyCaption(MetaClass, String, Locale) ignores the locale for inherited properties and property paths
Environment
Jmix version: 3.1.0 (also 3.0.3; the code is the same in master, release_2_7 and release_1_7)
Bug Description
MessageTools.getPropertyCaption(MetaClass, String, Locale) ignores the explicitly passed locale
when the key <ClassName>.<propertyName> is not found in the bundle of the entity's own class.
In this case the method falls back to MetaPropertyPath, but calls the overload without the locale:
// io.jmix.core.MessageTools, line 222
MetaPropertyPath propertyPath = metadataTools.resolveMetaPropertyPathOrNull(metaClass, propertyName);
if (propertyPath != null) {
return getPropertyCaption(propertyPath.getMetaProperty()); // locale is lost
}
getPropertyCaption(MetaProperty) passes null to getPropertyCaption(MetaProperty, Locale), which
then uses Messages.getMessage(Class, String), i.e. the locale of the current user.
The fallback is used in two common cases:
- the property is declared in an ancestor (
@MappedSuperclassor entity inheritance): Studio generates the keyParent.prop, notChild.prop; - a property path is passed, e.g.
"customer.name": a key likeOrder.customer.namenever exists.
So when captions are built for a locale other than the user's (reports, emails, background tasks, REST), captions of inherited properties and property paths come in the user's language.
Suggested fix:
return getPropertyCaption(propertyPath.getMetaProperty(), locale);
The behavior for locale == null doesn't change.
Steps To Reproduce
@JmixEntity
@MappedSuperclass
public class NamedEntity {
// id, version ...
@Column(name = "NAME")
private String name;
}
@JmixEntity
@Entity(name = "repro_Customer")
public class Customer extends NamedEntity {
@Column(name = "CODE")
private String code;
}
@JmixEntity
@Entity(name = "repro_SalesOrder")
public class SalesOrder {
// id ...
@ManyToOne(fetch = FetchType.LAZY)
private Customer customer;
}
messages.properties / messages_ru.properties (only the keys Studio generates):
com.company.repro.entity/NamedEntity.name=Name
com.company.repro.entity/Customer.code=Code
com.company.repro.entity/SalesOrder.customer=Customer
- Authenticate a user with the
rulocale (ClientDetails.locale). - Call:
messageTools.getPropertyCaption(metadata.getClass(Customer.class), "code", Locale.ENGLISH);
messageTools.getPropertyCaption(metadata.getClass(Customer.class), "name", Locale.ENGLISH);
messageTools.getPropertyCaption(metadata.getClass(SalesOrder.class), "customer.name", Locale.ENGLISH);
Current Behavior
Code, Название, Название
Expected Behavior
Code, Name, Name
Sample Project
jmix-messagetools-locale-repro.zip
A Gradle project with tests (Jmix 3.1.0, ./gradlew test): PropertyCaptionLocaleTest fails on the two
bug cases. PatchedPropertyCaptionLocaleTest runs the same tests with a MessageTools subclass that has
the one-line fix, and all of them pass.
Workaround: resolve the property first and call the MetaProperty overload, which respects the locale:
MetaPropertyPath path = metaClass.getPropertyPath(propertyName);
messageTools.getPropertyCaption(path.getMetaProperty(), locale);
Hi! I'd like to work on this. I'll add a regression test for the inherited property and property-path cases, then update MessageTools to preserve the requested locale. Please let me know if you have a different approach in mind.
Tested on: Jmix version: 3.1.999-SNAPSHOT Jmix Studio Plugin Version: 3.2.SNAPSHOT8847-262 IntelliJ version: IntelliJ IDEA 2026.2.5 Successful.