Modify

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#17238 closed defect (fixed)

[Patch] Poor error handling when saving to non-existing directory

Reported by: GerdP Owned by: GerdP
Priority: normal Milestone: 19.04
Component: Core Version:
Keywords: template_report Cc:

Description

What steps will reproduce the problem?

  1. Open new data layer
  2. Create a closed way
  3. Click Save As
  4. In the select box "Files of type" chose "Osmosis polygon filter files (*.poly)"
  5. Enter a file name with a directory that doesn't exist, e.g. c:\xyz\test

What is the expected result?

A popup that says something like "target directory doesn't exist"

What happens instead?

Nothing obvious happens in the dialog. Only the console shows an error message and a trace:

2019-01-24 10:35:22.654 SEVERE: java.io.FileNotFoundException: c:\xyz\test.poly (Das System kann den angegebenen Pfad nicht finden)
java.io.FileNotFoundException: c:\xyz\test.poly (Das System kann den angegebenen Pfad nicht finden)
	at java.io.FileOutputStream.open0(Native Method)
	at java.io.FileOutputStream.open(Unknown Source)
	at java.io.FileOutputStream.<init>(Unknown Source)
	at java.io.FileOutputStream.<init>(Unknown Source)
	at poly.PolyExporter.exportData(PolyExporter.java:40)
	at org.openstreetmap.josm.actions.SaveActionBase.doInternalSave(SaveActionBase.java:101)
	at org.openstreetmap.josm.actions.SaveActionBase.doSave(SaveActionBase.java:73)
	at org.openstreetmap.josm.actions.SaveActionBase.doSave(SaveActionBase.java:60)
	at org.openstreetmap.josm.actions.SaveActionBase.actionPerformed(SaveActionBase.java:50)
	at javax.swing.SwingUtilities.notifyAction(Unknown Source)
	at javax.swing.JComponent.processKeyBinding(Unknown Source)
	at javax.swing.KeyboardManager.fireBinding(Unknown Source)
	at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
	at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
	at javax.swing.JComponent.processKeyBindings(Unknown Source)
	at javax.swing.JComponent.processKeyEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

Please provide any additional information below. Attach a screenshot if possible.

Not sure if IO problems like this should be handled in each plugin? I think no. The attached patch catches shows a popup if the plugin throws an IOE.

Build-Date:2019-01-24 10:34:37
Revision:14726
Is-Local-Build:true

Identification: JOSM/1.5 (14726 SVN en) Windows 10 64-Bit
OS Build number: Windows 10 Home 1803 (17134)
Memory Usage: 578 MB / 1753 MB (179 MB allocated, but free)
Java version: 1.8.0_191-b12, Oracle Corporation, Java HotSpot(TM) 64-Bit Server VM
Screen: \Display0 1920x1080
Maximum Screen Size: 1920x1080
VM arguments: [-agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:57456, -ea, -Dfile.encoding=UTF-8]
Program arguments: [--debug]
Dataset consistency test: No problems found

Plugins:
+ OpeningHoursEditor (34535)
+ apache-commons (34506)
+ buildings_tools (34850)
+ download_along (34838)
+ ejml (34389)
+ geotools (34513)
+ jaxb (34506)
+ jts (34524)
+ o5m (34846)
+ opendata (34805)
+ pbf (34858)
+ poly (34546)
+ reltoolbox (34788)
+ reverter (34552)
+ utilsplugin2 (34844)

Tagging presets:
+ https://raw.githubusercontent.com/OpenNauticalChart/josm/master/INT-1-preset.xml
+ https://josm.openstreetmap.de/josmfile?page=Presets/Historical_Objects&zip=1

Last errors/warnings:
- W: No configuration settings found.  Using hardcoded default values for all pools.
- E: java.io.FileNotFoundException: c:\xyz\test.poly (Das System kann den angegebenen Pfad nicht finden)

Attachments (3)

17238.patch (701 bytes ) - added by GerdP 6 years ago.
17238-v2.patch (8.4 KB ) - added by GerdP 6 years ago.
17238-v3.patch (7.6 KB ) - added by GerdP 6 years ago.

Download all attachments as: .zip

Change History (14)

by GerdP, 6 years ago

Attachment: 17238.patch added

comment:1 by GerdP, 6 years ago

Owner: changed from Zverikk to GerdP
Status: newassigned

comment:2 by GerdP, 6 years ago

Summary: Poor error handling when saving to non-existing directory[Patch] Poor error handling when saving to non-existing directory

comment:3 by GerdP, 6 years ago

Component: Plugin polyCore

I've tried with other output types:

  • With osm.pbf the error is handled in the pbf plugin, I see a popup. Nevertheless the data layer is renamed to the non-existing file name.
  • With GeoJSON I see the same as with poly (no poup, console shows error)
  • With the default (OSM Server Files (*.osm) I see a popup "Error is: NoSuchFileException - c:\xyz\test.osm". When I press OK the data layer is renamed to "c:\xyz\test.osm". Not sure if that makes sense.

I thought about testing the path before calling the exporter but this could still fail, the drive might have not enough space. So, JOSM should just catch the IOE and show a popup. I think the data layer name should only be changed when there was no IOE.
Comments?

comment:4 by GerdP, 6 years ago

Owner: GerdP removed
Status: assignednew

by GerdP, 6 years ago

Attachment: 17238-v2.patch added

comment:5 by GerdP, 6 years ago

Please review v2. I think it works now for all exporters listed in ExtensionFileFilter.exporters
In case of errors the layer is not renamed and the invalid file is not added to the file history.

We already have a class ExceptionDialogUtil, maybe that would be the right place to add method showAndLogException()?

comment:6 by simon04, 6 years ago

I think your change to Compression.java breaks the function: you cannot use try-with-resources for returning an open stream to be used outside of this function …

by GerdP, 6 years ago

Attachment: 17238-v3.patch added

comment:7 by GerdP, 6 years ago

Ooops, good catch :)
The change is not needed at all. In v3 I've also corrected two checkstyle issues.

comment:8 by simon04, 6 years ago

The following plugins use/extend OsmExporter somehow, but should be fine:

$ ag -l OsmExporter
pdfimport/src/org/openstreetmap/josm/plugins/pdfimport/LoadPdfDialog.java
poly/src/poly/PolyExporter.java
pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfExporter.java

comment:9 by GerdP, 6 years ago

Ah,yes, forgot to write that. I tested pbf and poly, for the code in pdfimport I found no way to use it and a comment in the source says that the code is probably not needed (IIGTR it exports the layer as osm data).

comment:10 by GerdP, 6 years ago

Owner: set to GerdP
Resolution: fixed
Status: newclosed

In 14950/josm:

fix #17238 Don't know why I forgot to commit this patch.

comment:11 by GerdP, 6 years ago

Milestone: 19.04

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain GerdP.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.