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

LFE Can't handle java.lang.String objects from Erjang #84

Open
oubiwann opened this issue Apr 7, 2014 · 4 comments
Open

LFE Can't handle java.lang.String objects from Erjang #84

oubiwann opened this issue Apr 7, 2014 · 4 comments

Comments

@oubiwann
Copy link

oubiwann commented Apr 7, 2014

Here's a simple example of the problem in action:

> (set str (java.lang.String:new '"some string"))
exception error: badarg
  in (: lfe_io_pretty print1 "some string")
>

This seems to be a problem of displaying java.lang.String objects. Using a let (an operation which doesn't attempt to display the result) gets around the problem highlighted in the example above:

> (let ((str (java.lang.String:new '"some string")))
     (java:call str 'getClass '() '()))
java.lang.String
>
@oubiwann
Copy link
Author

oubiwann commented Apr 7, 2014

I followed up last night on the mail list about this one; Kresten had previously given this excellent information:

"… is probably some error in the value mapping. Its a bit complex, and if you want to dive into it I can explain more. But essentially a JavaObject thing can act as more than one kind of erlang term, depending on how you deconstruct it with pattern matching. For Java strings, we keep the string around, wrapped in a synthetic cons cell that will allow you to access head and tail..."

In LFE's src/lfe_io_pretty.erl, I made the following change:

@@ -47,6 +47,10 @@ print1([quote,E], D, I, L) -> ["'",print1(E, D, I+1, L)];
 print1([backquote,E], D, I, L) -> ["`",print1(E, D, I+1, L)];
 print1([unquote,E], D, I, L) -> [",",print1(E, D, I+1, L)];
 print1(['unquote-splicing',E], D, I, L) -> [",@",print1(E, D, I+2, L)];
+%% Handle specialized forms from Erjang
+print1([Head|Tail], _, _, _) when is_list(Head) and is_list(Tail) ->
+    Head ++ Tail;
+%% Continue with cons matching ...
 print1([Car|_]=List, D, I, L) ->
     %% Handle printable lists specially.
     case io_lib:printable_list(List) of

At first, this didn't seem to be stomping on any of the other patterns in the LFE pretty printer, but after a bit more testing, I'm unconvinced. I'm going to dig into this some more and explore some more edge cases.

I will open a new ticket in LFE for all of this.

@krestenkrab
Copy link
Contributor

Does your change make it work? Because that could give some good hints for where to go bug-hunting in the Erjang code.

@oubiwann
Copy link
Author

oubiwann commented Apr 7, 2014

Excellent -- will try again with the change (once I've gotteb it to a point where I think Robert might approve!).

@oubiwann
Copy link
Author

I'm going to update this ticket to be more specific, now that we're getting closer to the issue. Here was the original description, for future reference:

The following returns an error in LFE:

> (java.lang.System:getProperty '"java.io.tmpdir")
exception error: badarg
  in (: lfe_io_pretty
        print1
       "/var/folders/c8/2cl5l5_102b1qq8bh05t7xw40000gn/T/")

The same call in Erjang-proper:

10> 'java.lang.System':getProperty("java.io.tmpdir").
"/var/folders/c8/2cl5l5_102b1qq8bh05t7xw40000gn/T/"

This may be an issue in LFE; I will investigate and report back my findings to this ticket.

@oubiwann oubiwann changed the title LFE error when calling java.lang.System method LFE Can't handle java.lang.String objects from Erjang Apr 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants