Thanks Jordy,

 

I’ve created a PR (https://github.com/geotools/geotools/pull/2462) and a ticket 
https://osgeo-org.atlassian.net/browse/GEOT-6331 for it.

However, for the short term I’ll register my own listener.

 

Ciao

  Marco

 

Von: Jody Garnett <jody.garn...@gmail.com> 
Gesendet: Mittwoch, 19. Juni 2019 08:23
An: Marco Peters <marco.pet...@brockmann-consult.de>
Cc: GeoTools Users <geotools-gt2-users@lists.sourceforge.net>
Betreff: Re: [Geotools-gt2-users] Logging changes the behaviour of JAI

 

I am responsible for that code, the listener is used as we could not reprises 
the expected errors thrown by JAI when native code is unavailable (the default 
case now that medialib is not provided).

 

Here is the code from Logging 
<https://github.com/geotools/geotools/blob/master/modules/library/metadata/src/main/java/org/geotools/util/logging/Logging.java#L117>
 :

 

            if (imagingListener == null

                    || 
imagingListener.getClass().getName().contains("ImagingListenerImpl")) {

                // Client code has not provided an ImagingListener so we can 
use our own

                // Custom GeoTools ImagingListener used to ignore common 
warnings

                setImagingListener.invoke(jai, new LoggingImagingListener());

                if (LOGGING_TRACE) {

                    System.out.println("Logging JAI messages: javax.media.jai 
logger redirected");

                }

 

So if you have your own imagingListener registered we will not override your 
setting, and we only seek to replace the built-in implementation.

 

We have the following very specific exception to catch in LoggingImagingListern 
<https://github.com/geotools/geotools/blob/master/modules/library/metadata/src/main/java/org/geotools/util/logging/LoggingImagingListener.java#L35>
 , and return "false" to indicate we are not trying to recover from the 
exception.

 

    public boolean errorOccurred(

            String message, Throwable thrown, Object where, boolean isRetryable)

            throws RuntimeException {

        Logger log = Logging.getLogger(LoggingImagingListener.class);

        if (message.contains("Continuing in pure Java mode")) {

            log.log(Level.FINER, message, thrown);

        } else {

            log.log(Level.INFO, message, thrown);

        }

        return false; // we are not trying to recover

    }

 

So options are:

 

a) Make a pull request so the above message throws the provided exception. I am 
not sure if that is in keeping with the API contract though ...

b) Configure your own imagingListener which rethrows exceptions, this will 
prevent GeoTools from registering its own ...

 

Reading in ImagingListenerImpl 
<https://github.com/eclipse/imagen/blob/master/modules/core/src/main/java/org/eclipse/imagen/media/util/ImagingListenerImpl.java#L74>
  it actually has some very specific logic that could be reproduced:

 

        // Silent the RuntimeException occuring in any OperationRegistry

        // and rethrown all the other RuntimeExceptions.

        if (thrown instanceof RuntimeException &&

            !(where instanceof OperationRegistry))

            throw (RuntimeException)thrown;

 

 




--

Jody Garnett

 

 

On Fri, 14 Jun 2019 at 06:09, Marco Peters <marco.pet...@brockmann-consult.de 
<mailto:marco.pet...@brockmann-consult.de> > wrote:

Hello,

 

In the static block of the class org.geotools.util.logging.Logging a new 
ImagingListener is registered to JAI.

Unfortunately, this causes problems especially in unit level tests.

The newly registered listener behaves differently as the default JAI listener 
(ImagingListenerImpl). RuntimeExceptions are not rethrown but only logged. 

 

This leads to the situation that a NullPointerException occurs where actually a 
certain RuntimeException is expected.

 

This caused some trouble in unit level tests. Depending on the execution order 
tests can fail. In one test (TestA) the GeoTools LoggingImagingListener is 
registered because GeoTools is used. 

Another test (TestB), which does not use GeoTools, fails if it runs after TestA 
and works if it runs before TestA.

 

Does someone have a suggestion how to deal with it?

Currently, I changed TestB to initialise GeoTools Logging too and to expect the 
NullPointerException. But I this is not ideal.

I think that it would be better to rethrow RuntimeExceptions as the 
ImagingListenerImpl does, but maybe there is a reason not to do it.

 

Ciao

  Marco

 

 

_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net 
<mailto:GeoTools-GT2-Users@lists.sourceforge.net> 
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to