How can you make sure that the object still exists? How to make the object exist at a certain point? There is such code:

public void onMouseDown(MouseDownEvent event) { final MouseDownEvent e = event; timer = new Timer() { @Override public void run() { int x = e.getX(); int y = e.getY(); } }; timer.schedule(timeDelay); } 

As a result, on the call int x = e.getX(); falls with an error.

(TypeError): Cannot read property 'clientX' of null arguments: clientX, type: non_object_property_load

How to make it so that after the timer is triggered to get access to all the fields of the MouseDownEvent object?

Is it possible to copy an object ( clone similarity)?

Tried to make a subclass and override some fields, did not help. Apparently, it is necessary, either to override everything, or to look for another way.

  • More like some kind of bug somewhere in the GWT. - cy6erGn0m
  • I have gwt 2.3.0. - Nicolas Chabanovsky ♦
  • I understand that you, of course, checked that e! = Null really? - cy6erGn0m
  • Yes. Only it does not solve the problem: ( - Nicolas Chabanovsky ♦
  • Place final MouseDownEvent e = event; inside timer = new Timer (), but in fact, at the moment when the timer is triggered on the object MouseDownEvent, the links may not be from anywhere. You do not hit me hard for this assumption, I'm just starting to learn Java and GWT. - avp pm

3 answers 3

I don’t know if this is a bug or a feature designed to speed up the processing of events, but you have little choice. You will have to extract the necessary information from the event before the timer starts and use it in the timer handler.

UPD is not a bug. So conceived. Here is an excerpt from the GwtEvent documentation:

All GWT events are considered unacceptable. That is, it’s not .

So after the event has ended, the object cannot be reused. This is caused by the use of the “opportunistic” design pattern, which in this case is very appropriate.

As I said, you have no choice. You cannot use this event in the timer. The library you use should be able to work without an event. Or do not use the timer.

  • The fact is that I have an add-on over another library, and I need to pass a MouseDownEvent object MouseDownEvent , after some time + reaching the defined one. conditions I need exactly the whole object. - Nicolas Chabanovsky ♦

Checking on e! = Null is not the topic. If you put a condition, then e.isLive ().

Using GwtEvent as a parameter in the library can be either a violation of the GWT contract, or a deliberate ban on calling a method from callback, timer, scheduler, and others. Because This is clearly stated in the documentation. In general cases, if x want to report that an event can be passed as a parameter at any time, use NativeEvent, not GwtEvent. For this purpose, the createMouseDownEvent method in the Document has been created . And also NativeEvent can be obtained from GwtEvent, the reverse is not true.

If such a parameter is in the library by the author's mistake, then you can try inheriting from MouseDownEvent, if it is possible (it seems to be not final), in order to create it. We can create a public constructor and call the super constructor of the main class through the super (). And override the get-something-there methods to the values ​​that came with the event before the timer runs. And use as a wrapper. Not the fact that it is possible. I can not check now.

  • I think this is possible, but there may be trouble due to getType. Besides, this is a terrible hack. It would be better without him. - cy6erGn0m
  • About e! = Null, I first thought, because I suspected that perhaps the call to the event handler was done somehow incorrectly. I do not see UiBinder's annotations, which means the handler is signed somehow differently. - cy6erGn0m
  • I tried to inherit, nothing good happened. Does not fall, but does not work as intended. - Nicolas Chabanovsky ♦

I don’t know if this will help you, but I discovered the following: (in GwtEven.java)

  /** * Asserts that the event still should be accessed. All events are considered * to be "dead" after their original handler manager finishes firing them. An * event can be revived by calling { @link GwtEvent#revive()}. */ protected void assertLive() { assert (!dead) : "This event has already finished being processed by its original handler manager, so you can no longer access it"; }