WKT referencing module does not close input streams used to load epsg file
--------------------------------------------------------------------------

                 Key: GEOT-2959
                 URL: http://jira.codehaus.org/browse/GEOT-2959
             Project: GeoTools
          Issue Type: Bug
          Components: core referencing
    Affects Versions: 2.6.1
         Environment: Java 1.6, glassfish v3
            Reporter: Joshua Portway
            Priority: Minor


the loadDefault() method opens streams and calls Properties.load without 
closing the stream afterwards. 
I am running code in the Glassfish application server (which probably does a 
lot more strict checking than most environments), and it logs this warning :

{code}
WARNING: Input stream has been finalized or forced closed without being 
explicitly closed; stream instantiation reported in following stack trace
java.lang.Throwable
        at 
com.sun.enterprise.loader.ASURLClassLoader$SentinelInputStream.<init>(ASURLClassLoader.java:1153)
        at 
com.sun.enterprise.loader.ASURLClassLoader$InternalJarURLConnection.getInputStream(ASURLClassLoader.java:1246)
        at java.net.URL.openStream(URL.java:1010)
        at 
org.geotools.referencing.crs.EPSGCRSAuthorityFactory.loadDefault(EPSGCRSAuthorityFactory.java:144)
        at 
org.geotools.referencing.crs.EPSGCRSAuthorityFactory.<init>(EPSGCRSAuthorityFactory.java:105)
        at 
org.geotools.referencing.crs.EPSGCRSAuthorityFactory.<init>(EPSGCRSAuthorityFactory.java:94)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at java.lang.Class.newInstance0(Class.java:355)
        at java.lang.Class.newInstance(Class.java:308)
        at sun.misc.Service$LazyIterator.next(Service.java:271)
        at 
org.geotools.factory.FactoryRegistry.register(FactoryRegistry.java:829)
        at 
org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:773)
        at 
org.geotools.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:808)
        at 
org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:195)
        at 
org.geotools.referencing.ReferencingFactoryFinder.getFactories(ReferencingFactoryFinder.java:176)
        at 
org.geotools.referencing.ReferencingFactoryFinder.getCRSAuthorityFactories(ReferencingFactoryFinder.java:451)
        at 
org.geotools.referencing.DefaultAuthorityFactory.getBackingFactory(DefaultAuthorityFactory.java:88)
        at 
org.geotools.referencing.DefaultAuthorityFactory.<init>(DefaultAuthorityFactory.java:69)
        at org.geotools.referencing.CRS.getAuthorityFactory(CRS.java:197)
        at org.geotools.referencing.CRS.decode(CRS.java:435)
        at 
org.geotools.gce.geotiff.adapters.GeoTiffMetadata2CRSAdapter.createGeographicCoordinateSystem(GeoTiffMetadata2CRSAdapter.java:409)
        at 
org.geotools.gce.geotiff.adapters.GeoTiffMetadata2CRSAdapter.createCoordinateSystem(GeoTiffMetadata2CRSAdapter.java:238)
        at 
org.geotools.gce.geotiff.GeoTiffReader.getHRInfo(GeoTiffReader.java:292)
        at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:229)
        at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:140)
        at org.autogena.skyserver.maps.MapUpdater.<init>(MapUpdater.java:67)
        at org.autogena.skyserver.maps.OzoneMap.<init>(OzoneMap.java:23)
        at 
org.autogena.skyserver.maps.__EJB31_Generated__OzoneMap__Intf____Bean__.<init>(Unknown
 Source)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at java.lang.Class.newInstance0(Class.java:355)
        at java.lang.Class.newInstance(Class.java:308)
        at 
com.sun.ejb.containers.BaseContainer.instantiateOptionalEJBLocalBusinessObjectImpl(BaseContainer.java:3752)
        at 
com.sun.ejb.containers.AbstractSingletonContainer.initializeHome(AbstractSingletonContainer.java:269)
        at 
com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:161)
        at 
org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:207)
        at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:197)
        at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:63)
        at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:175)
        at 
org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:216)
        at 
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:338)
        at 
com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
        at 
org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
        at 
com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
        at 
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
        at 
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
        at 
com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
        at 
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
        at 
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
        at 
com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
        at 
com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
        at 
com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
        at 
com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
        at 
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
        at 
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
        at 
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
        at 
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
        at 
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
        at 
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
        at 
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at 
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
        at 
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
        at 
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
        at 
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
        at java.lang.Thread.run(Thread.java:637)
{code}

Here's a fix :
{code}
/**
     * Loads from epsg.properties if the file exists, defaults to internal 
defintions
     * exported from postgis and cubeworks.
     * 
     * @throws IOException
     */
    protected void loadDefault() throws IOException {
        // Check the application directory first
        //
        File file = new File("epsg.properties");
        if( file.exists() ){
            final FileInputStream fileInputStream = new FileInputStream(file);
            try{
            epsg.load( fileInputStream);
            }
            finally{
                fileInputStream.close();
            }
        }        
        // Use the built-in property defintions
        //
        URL url = EPSGCRSAuthorityFactory.class.getResource("epsg.properties");
        final InputStream stream = url.openStream();
        try{
        epsg.load( stream);
        }
        finally{
            stream.close();
        }
    }
{code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to