-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
On eval of Time#strftime read from file: Java::JavaLang::Error: Unknown special char: Y #5179
Comments
Shorter reproduction:
No Gemfile needed. The next reproduction, excluding more code, would be
but that doesn't reproduce the issue anymore. |
wanted to look into this but (yet) seems Bundler 1.16.2 specific ... which must be a recent release 😞
|
Problem turns out to be independent of bundler. Smaller reproduction:
where Passes on JRuby 9.1.17.0. |
A quick glance and some notes. default will be UTF-8 for eval and that works and so does even more uncommon encodings which are ascii compatible like EUC-JP. If I force_encoding of the format string I can see that we also work. So ASCII-BINARY strftime format string is our problem. Reduced more: Time.now.strftime('%Y-%m-%d'.force_encoding('ASCII-8BIT')) |
The following patch fixes it. Without calling into this line, the Format class never initializes properly, which leaves the conversion token mapping array unpopulated, so all tokens come out null. This isn't the right fix; the Format enumeration needs to be allowed to initialize properly before the parsing proceeds. It doesn't without this code because all subsequent logic goes directly for the conversion array, which doesn't trigger the class initialization. diff --git a/core/src/main/java/org/jruby/util/RubyDateFormatter.java b/core/src/main/java/org/jruby/util/RubyDateFormatter.java
index fb9618e086..dc1193dee0 100644
--- a/core/src/main/java/org/jruby/util/RubyDateFormatter.java
+++ b/core/src/main/java/org/jruby/util/RubyDateFormatter.java
@@ -266,9 +266,9 @@ public class RubyDateFormatter {
}
final List<Token> compiledPattern = new LinkedList<Token>();
- if (enc != ASCIIEncoding.INSTANCE) { // default for ByteList
+// if (enc != ASCIIEncoding.INSTANCE) { // default for ByteList
compiledPattern.add(new Token(Format.FORMAT_ENCODING, enc));
- }
+// }
ByteArrayInputStream in = new ByteArrayInputStream(pattern.getUnsafeBytes(), pattern.getBegin(), pattern.getRealSize());
Reader reader = new InputStreamReader(in, runtime.getEncodingService().charsetForEncoding(pattern.getEncoding())); |
The bug was introduced at 7b8221e by commenting out an access of one of the Format enum values. This forced the class, and the associated conversion array, to be initialized. I have a more complete fix in process. |
Environment
Current JRuby head on Ubuntu 16.04
Gemfile:
foo.gemspec:
Expected Behavior
This is a reduced case from an original setup that works correctly using JRuby 9.1.17.0, which I wanted to test using current JRuby head. Therefore the expected behavior as shown by MRI may seems silly, but what matters is that the JRuby output differs. MRI 2.5.0 with bundler 1.16.2 returns:
because the gemspec does not contain a valid Gem::Specification, but returns a String. This is also what JRuby 9.1.17.0 returns.
Actual Behavior
If you run with the debugger enabled, add a
debugger
statement on the first line of thefoo.gemspec
and manually execute the command, then you see it actually returns the correct answer (the current date in ISO8601 format) and subsequently the output becomes the same as the MRI output. But immediatelyc
ontinuing execution in the debugger session causes the original error.The text was updated successfully, but these errors were encountered: