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

Java client code for printing messages/errors is buggy #242

Closed
daveyarwood opened this issue Jun 20, 2016 · 2 comments
Closed

Java client code for printing messages/errors is buggy #242

daveyarwood opened this issue Jun 20, 2016 · 2 comments
Assignees
Milestone

Comments

@daveyarwood
Copy link
Member

Full disclosure: I'm not the best Java programmer. When I wrote the Java code for the Alda client, I included a couple of convenience functions for printing messages and errors that bubble up from the Alda servers. These functions are basically wrappers around printf, with some program-specific context like the port the server is running on.

Occasionally, things can get weird if the message or error strings happens to contain some unexpected formatting characters like %s. This may be what was happening here in the stacktrace @elyisgreat was getting.

I'm opening this up to all the Java programmers out there:

  1. Is there a way these convenience functions can be made more robust so that they won't fail if the message string contains unexpected format characters?
  2. Is the java.util.UnknownFormatConversionException: Conversion = '1' error indicative of some other problem?
@jgkamat
Copy link
Contributor

jgkamat commented Jun 20, 2016

Sorry for not contributing in a long time, I've been kind of backed up on other projects, but I'll probably work a bit more on alda in about a month!

That error message is likely something wrong with the inputs into printf, either % directives that don't exist (like %q I think?), or perhaps there are an incorrect number of % directives. From the error, I'm guessing that there is a %1 in your input to printf.

In general, java programmers don't use printf, as the built in string addition is more robust and easier to use.

The possible solutions I can think of are:

  1. (the easiest) Make sure inputs into the msg functions are valid printf statements, and make sure you have the correct number of arguments. Effectively, you would be treating msg as a printf function, as you do now. If you do this, it's up to callers of this function to make sure the input is valid. In this case, you would have to make sure the prefix variable does not contain any printf special characters.
  2. Switch over to use string addition entirely, by passing in a list of args, and your function will string concatenate them and print them out.
  3. (probably the cleanest) pass a pure string into msg and let the caller deal with concatenation and message formatting. The caller could make a sprintf (equivalent) call themselves.

If I have a bit of free time I'll look at the error thats in the attached issue.

@daveyarwood
Copy link
Member Author

Fixed in 1.0.0-rc48.

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

No branches or pull requests

3 participants