Search code examples
quarkusquarkus-qute

Quarkus + Qute + MessageBundle: java.nio.charset.MalformedInputException: Input length = 1


I want to have all the messages on my system in a msg.properties file that follows the key=value pattern, where can I find an example?

I tried like below:

resources/messages/msg.properties invalid-data=the message comes here

AppMessages.java

@MessageBundle
public interface AppMessages {
    @Message
    String invalidData();
}

MyService.java

@ApplicationScoped
public class MyService {

    @Inject
    AppMessages messages;

    @Transactional
    public void create() throws Exception {
        if (true) {
            throw new IllegalArgumentException(messages.invalidData());
        }
       ...
    }
...
}

But I getting the error during the build:

ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors [error]: Build step io.quarkus.qute.deployment.MessageBundleProcessor#processBundles threw an exception: java.lang.IllegalStateException: java.nio.charset.MalformedInputException: Input length = 1

How to solve this problem?

---EDIT---

I don't know why when creating a file in IntelliJ even though it is configure for UTF-8, the file is being created with ISO encoding, so I created the file via terminal and another error appears.

Caused by: io.quarkus.qute.deployment.MessageBundleException: Message bundle method invalid-data() not found on: pt.sharecar.messages.AppMessages
    - file: /myproject/target/classes/messages/msg.properties
    - line 0

If I put the name of the method in the properties file it starts to work, but according to the documentation it was supposed to work using "-"


Solution

  • I don't know why when creating a file in IntelliJ even though it is configure for UTF-8, the file is being created with ISO encoding, so I created the file via terminal and another error appears.

    So yes, the file must be encoded in UTF-8.

    If I put the name of the method in the properties file it starts to work, but according to the documentation it was supposed to work using "-"

    The keys in the localized file are mapped to the method names from the message bundle interface, i.e. the file should contain invalidData=the message comes here. I suppose that you're using the io.quarkus.qute.i18n.Message.HYPHENATED_ELEMENT_NAME strategy - the transformed method name is only used in templates, e.g {msg:invalid-data}.

    See also Qute docs about localization files.