You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by smurphy <sm...@trustwave.com> on 2018/09/24 22:05:19 UTC

java.lang.IllegalArgumentException: Can not set final

FragmentAssignToScannerEntryProcessor.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1317/FragmentAssignToScannerEntryProcessor.java>  
BinaryFragmentConverter.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1317/BinaryFragmentConverter.java>  

I am running 2 server nodes with peer class loading enabled and no custom
classes on the server classpaths.
I am using an EntryProcessor with a custom class constructor injected as a
private final member variable (both files are attached).
The custom class cannot be deserialized with the following stack trace:






--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: java.lang.IllegalArgumentException: Can not set final

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

I think you should avoid having final fields in classes sent over to nodes
for execution. I also think that you should mark _ignite field with
@IgniteInstanceResource (it might work anyway but this is more of Ignite
way)

Regards,
-- 
Ilya Kasnacheev


пт, 28 сент. 2018 г. в 21:09, smurphy <sm...@trustwave.com>:

> Hi Ilya,
>
> I don't think the errors are caused by the binary objects, but by having
> custom objects in the EntryProcessor. Checkout the attached
> FragmentAssignToScannerEntryProcessor.java. Instead of injecting the
> BinaryFragmentConverter into FragmentAssignToScannerEntryProcessor, I moved
> all the binary object code from BinaryFragmentConverter directly into
> FragmentAssignToScannerEntryProcessor.
> This works fine.
>
> Then I created the static FragmentAssignToScannerEntryProcessor.Tester
> class, which has no binary objects, and added it as a member variable of
> FragmentAssignToScannerEntryProcessor and that resulted in the same
> IllegalArgumentException as before: "failed to read field [name=tester]"
>
> FragmentAssignToScannerEntryProcessor.java
> <
> http://apache-ignite-users.70518.x6.nabble.com/file/t1317/FragmentAssignToScannerEntryProcessor.java>
>
>
> stackTrace.txt
> <http://apache-ignite-users.70518.x6.nabble.com/file/t1317/stackTrace.txt>
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: java.lang.IllegalArgumentException: Can not set final

Posted by smurphy <sm...@trustwave.com>.
Hi Ilya,

I don't think the errors are caused by the binary objects, but by having
custom objects in the EntryProcessor. Checkout the attached
FragmentAssignToScannerEntryProcessor.java. Instead of injecting the
BinaryFragmentConverter into FragmentAssignToScannerEntryProcessor, I moved
all the binary object code from BinaryFragmentConverter directly into
FragmentAssignToScannerEntryProcessor. 
This works fine.

Then I created the static FragmentAssignToScannerEntryProcessor.Tester
class, which has no binary objects, and added it as a member variable of
FragmentAssignToScannerEntryProcessor and that resulted in the same
IllegalArgumentException as before: "failed to read field [name=tester]"

FragmentAssignToScannerEntryProcessor.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1317/FragmentAssignToScannerEntryProcessor.java>  

stackTrace.txt
<http://apache-ignite-users.70518.x6.nabble.com/file/t1317/stackTrace.txt>  



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: java.lang.IllegalArgumentException: Can not set final

Posted by Ilya Kasnacheev <il...@gmail.com>.
Oh!

Normally, BinaryObject should of course work with both boxed and unboxed
fields.

Note that BinaryObject has setField(name, val, type) - > you can pass
Integer.class or you may pass Integer.TYPE there to get different behaviour.

Unfortunately it's hard to say more just from the fragments of code that
you have provided.

Regards,
-- 
Ilya Kasnacheev


вт, 25 сент. 2018 г. в 21:56, smurphy <sm...@trustwave.com>:

> Thanks for the responses.
>
> Ilya - I did try your suggestion: removing the final modifier, deleting the
> constructor and only using getters and setters.
> I even went as far as to make the fields public.
> All these changes resulted in the an IllegalArgumentException.
>
> If it helps, I was able to write a JUnit that replicated the exception and
> fixed it along the lines of the following article:
>
> https://docs.oracle.com/javase/tutorial/reflect/member/fieldTrouble.html
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: java.lang.IllegalArgumentException: Can not set final

Posted by smurphy <sm...@trustwave.com>.
Thanks for the responses.

Ilya - I did try your suggestion: removing the final modifier, deleting the
constructor and only using getters and setters. 
I even went as far as to make the fields public. 
All these changes resulted in the an IllegalArgumentException.

If it helps, I was able to write a JUnit that replicated the exception and
fixed it along the lines of the following article:

https://docs.oracle.com/javase/tutorial/reflect/member/fieldTrouble.html



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: java.lang.IllegalArgumentException: Can not set final

Posted by vkulichenko <va...@gmail.com>.
Probably that's the issue :) In any case, Java serialization successfully
deserializes such objects, so I think it's a bug.

-Val



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: java.lang.IllegalArgumentException: Can not set final

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

I can see that java.lang.reflect.Field is used. Why would it set final
fields?

Regards,
-- 
Ilya Kasnacheev


вт, 25 сент. 2018 г. в 19:22, vkulichenko <va...@gmail.com>:

> Ilya,
>
> Do you know what is the reason for such limitation? It doesn't sounds right
> to me, I believe any other marshaller would work just fine with final
> fields.
>
> -Val
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: java.lang.IllegalArgumentException: Can not set final

Posted by vkulichenko <va...@gmail.com>.
Ilya,

Do you know what is the reason for such limitation? It doesn't sounds right
to me, I believe any other marshaller would work just fine with final
fields.

-Val



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: java.lang.IllegalArgumentException: Can not set final

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

You can't set final fields when deserializing binary objects.

Consider changing them to non-final fields with getter-setter.

Regards,
-- 
Ilya Kasnacheev


вт, 25 сент. 2018 г. в 1:31, smurphy <sm...@trustwave.com>:

> Hmm pasting the stack trace into the page didn't work.
> Here it is as an attachment..:
>
>
> stackTrace.txt
> <http://apache-ignite-users.70518.x6.nabble.com/file/t1317/stackTrace.txt>
>
>
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: java.lang.IllegalArgumentException: Can not set final

Posted by smurphy <sm...@trustwave.com>.
Hmm pasting the stack trace into the page didn't work.
Here it is as an attachment..:


stackTrace.txt
<http://apache-ignite-users.70518.x6.nabble.com/file/t1317/stackTrace.txt>  





--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/