Orekit Jpype - Issue with implementing java interfaces

Hello Everyone,

I have been experimenting with orekit_jpype for a while and have been using the OrekitFixedStepHandler with my numerical propagator. Below is an example code snippet I came across in the Orekit_jpype examples:

import orekit_jpype as orekit
from jpype import JImplements, JOverride

orekit.initVM()

from org.orekit.propagation.sampling import OrekitFixedStepHandler  # noqa

@JImplements(OrekitFixedStepHandler)
class MyStepHandler:
   dates = []

   @JOverride
   def init(self, s0, t, step):
       pass

   @JOverride
   def handleStep(self, currentState):
       self.dates.append(currentState.getDate())

   @JOverride
   def finish(self, s):
       pass


a = MyStepHandler()
b = MyStepHandler()

print(a.dates is b.dates)

When I run this code, True is printed to the console. This implies that every instance of the MyStepHandler class shares the same dates list. However, this is not the behavior I want. I want each instance of the class to hold its own separate dates list.

To achieve this, I tried moving the initialization of the dates list into the init method, as shown below:

@JOverride
def init(self, s0, t, step):
    self.dates = []

But this resulted in the following error:

print(a.dates is b.dates)
^^^^^^^
AttributeError: 'proxy.MyStepHandler' object has no attribute 'dates'

Is this the correct way to implement this? How can I ensure that each instance of the MyStepHandler class has its own separate dates list?

Hi there,

You should make dates an attribute of your class yes, but to do so it should be initialized in the __init__ method, which is the constructor for python.
The init method is inherited from Orekit (written in Java) and is not a constructor, simply a function called by the handler.

Cheers,
Romain.