Weird behaviour causing JavaError

Hello everyone, I’ve recently encounter this issue:
I have 2 scripts, let’s call them script A and script B. Script A contains almost no calls to Orekit, all it does is call its Constants class to get some data, and then solves a minimization problem based on an analytical formulation of an orbital mechanics problem. Then, I save the solution computed to a txt file which is used to initialize script B. Script B makes instead extensive use of Orekit as it is meant to propagate the solution computed by the analytical model in a more physically meaningful dynamical model. In particular, it uses a NumericalPropagator to propagate the effect of the maneuvers computed in script A and it also uses a DSSTPropagator to compute the corresponding mean elements. However, when I run script B after running script A, NumericalPropagator returns this error:

JavaError: <super: <class 'JavaError'>, <JavaError object>>
    Java stacktrace:
java.lang.ArrayIndexOutOfBoundsException: 1
	at org.orekit.forces.gravity.OceanTidesField$TideHarmonics.getNormalizedCnm(
	at org.orekit.forces.gravity.potential.CachedNormalizedSphericalHarmonicsProvider$Generator.fillArray(
	at org.orekit.forces.gravity.potential.CachedNormalizedSphericalHarmonicsProvider$Generator.generate(
	at org.orekit.utils.GenericTimeStampedCache$Slot.generateAndCheck(
	at org.orekit.utils.GenericTimeStampedCache$Slot.<init>(
	at org.orekit.utils.GenericTimeStampedCache.selectSlot(
	at org.orekit.utils.GenericTimeStampedCache.getNeighbors(
	at org.orekit.forces.gravity.potential.CachedNormalizedSphericalHarmonicsProvider.onDate(
	at org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel.gradient(
	at org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel.acceleration(
	at org.orekit.forces.gravity.OceanTides.acceleration(
	at org.orekit.forces.ForceModel.addContribution(
	at org.orekit.propagation.numerical.NumericalPropagator$Main.computeDerivatives(
	at org.orekit.propagation.integration.AbstractIntegratedPropagator$ConvertedMainStateEquations.computeDerivatives(
	at org.hipparchus.ode.ExpandableODE.computeDerivatives(
	at org.hipparchus.ode.AbstractIntegrator.computeDerivatives(
	at org.hipparchus.ode.AbstractIntegrator.initIntegration(
	at org.hipparchus.ode.nonstiff.EmbeddedRungeKuttaIntegrator.integrate(
	at org.orekit.propagation.integration.AbstractIntegratedPropagator.integrateDynamics(
	at org.orekit.propagation.integration.AbstractIntegratedPropagator.propagate(
	at org.orekit.propagation.integration.AbstractIntegratedPropagator.propagate(

The force models I use are defined like this:

n, m = 4, 4;
nonSphericalGravity = HolmesFeatherstoneAttractionModel(FramesFactory.getITRF(IERSConventions.IERS_2010, True),
sunThirdBody = ThirdBodyAttraction(CelestialBodyFactory.getSun());
moonThirdBody = ThirdBodyAttraction(CelestialBodyFactory.getMoon());
dragForce = DragForce(HarrisPriester(CelestialBodyFactory.getSun(), earth), IsotropicDrag(area, CD));
srpForce = SolarRadiationPressure(CelestialBodyFactory.getSun(),
                                  Re, IsotropicRadiationSingleCoefficient(area, CR));
oceanicTides = OceanTides(FramesFactory.getITRF(IERSConventions.IERS_2010, True),
                          Re, mu, n, m, IERSConventions.IERS_2010, 
                          TimeScalesFactory.getUT1(IERSConventions.IERS_2010, True));
solidTides = SolidTides(FramesFactory.getITRF(IERSConventions.IERS_2010, True),
                        Re, mu, GravityFieldFactory.getConstantNormalizedProvider(n, m).getTideSystem(),
                        IERSConventions.IERS_2010, TimeScalesFactory.getUT1(IERSConventions.IERS_2010, True),
                        [CelestialBodyFactory.getSun(), CelestialBodyFactory.getMoon()]);
forces = [nonSphericalGravity, sunThirdBody, moonThirdBody, dragForce, srpForce, oceanicTides, solidTides];

(I know that I probably shouldn’t add OceanicTides and SolidTides since they don’t have a DSST equivalent, but let’s sidestep that for a moment)

What is really weird is the fact that if I restart my console and run script B (without running script A) the propagator doesn’t encounter this error. It also works fine if I run B → A → B on a fresh console. Basically the propagation fails if A is the absolute first script run.
Any ideas on what is causing this issue?

Hi Emiliano,

This may be linked to this


Hi @Emiliano and @Serrof,

I agree with you Romain.
Emiliano, there’s already an issue opened about this.
A workaround is to use two different DataContext for the two scripts.


Hello @Serrof and @MaximeJ,

Thank you for your answers. Before posting this I read that thread as well, but I thought it was a different issue since in my case I’m only building the OceanTides once (in the second script) so I thought it had nothing to do with caching.


Hmm… :thinking:

Now that you mention this, I may have read your first post too fast…
Could you provide a small runnable example of the issue?

Hello @MaximeJ, sorry for the late reply :sweat_smile:

Something even weirder just happened… I tried again this morning, and… the error doesn’t get raised anymore. I have literally no clue what’s going on :confused:

Hi @Emiliano,

That’s weird. If you run into the problem again, feel free to share a bit of code so we can all investigate.