Modify

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#2953 closed defect (fixed)

[PATCH] Sorting a relation adds new members or crashes

Reported by: R2D2_C3PO Owned by: Gubaer
Priority: major Component: Core
Version: latest Keywords: relation, sort
Cc: karl.guggisberg@…

Description

Version: 1788
I was trying to sort relation 31508 usings JOSM's sort function.
First I had not all members downloaded and it failed with this exception:
java.lang.NullPointerException

at org.openstreetmap.josm.gui.dialogs.relation.RelationNodeMap.remove(RelationNodeMap.java:99)
at org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.sort(GenericRelationEditor.java:384)
at org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.access$700(GenericRelationEditor.java:106)
at org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor$9.actionPerformed(GenericRelationEditor.java:333)

Of course sorting can't work when not all members are downloaded but a message telling the user about the problem would be better than an expection.

After downloading all members I tried to sort again. Each time I click the sort button the number of members increases. This should not happen. Sort has to reoder the existing members, not to add any new (even if they are duplicates).

Attachments (0)

Change History (11)

comment:1 Changed 4 years ago by cjw@…

  • Summary changed from Sorting a relation adds new members or crashes to [PATCH] Sorting a relation adds new members or crashes

Thanks for the report. The exception on incomplete elements was specifically for the first element which I fixed locally. Both this problem and the duplicated members problem are fixed with the following patch:
http://www.time4t.net/~cjw/josm/josm-relation-member-sort-20090718-fixed.patch

No message is displayed yet for incomplete members as I do not know an existing method for displaying such informational/warning messages. Since much of the sorting code was removed in svn trunk, the patch contains much more than just these fixes.

comment:2 Changed 4 years ago by stoecker

  • Owner changed from team to Gubaer

Sorry, does no longer work. Could you update it?

Assigning to Karl.

comment:3 Changed 4 years ago by Gubaer

  • Cc karl.guggisberg@… added

Development on the relation editor recently was quite pacey. I had to temporarily remove the code which displays "link" information between relation members and sorts relations members.

@cjw: could you try to get it to work again?

comment:4 Changed 4 years ago by cjw@…

The patch I linked to in my first comment here should add sorting again, and only has one minor merge conflict (I fixed something that is now also fixed in svn). But, I made a new patch, which contains an additional change:

http://www.time4t.net/~cjw/josm/josm-relation-member-sort-20090720.patch

  • generic relation editor
    o add back relation member sorting, with a button at the left
    o add back linkedness info, but without recursion into members that are relations (can be added later)
    o split MemberTableCellRenderer into 3 classes for each column to prevent a runtime type error when moving columns in the member table

comment:5 Changed 4 years ago by Gubaer

I applied the patch in r1822 but I've disabled the sort action. Here's how I got a NoSuchElementException:

  1. download http://api06.dev.openstreetmap.org/api/0.6/map?bbox=7.373542785644531,46.916972287629385,7.4219512939453125,46.93924602724242
  2. lauch relation editor for relation(3 members)
  3. sort

Here's the exceptions stack trace:

java.util.NoSuchElementException
	at java.util.Vector.lastElement(Vector.java:461)
	at org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel.sort(MemberTableModel.java:428)
	at org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor$SortAction.actionPerformed(GenericRelationEditor.java:770)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
	at java.awt.Component.processMouseEvent(Component.java:5517)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
	at java.awt.Component.processEvent(Component.java:5282)
	at java.awt.Container.processEvent(Container.java:1966)
	at java.awt.Component.dispatchEventImpl(Component.java:3984)
	at java.awt.Container.dispatchEventImpl(Container.java:2024)
	at java.awt.Component.dispatchEvent(Component.java:3819)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
	at java.awt.Container.dispatchEventImpl(Container.java:2010)
	at java.awt.Window.dispatchEventImpl(Window.java:1791)
	at java.awt.Component.dispatchEvent(Component.java:3819)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

comment:6 Changed 4 years ago by cjw@…

I never tested relations as members (they are currently not sorted anyway) so thanks for testing this. The patch is bigger than needed because the code in svn is reformatted while I fixed the problem on my local copy. You'll have to reformat again before you can see the real diff.

http://www.time4t.net/~cjw/josm/josm-relation-member-sort-fix-first-element-relation-exception.patch

comment:7 follow-up: Changed 4 years ago by Gubaer

I suggest

  1. you do an svn update to get the current version from the JOSM snv
  2. fix the code
  3. create a patch
  4. submit it here

It's much easier then to apply your patch. And the code will look similar to what other code in JOSM looks like (it usually uses the curly-braces-on-the-same-line convention, not the curly-braces-on-the-next-line convention).

comment:8 in reply to: ↑ 7 ; follow-up: Changed 4 years ago by cjw@…

Replying to Gubaer:

  1. you do an svn update to get the current version from the JOSM snv
  2. fix the code
  3. create a patch
  4. submit it here

No, the procedure is:

  1. in eclipse, choose Source -> Clean up...
  2. choose custom + appropriate config
  3. finish

http://www.time4t.net/~cjw/josm/josm-relation-member-sort-fix-first-element-relation-exception-reformatted.patch

comment:9 in reply to: ↑ 8 Changed 4 years ago by Gubaer

No, the procedure is:

  1. in eclipse, choose Source -> Clean up...
  2. choose custom + appropriate config
  3. finish

http://www.time4t.net/~cjw/josm/josm-relation-member-sort-fix-first-element-relation-exception-reformatted.patch

This way you didn't pick up the changes I made to your patch when I applied it the last time. There were to many try-catch blocks for NullPointerExceptions and ClassCastExceptions. Luckily it doesn't matter, though, I was able to apply your new patch. I'll check it in soon.

comment:10 Changed 4 years ago by Gubaer

  • Resolution set to fixed
  • Status changed from new to closed

applied you patch in r1828

comment:11 Changed 4 years ago by anonymous

Ticket #3047 has been marked as a duplicate of this ticket.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed .
as The resolution will be set. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.