diff --git a/src/main/java/org/orekit/rugged/adjustment/LeastSquareAdjuster.java b/src/main/java/org/orekit/rugged/adjustment/LeastSquareAdjuster.java index 02fe4ce2221e14de0c64a51545fe3942830ca1f2..cbd228353c42049433f429517d091f0efc6dd44f 100644 --- a/src/main/java/org/orekit/rugged/adjustment/LeastSquareAdjuster.java +++ b/src/main/java/org/orekit/rugged/adjustment/LeastSquareAdjuster.java @@ -24,7 +24,7 @@ import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresOptimizer; import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresOptimizer.Optimum; import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem; import org.hipparchus.optim.nonlinear.vector.leastsquares.LevenbergMarquardtOptimizer; -import org.orekit.rugged.errors.RuggedException; +import org.orekit.rugged.errors.RuggedInternalError; /** LeastSquareAdjuster * Class for setting least square algorithm chosen for solving optimization problem. @@ -84,7 +84,7 @@ public class LeastSquareAdjuster { default : // this should never happen - throw RuggedException.createInternalError(null); + throw new RuggedInternalError(null); } } } diff --git a/src/main/java/org/orekit/rugged/api/Rugged.java b/src/main/java/org/orekit/rugged/api/Rugged.java index f8b109b4cf21cb39b9b0d40fe83b0a8e99629511..b7207f9bb3f1e70b70dcd25983556a8209d021ed 100644 --- a/src/main/java/org/orekit/rugged/api/Rugged.java +++ b/src/main/java/org/orekit/rugged/api/Rugged.java @@ -28,6 +28,7 @@ import org.orekit.bodies.GeodeticPoint; import org.orekit.frames.Transform; import org.orekit.rugged.errors.DumpManager; import org.orekit.rugged.errors.RuggedException; +import org.orekit.rugged.errors.RuggedInternalError; import org.orekit.rugged.errors.RuggedMessages; import org.orekit.rugged.intersection.IntersectionAlgorithm; import org.orekit.rugged.linesensor.LineSensor; @@ -799,7 +800,7 @@ public class Rugged { } catch (RuggedException re) { // This should never happen // In order for the dump to end nicely DumpManager.endNicely(); - throw RuggedException.createInternalError(re); + throw new RuggedInternalError(re); } // Check if the pixel is inside the sensor (with a margin) OR if the inverse location was impossible (null result) @@ -860,7 +861,7 @@ public class Rugged { } catch (RuggedException re) { // This should never happen // In order for the dump to end nicely DumpManager.endNicely(); - throw RuggedException.createInternalError(re); + throw new RuggedInternalError(re); } } // end loop vIndex } // end loop uIndex diff --git a/src/main/java/org/orekit/rugged/api/RuggedBuilder.java b/src/main/java/org/orekit/rugged/api/RuggedBuilder.java index 3a604d61038385ddc426fd0f14e83c9fb6c845af..58be9580082ae9bf6860c085655834a0b7b2de15 100644 --- a/src/main/java/org/orekit/rugged/api/RuggedBuilder.java +++ b/src/main/java/org/orekit/rugged/api/RuggedBuilder.java @@ -35,6 +35,7 @@ import org.orekit.propagation.Propagator; import org.orekit.propagation.SpacecraftState; import org.orekit.propagation.sampling.OrekitFixedStepHandler; import org.orekit.rugged.errors.RuggedException; +import org.orekit.rugged.errors.RuggedInternalError; import org.orekit.rugged.errors.RuggedMessages; import org.orekit.rugged.intersection.BasicScanAlgorithm; import org.orekit.rugged.intersection.ConstantElevationAlgorithm; @@ -883,7 +884,7 @@ public class RuggedBuilder { return FramesFactory.getVeis1950(); default : // this should never happen - throw RuggedException.createInternalError(null); + throw new RuggedInternalError(null); } } @@ -903,7 +904,7 @@ public class RuggedBuilder { return FramesFactory.getGTOD(IERSConventions.IERS_1996, true); default : // this should never happen - throw RuggedException.createInternalError(null); + throw new RuggedInternalError(null); } } @@ -928,7 +929,7 @@ public class RuggedBuilder { return new OneAxisEllipsoid(6378136.6, 1.0 / 298.25642, bodyFrame); default : // this should never happen - throw RuggedException.createInternalError(null); + throw new RuggedInternalError(null); } } @@ -958,7 +959,7 @@ public class RuggedBuilder { return new IgnoreDEMAlgorithm(); default : // this should never happen - throw RuggedException.createInternalError(null); + throw new RuggedInternalError(null); } } diff --git a/src/main/java/org/orekit/rugged/errors/Dump.java b/src/main/java/org/orekit/rugged/errors/Dump.java index d06de7e4a9308db0abab7da10769702890f6a97e..109ee3568b4aece6620e5d7261753b3a40aca0cd 100644 --- a/src/main/java/org/orekit/rugged/errors/Dump.java +++ b/src/main/java/org/orekit/rugged/errors/Dump.java @@ -512,7 +512,7 @@ class Dump { result.getTargetDirectionDerivative().getY(), result.getTargetDirectionDerivative().getZ()); } catch (RuggedException re) { - throw RuggedException.createInternalError(re); + throw new RuggedInternalError(re); } }); writer.format(Locale.US, "%n"); diff --git a/src/main/java/org/orekit/rugged/errors/DumpReplayer.java b/src/main/java/org/orekit/rugged/errors/DumpReplayer.java index 74ba805292aeabaac83ad9396bc81911aaffa237..4d24e5467090362030a057ac2bf13a68a918bd0d 100644 --- a/src/main/java/org/orekit/rugged/errors/DumpReplayer.java +++ b/src/main/java/org/orekit/rugged/errors/DumpReplayer.java @@ -411,19 +411,19 @@ public class DumpReplayer { throw new RuggedException(ioe, LocalizedCoreFormats.SIMPLE_MESSAGE, ioe.getLocalizedMessage()); } catch (SecurityException e) { // this should never happen - throw RuggedException.createInternalError(e); + throw new RuggedInternalError(e); } catch (NoSuchMethodException e) { // this should never happen - throw RuggedException.createInternalError(e); + throw new RuggedInternalError(e); } catch (IllegalArgumentException e) { // this should never happen - throw RuggedException.createInternalError(e); + throw new RuggedInternalError(e); } catch (IllegalAccessException e) { // this should never happen - throw RuggedException.createInternalError(e); + throw new RuggedInternalError(e); } catch (InvocationTargetException e) { // this should never happen - throw RuggedException.createInternalError(e); + throw new RuggedInternalError(e); } } @@ -1179,7 +1179,7 @@ public class DumpReplayer { public Vector3D getLOS(final int index, final AbsoluteDate date) { final List<Pair<AbsoluteDate, Vector3D>> list = losMap.get(index); if (list == null) { - throw RuggedException.createInternalError(null); + throw new RuggedInternalError(null); } if (list.size() < 2) { diff --git a/src/main/java/org/orekit/rugged/errors/RuggedException.java b/src/main/java/org/orekit/rugged/errors/RuggedException.java index 7bd83e81837c8c62b51a928f7bf9646d57648b8f..9595c94a6cd373542d8c9651bb322f9ed8d73175 100644 --- a/src/main/java/org/orekit/rugged/errors/RuggedException.java +++ b/src/main/java/org/orekit/rugged/errors/RuggedException.java @@ -113,37 +113,4 @@ public class RuggedException extends RuntimeException implements LocalizedExcept return (specifier == null) ? "" : new MessageFormat(specifier.getLocalizedString(locale), locale).format(parts); } - /** Create an {@link java.lang.RuntimeException} for an internal error. - * @param cause underlying cause - * @return an {@link java.lang.RuntimeException} for an internal error - */ - public static RuntimeException createInternalError(final Throwable cause) { - - /** Format specifier (to be translated). */ - final Localizable specifier = RuggedMessages.INTERNAL_ERROR; - - /** Parts to insert in the format (no translation). */ - final String parts = "https://gitlab.orekit.org/orekit/rugged/issues"; - - return new RuntimeException() { - - /** Serializable UID. */ - private static final long serialVersionUID = 20140309L; - - /** {@inheritDoc} */ - @Override - public String getMessage() { - return buildMessage(Locale.US, specifier, parts); - } - - /** {@inheritDoc} */ - @Override - public String getLocalizedMessage() { - return buildMessage(Locale.getDefault(), specifier, parts); - } - - }; - - } - } diff --git a/src/main/java/org/orekit/rugged/errors/RuggedInternalError.java b/src/main/java/org/orekit/rugged/errors/RuggedInternalError.java new file mode 100644 index 0000000000000000000000000000000000000000..29362e1a645438cd41aa54992174a63659b9b0d9 --- /dev/null +++ b/src/main/java/org/orekit/rugged/errors/RuggedInternalError.java @@ -0,0 +1,88 @@ +/* Copyright 2013-2019 CS Systèmes d'Information + * Licensed to CS Systèmes d'Information (CS) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * CS licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.orekit.rugged.errors; + +import java.text.MessageFormat; +import java.util.Locale; + +import org.hipparchus.exception.Localizable; +import org.hipparchus.exception.LocalizedException; + + +/** Extension of {@link java.lang.Runtime} with localized message for internal errors only. + * @since 2.1 + */ +public class RuggedInternalError extends RuntimeException implements LocalizedException { + + /** Serializable UID. */ + private static final long serialVersionUID = 20190305L; + + /** Format specifier (to be translated). */ + private final Localizable specifier = RuggedMessages.INTERNAL_ERROR; + + /** Parts to insert in the format (no translation). */ + private final String[] parts = new String[] { + "https://gitlab.orekit.org/orekit/rugged/issues" + }; + + /** Create an exception with localized message. + * @param cause underlying cause + */ + public RuggedInternalError(final Throwable cause) { + super(cause); + } + + /** {@inheritDoc} */ + @Override + public String getMessage(final Locale locale) { + return buildMessage(locale); + } + + /** {@inheritDoc} */ + @Override + public String getMessage() { + return buildMessage(Locale.US); + } + + /** {@inheritDoc} */ + @Override + public String getLocalizedMessage() { + return buildMessage(Locale.getDefault()); + } + + /** {@inheritDoc} */ + @Override + public Localizable getSpecifier() { + return specifier; + } + + /** {@inheritDoc} */ + @Override + public Object[] getParts() { + return parts.clone(); + } + + /** + * Builds a message string by from a pattern and its arguments. + * @param locale Locale in which the message should be translated + * @return a message string + */ + private String buildMessage(final Locale locale) { + return new MessageFormat(specifier.getLocalizedString(locale), locale).format(parts); + } + +} diff --git a/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java b/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java index 78f709bf52da487ca70a90195c07706dea1d3c04..a3abd8b3050b2500887b4d7f33d8a522f857116a 100644 --- a/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java @@ -22,6 +22,7 @@ import org.orekit.bodies.GeodeticPoint; import org.orekit.rugged.api.AlgorithmId; import org.orekit.rugged.errors.DumpManager; import org.orekit.rugged.errors.RuggedException; +import org.orekit.rugged.errors.RuggedInternalError; import org.orekit.rugged.errors.RuggedMessages; import org.orekit.rugged.intersection.IntersectionAlgorithm; import org.orekit.rugged.raster.Tile; @@ -181,7 +182,7 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { if (intersection != null) { return intersection; } else { - throw RuggedException.createInternalError(null); + throw new RuggedInternalError(null); } } } @@ -311,7 +312,7 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { if (depth > 30) { // this should never happen - throw RuggedException.createInternalError(null); + throw new RuggedInternalError(null); } if (searchDomainSize(entryLat, entryLon, exitLat, exitLon) < 4) { @@ -635,7 +636,7 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { default : // this should never happen - throw RuggedException.createInternalError(null); + throw new RuggedInternalError(null); } } diff --git a/src/main/java/org/orekit/rugged/linesensor/SensorMeanPlaneCrossing.java b/src/main/java/org/orekit/rugged/linesensor/SensorMeanPlaneCrossing.java index 8562497bd883bfed862ff09683327484c3e099a9..d737a401edbd609eada887c943925a1cc50d344d 100644 --- a/src/main/java/org/orekit/rugged/linesensor/SensorMeanPlaneCrossing.java +++ b/src/main/java/org/orekit/rugged/linesensor/SensorMeanPlaneCrossing.java @@ -38,6 +38,7 @@ import org.hipparchus.util.FastMath; import org.hipparchus.util.Precision; import org.orekit.frames.Transform; import org.orekit.rugged.errors.RuggedException; +import org.orekit.rugged.errors.RuggedInternalError; import org.orekit.rugged.utils.SpacecraftToObservedBody; import org.orekit.time.AbsoluteDate; import org.orekit.utils.Constants; @@ -537,7 +538,7 @@ public class SensorMeanPlaneCrossing { evaluateLine(x, targetPV, scToBody.getBodyToInertial(date), scToBody.getScToInertial(date)); return 0.5 * FastMath.PI - FastMath.acos(Vector3D.dotProduct(targetDirection[0], meanPlaneNormal)); } catch (RuggedException re) { - throw RuggedException.createInternalError(re); + throw new RuggedInternalError(re); } } }, minLine, maxLine, startValue); diff --git a/src/main/java/org/orekit/rugged/linesensor/SensorPixelCrossing.java b/src/main/java/org/orekit/rugged/linesensor/SensorPixelCrossing.java index fa60b1579b5e2af9ed12c0b30668b2e55d5ca278..0ae635599a68475f86fffacefd21628b3baab9d1 100644 --- a/src/main/java/org/orekit/rugged/linesensor/SensorPixelCrossing.java +++ b/src/main/java/org/orekit/rugged/linesensor/SensorPixelCrossing.java @@ -23,6 +23,7 @@ import org.hipparchus.exception.MathIllegalArgumentException; import org.hipparchus.geometry.euclidean.threed.Vector3D; import org.hipparchus.util.FastMath; import org.orekit.rugged.errors.RuggedException; +import org.orekit.rugged.errors.RuggedInternalError; import org.orekit.time.AbsoluteDate; /** Class devoted to locate where ground point crosses a sensor line. @@ -80,7 +81,7 @@ public class SensorPixelCrossing { try { return Vector3D.angle(cross, getLOS(date, x)) - 0.5 * FastMath.PI; } catch (RuggedException re) { - throw RuggedException.createInternalError(re); + throw new RuggedInternalError(re); } } }; diff --git a/src/test/java/org/orekit/rugged/errors/DumpReplayerTest.java b/src/test/java/org/orekit/rugged/errors/DumpReplayerTest.java index 452ca13ab4b239df0c3386243c0d6c2844cafe17..c1c6cc473ce136cb8fec0f7a258b311f8a6bfe25 100644 --- a/src/test/java/org/orekit/rugged/errors/DumpReplayerTest.java +++ b/src/test/java/org/orekit/rugged/errors/DumpReplayerTest.java @@ -605,8 +605,9 @@ public class DumpReplayerTest { try { getLos.invoke(parsedSensor, 1, date); Assert.fail("an exception should have been thrown"); - } catch (Exception re) { - assertTrue(re.getCause().toString().contains("internal error")); + } catch (InvocationTargetException ite) { + RuggedInternalError rie = (RuggedInternalError) ite.getTargetException(); + assertEquals(RuggedMessages.INTERNAL_ERROR, rie.getSpecifier()); } } @@ -657,6 +658,7 @@ public class DumpReplayerTest { return null; } }; + @SuppressWarnings("unchecked") FieldVector3D<DerivativeStructure> fv= (FieldVector3D<DerivativeStructure>) getLOSDerivatives.invoke(parsedSensor, 1, date, generator); assertEquals(0., fv.getX().getValue(), 1.e-15); assertEquals(0., fv.getY().getValue(), 1.e-15); diff --git a/src/test/java/org/orekit/rugged/errors/RuggedExceptionTest.java b/src/test/java/org/orekit/rugged/errors/RuggedExceptionTest.java index 6208b608501bb487817acbf2a3dc285ab8ac95bb..1a4025063a6aa4a172e8195e7d6fa56dba05b5d7 100644 --- a/src/test/java/org/orekit/rugged/errors/RuggedExceptionTest.java +++ b/src/test/java/org/orekit/rugged/errors/RuggedExceptionTest.java @@ -63,12 +63,13 @@ public class RuggedExceptionTest { @Test public void testInternalError() { RuggedException re = new RuggedException(RuggedMessages.DUPLICATED_PARAMETER_NAME, "dummy"); - RuntimeException rte = RuggedException.createInternalError(re); + RuntimeException rte = new RuggedInternalError(re); Assert.assertFalse(re.getLocalizedMessage().contains("https://gitlab.orekit.org/orekit/rugged/issues")); Assert.assertTrue(rte.getLocalizedMessage().contains("https://gitlab.orekit.org/orekit/rugged/issues")); Assert.assertTrue(rte.getMessage().contains("https://gitlab.orekit.org/orekit/rugged/issues")); } + @Deprecated @Test public void testCoverage() { RuggedExceptionWrapper rew = new RuggedExceptionWrapper(new RuggedException(RuggedMessages.DUPLICATED_PARAMETER_NAME, "dummy"));