relaxng / jing-trang

Schema validation and conversion based on RELAX NG
http://www.thaiopensource.com/relaxng/
Other
228 stars 69 forks source link

RELAX NG Invalid value for regex - error message lists regexes in random order #247

Open walmsleyph opened 5 years ago

walmsleyph commented 5 years ago

This is a really minor issue, but when a datatype lists multiple possible regexes, and Jing correctly reports that a value is invalid, it lists all the regexes but in random order. For example, the error message might be

value of attribute "x" is invalid; must be a string matching the regular expression "a", must be a string matching the regular expression "b" or must be a string matching the regular expression "c"

one time, but then the next time it lists them in c, b, a order.

It's a minor thing, but it is wreaking havoc with our regression tests that are looking for a specific error message. It would be great if they could be in the order they are listed in the RELAX NG schema, which is probably the most logical.

sideshowbarker commented 5 years ago

If you could provide a test case I can use to reproduce the problem, that’s be super great.

I think the code that’s composing the content of that error message is here:

https://github.com/relaxng/jing-trang/blob/a3ec4cd650f48ec00189578f314fbe94893cd92d/mod/pattern/src/main/com/thaiopensource/relaxng/pattern/PatternMatcher.java#L420-L425

…but without having a test case or constructing one, we can’t really know for sure and can’t do much specific troubleshooting to isolate the cause of the random ordering.

As you can in that code snippet, Collections.sort(stringValues) is getting called on what I think is the list of string that are getting emitted in the error message you’re seeing. So I would assume that ought to be putting the message strings into the same order each time. But despite that sort(…), clearly in the end the strings are not actually ending up in the same order each time. Or else my assumption about the relevant part of the code is wrong…