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

Long Type Problem (IllegalArgumentException) #99

Closed
gdw2 opened this issue May 16, 2012 · 2 comments
Closed

Long Type Problem (IllegalArgumentException) #99

gdw2 opened this issue May 16, 2012 · 2 comments
Milestone

Comments

@gdw2
Copy link
Contributor

gdw2 commented May 16, 2012

I have a simple data class. One of the attributes, the checksum, is of type "Long" and here is its setter definition:

public void setCheckSum(Long checksum)

From python, certain values throw an exception:

lib_bo.setCheckSum(905533471L) # Doesn't work
lib_bo.setCheckSum(1L) # Doesn't work
lib_bo.setCheckSum(2442549686L) # Works

And here is the traceback for the two that don't work:

Traceback (most recent call last):
  File "/home/gwarner/comission.py", line 173, in <module>
    import_bws(GCMS_HOST)
  File "/home/gwarner/comission.py", line 52, in import_bws
    lib_bo.setCheckSum(1L)#long(checksum)) #Long.getLong(str(checksum)))
  File "/usr/lib/python2.7/site-packages/py4j/java_gateway.py", line 432, in __call__
    self.target_id, self.name)
  File "/usr/lib/python2.7/site-packages/py4j/protocol.py", line 271, in get_return_value
    raise Py4JError('An error occurred while calling %s%s%s. Trace:\n%s\n' % (target_id, '.', name, value))
py4j.protocol.Py4JError: An error occurred while calling o37.setCheckSum. Trace:
java.lang.IllegalArgumentException: java.lang.ClassCastException@5e2d3c48
        at sun.reflect.GeneratedMethodAccessor2317.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:119)
        at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:392)
        at py4j.Gateway.invoke(Gateway.java:255)
        at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:124)
        at py4j.commands.CallCommand.execute(CallCommand.java:81)
        at py4j.GatewayConnection.run(GatewayConnection.java:175)
        at java.lang.Thread.run(Unknown Source)
      lib_bo.setCheckSum(1L) 

I would expect all three examples to work.

@gdw2
Copy link
Contributor Author

gdw2 commented May 16, 2012

I implemented a work around by adding support for Long primitives. I doubt this is the right answer because if it were, you'd have done it in the first place. Sending you a pull request so you can at least look at it.

gdw2@8f7c992

@bartdag
Copy link
Collaborator

bartdag commented Jul 21, 2012

Thank you very much for the pull request. Actually, I thought that I could get away with int to long conversion (because python is more relaxed when it comes to long primitives), but the autoboxing from int primitive to Long object on the Java side did not work. Your patch fixed the problem and make the protocol more correct.

Python integers that are too large to fit in a Java integer are still converted to long primitive when possible (that was always supported).

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