-
Notifications
You must be signed in to change notification settings - Fork 172
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
Block processor attributes is Map<String, Object> but may contain non-String keys. #450
Comments
%s/Integer/Long/g |
You are correct that block attributes can have numeric keys. These are the positional attributes. Unfortunately, accommodating that scenario would mean a change in a lot of places. One solution is to coerce those numeric keys to strings at the boundary of Ruby and Java. The other is updating the signature of attributes on all nodes to be a |
I think we have sorted it out in the 1.6.0 branch by skipping numeric attributes which should always be positional attributes. |
I vaguely remember discussing that as well. I case did come up recently when accessing the positional attribute directly was necessary. However, I think if we decide we do want to still keep them, we will use string-based keys to map them back in so that we can stick with string-based keys. The numeric keys really should be considered an internal API. |
Oops, it's not sorted out. Thank you for reporting! |
Fixes #450, Pass a RubyAttributesMapDecorator to Processors.
Fixed in a2967ea. |
👍 |
Oh no! I mean, thanks for fixing quickly, but the fix makes things all the worse for me because it simply removes attributes with numeric keys rather than coerce them to Strings--so now I can't get at the positional attributes! I can work around the original issue, but I don't know that I can work around the fix :) Would you consider coercing numeric keys to String instead of ignoring/removing them? |
Hi, The current approach is to define the positional attributes as options to Cheers Am Sonntag, 24. April 2016 schrieb jjaderberg :
|
I see--yes, I can work with that. Thanks! |
A block processor needs to take a
Map<String, Object>
argument for "attributes", but the map that is passed may contain non-String keys.The following block processor throws a
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
when treating all map keys as strings.The exception is thrown in the for loop because one or more keys in the map are
Integer
s.If I change the style of the block in the AsciiDoc source to
source
, no exception is thrown.My guess is that "custom attributes" are keyed by
Integer
s in the attributes map.If that's the case, maybe the signature of
BlockProcessor#process()
should type 'attributes' asMap<Object, Object>
, or maybe some type coersion magic needs to happen to make sure the generics of the map in the signature are respected.It works to treat the map as if it were
<Object, Object>
, at least for theInteger
case.Since there is a
Integer#toString()
method, treating a key as anObject
in the for loop works just fine.Block processor:
Test:
AsciiDoc source:
The text was updated successfully, but these errors were encountered: