Project

General

Profile

bug #8041

PatternSyntaxException in FeatureTreeSelectionDialog

Added by Patrick Plitzner 17 days ago. Updated 10 days ago.

Status:
Closed
Priority:
Highest
Category:
taxeditor
Target version:
Start date:
01/31/2019
Due date:
% Done:

100%

Severity:
normal
Found in Version:

Description

When entering '*' in the search field the following exception occurrs:

I think I have seen this exception in other selection dialogs as well

login : admin

editor version : 5.5.0.201901242349

server : test.e-taxonomy.eu (edit-test) / rem_conf_am

schema version : 5.0.0.0.20180514

os : Windows Server 2012 R2 6.3 amd64

java : 1.8.0_121

java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 4

(?i)*.*

    ^

                at java.util.regex.Pattern.error(Pattern.java:1955)

                at java.util.regex.Pattern.sequence(Pattern.java:2123)

                at java.util.regex.Pattern.expr(Pattern.java:1996)

                at java.util.regex.Pattern.compile(Pattern.java:1696)

                at java.util.regex.Pattern.<init>(Pattern.java:1351)

                at java.util.regex.Pattern.compile(Pattern.java:1028)

                at java.util.regex.Pattern.matches(Pattern.java:1133)

                at java.lang.String.matches(String.java:2121)

                at eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog.callService(FeatureTreeSelectionDialog.java:67)

                at eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog.search(AbstractFilteredCdmResourceSelectionDialog.java:575)

                at eu.etaxonomy.taxeditor.ui.dialog.selection.SearchDialog$2.modifyText(SearchDialog.java:178)

                at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:180)

                at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)

                at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4418)

                at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)

                at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1103)

                at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1084)

                at org.eclipse.swt.widgets.Text.wmCommandChild(Text.java:3122)

                at org.eclipse.swt.widgets.Control.WM_COMMAND(Control.java:4947)

                at org.eclipse.swt.widgets.Control.windowProc(Control.java:4802)

                at org.eclipse.swt.widgets.Display.windowProc(Display.java:5123)

                at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)

                at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2446)

                at org.eclipse.swt.widgets.Text.callWindowProc(Text.java:262)

                at org.eclipse.swt.widgets.Control.windowProc(Control.java:4897)

                at org.eclipse.swt.widgets.Text.windowProc(Text.java:2704)

                at org.eclipse.swt.widgets.Display.windowProc(Display.java:5110)

                at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)

                at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2552)

                at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3822)

                at org.eclipse.jface.window.Window.runEventLoop(Window.java:818)

                at org.eclipse.jface.window.Window.open(Window.java:794)

                at eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog.getUuidAndTitleCacheSelectionFromDialog(AbstractFilteredCdmResourceSelectionDialog.java:166)

                at eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog.getSelectionFromDialog(AbstractFilteredCdmResourceSelectionDialog.java:147)

                at eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog.select(FeatureTreeSelectionDialog.java:42)

                at eu.etaxonomy.taxeditor.editor.descriptiveDataSet.character.CharacterEditor$FeatureTreeChooserListener.widgetSelected(CharacterEditor.java:433)

                at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)

                at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)

                at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4418)

                at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)

                at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4236)

picture807-1.png View (16.7 KB) Patrick Plitzner, 01/31/2019 08:47 AM

Associated revisions

Revision 839b9253 (diff)
Added by Katja Luther 17 days ago

fix #8041: fix syntax pattern exception

Revision b5046c38 (diff)
Added by Patrick Plitzner 17 days ago

ref #8041 Add CdmUtils method to trim a string of non-word characters

Revision 38b475da (diff)
Added by Patrick Plitzner 17 days ago

ref #8041 trim all non-word characters in selecti dialog search string

Revision 787bc714 (diff)
Added by Patrick Plitzner 16 days ago

ref #8041 Replace non-word characters with '.' instead of ""

Revision 7bd5476c (diff)
Added by Andreas Müller 16 days ago

ref #8041 try to fix pattern escaping issue

Revision e5a59879 (diff)
Added by Andreas Müller 16 days ago

ref #8041 try to fix pattern escaping issue (cont.)

Revision da9ff9c4 (diff)
Added by Andreas Müller 15 days ago

ref #8041 correct regex quotation method implemented in CdmUtils

Revision 071232d5 (diff)
Added by Andreas Müller 15 days ago

ref #8041 revert all changes except for the first and for the new method CdmUtils.quoteRegExWithWildcard

Revision d50317d6 (diff)
Added by Patrick Plitzner 11 days ago

ref #8041 Use existing service method for retrieval of UuidAndTitleCache

Revision f4935f27 (diff)
Added by Patrick Plitzner 11 days ago

ref #8041 Use CdmUtils.quoteRegExWithWildcard(pattern) for search string

Revision 43337563 (diff)
Added by Patrick Plitzner 10 days ago

ref #8041 Remove "New" option for groups and user selection dialog

Revision a0dd030b (diff)
Added by Patrick Plitzner 10 days ago

ref #8041 Store protected flag when creating a new feature tree

History

#1 Updated by Katja Luther 17 days ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 50

#2 Updated by Andreas Müller 17 days ago

  • Target version changed from Unassigned CDM tickets to Release 5.5

#3 Updated by Katja Luther 17 days ago

please review

#4 Updated by Patrick Plitzner 17 days ago

  • Status changed from Resolved to Closed
  • Assignee changed from Patrick Plitzner to Katja Luther
  • % Done changed from 50 to 100

Works fine. I added a utility method to remove all non-word characters of the pattern because search string with characters like '(' or multiple '*' caused the same problem.

#5 Updated by Andreas Müller 17 days ago

  • Status changed from Closed to Feedback
  • Assignee changed from Katja Luther to Patrick Plitzner

Patrick Plitzner wrote:

Works fine. I added a utility method to remove all non-word characters of the pattern because search string with characters like '(' or multiple '*' caused the same problem.

Sorry but doing such a change it should be reviewed!! First of all, it does not work. I created a FeatureTree called "Test Feature(Tree). Searching for "Test Feature(" did throw:

login : admin
editor version : 5.5.0.201901311248
server : test.e-taxonomy.eu (edit-test) / rem_conf_am
schema version : 5.0.0.0.20180514
os : Windows Server 2012 R2 6.3 amd64
java : 1.8.0_121
java.util.regex.PatternSyntaxException: Unclosed group near index 19
(?i)Test Feature(.*
                   ^
    at java.util.regex.Pattern.error(Pattern.java:1955)
    at java.util.regex.Pattern.accept(Pattern.java:1813)
    at java.util.regex.Pattern.group0(Pattern.java:2908)
    at java.util.regex.Pattern.sequence(Pattern.java:2051)
    at java.util.regex.Pattern.expr(Pattern.java:1996)
    at java.util.regex.Pattern.compile(Pattern.java:1696)
    at java.util.regex.Pattern.<init>(Pattern.java:1351)
    at java.util.regex.Pattern.compile(Pattern.java:1028)
    at java.util.regex.Pattern.matches(Pattern.java:1133)
    at java.lang.String.matches(String.java:2121)
    at eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog.callService(FeatureTreeSelectionDialog.java:67)
    at eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog.search(AbstractFilteredCdmResourceSelectionDialog.java:577)
    at eu.etaxonomy.taxeditor.ui.dialog.selection.SearchDialog$2.modifyText(SearchDialog.java:178)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:180)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4418)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1103)

Also it is not the correct way to simply remove non-word characters as this may filter those entries which DO have such characters, and we do not limit labels to word characters.

Slightly better would be to remove them by ".".

But the best solution is to mask all RegEx syntax characters correctly. E.g. "(" -> "\(" . I am quite sure there must be libraries/ java functionality doing this, havn't checked.

#6 Updated by Patrick Plitzner 16 days ago

  • Status changed from Feedback to Resolved
  • Assignee changed from Patrick Plitzner to Andreas Müller
  • % Done changed from 100 to 90

Now the non-word characters are replaced by '.'

#7 Updated by Andreas Müller 16 days ago

This is also not yet good, as \w matches ONLY a-zA-Z_0-9 . No letters from other languages like German Umlaut is recognized. Probably better were \p{Letter} (https://www.regular-expressions.info/unicode.html).

However, this is still half correct only. I used Pattern.quote(pattern) now. Let's see if it works.

#8 Updated by Andreas Müller 15 days ago

  • Status changed from Resolved to Feedback
  • Assignee changed from Andreas Müller to Patrick Plitzner
  • % Done changed from 90 to 30

I now had a closer look to how this is all used. And there are principal problems why this can not work.

The code is in AbstractFilteredCdmResourceSelectionDialog and manipulates the search string before calling callService(String) . The problem is that this method has not javadoc contract how the method should be used and how the search string should look like.
So currently in subclasses the method is sometimes used to simply pass the search string to a service method call (e.g. ClassificationSelectionDialog) while in other classes it is used for java regular expressions (e.g. FeatureTreeSelectionDialog).

If we allow such different handling we can not do any search type specific handling of the search string in AbstractFilteredCdmResourceSelectionDialog. E.g. replacing some characters by "." works for java regex but does not work for service layer hiberate/sql calls. Some counts for the last solution using Pattern.quote() or similar.

If an adaptation of the search string is needed it NEEDS to take place in the subclasses, not in the base class. And if java regex is used CdmUtils.quoteRegExWithWildcard(String) is probably the correct transformation method.

BUT: we should discuss if it should not be required to always run service method calls. Isn't this the idea of the dialogs that they work in the same way and that they all retrieve data from DB according to the filter string and do NOT usually load all data first and filter them afterwards. If according service method calls do not exist we should create them.
Handling all dialogs the same way makes it much easier to maintain the code and avoids problems as the one that we encountered here.

Katja, Patrick, could you please discuss how this can be achieved.

#9 Updated by Andreas Müller 15 days ago

I reverted most of the changes except for first and except for new method CdmUtils.quoteRegExWithWildcard

#10 Updated by Patrick Plitzner 11 days ago

The classes that do not directly invoke a service method with the search pattern are:

  • FeatureSelectionDialog -> regex
  • FeatureTreeSelectionDialog -> regex
  • GrantedAuthoritySelectionDialog -> regex
  • GroupSelectionDialog -> regex
  • (ReferenceSelectionDialog, NomenclaturalReferenceSelectionDialog) -> pattern is used for service calls but the method has a lot of lines of code
  • TermVocabularySelectionDialog -> regex
  • UserSelectionDialog -> regex

From the above mentioned

  • FeatureSelectionDialog
  • FeatureTreeSelectionDialog
  • TermVocabularySelectionDialog

already have service method to retrieve a list of UuidAndTitleCache objects which is used as the input of selection dialogs. So here, we can probably use a direct service call instead of retrieving all items and then filtering by regex on the titlecache.

For the remaining dialogs the according services to not offer these methods. These would have to be added. These CDM classes do not have titleCaches, so semantically the usage of UuidAndTitleCache wrappers is wrong but this is how it is done now anyways.

#11 Updated by Patrick Plitzner 11 days ago

I changed the callService() method for

  • FeatureSelectionDialog
  • FeatureTreeSelectionDialog
  • TermVocabularySelectionDialog

to use the UuidAndTitleCache service directly.

That leaves open

  • GrantedAuthoritySelectionDialog
  • GroupSelectionDialog
  • UserSelectionDialog

For these I would just add the CdmUtils.quoteRegExWithWildcard(String) as these are anyway rarely used and to avoid adding new service methods shortly before the release.

#12 Updated by Patrick Plitzner 11 days ago

  • Status changed from Feedback to Resolved
  • Assignee changed from Patrick Plitzner to Andreas Müller
  • % Done changed from 30 to 50

I tested all changed selection dialogs and experienced no exceptions.

#13 Updated by Andreas Müller 11 days ago

  • Priority changed from New to Highest

#14 Updated by Andreas Müller 11 days ago

  • Status changed from Resolved to Feedback
  • Assignee changed from Andreas Müller to Patrick Plitzner

There is a related issue. When creating a new Feature Tree in FeatureTree selection dialog "New Feature Tree" the created feature tree does not set the protected title cache correctly. Is is set to false and therefore the titleCache is not stored correctly. FeatureTree should be created same way as in FeatureTree editor "New".

#15 Updated by Andreas Müller 11 days ago

Also the New Group dialog does not allow to enter a group name. The dialog is empty.
Also in New User dialog it is not possible to enter a username. Textfield is disabled.

Are these on purpose? If yes we should remove the "New Group" and "New User" buttons.

#16 Updated by Andreas Müller 11 days ago

I tested

FeatureTreeSelectionDialog
TermVocabularySelectionDialog
GrantedAuthoritySelectionDialog
GroupSelectionDialog
UserSelectionDialog

they all work as expected. I did not find any place where FeatureSelectionDialog is used. Can you give a hint? However, I think it will also work as you have tested it already and it uses UuidAndTitleCache now.

So, once the "New" buttons are fixed (or if difficult to fix a new ticket(s) is/are created) we can close this ticket.

#17 Updated by Patrick Plitzner 10 days ago

Andreas Müller wrote:

they all work as expected. I did not find any place where FeatureSelectionDialog is used. Can you give a hint? However, I think it will also work as you have tested it already and it uses UuidAndTitleCache now.

The Feature selection dialog can be found in the details view for PolytomousKeyNodes

#18 Updated by Patrick Plitzner 10 days ago

Andreas Müller wrote:

Also the New Group dialog does not allow to enter a group name. The dialog is empty.
Also in New User dialog it is not possible to enter a username. Textfield is disabled.

Are these on purpose? If yes we should remove the "New Group" and "New User" buttons.

I would say that we remove "New group" and "New user" because those entities should be created and edited only in the corresponding bulk editor.

#19 Updated by Patrick Plitzner 10 days ago

  • Status changed from Feedback to Resolved
  • Assignee changed from Patrick Plitzner to Andreas Müller

Andreas Müller wrote:

There is a related issue. When creating a new Feature Tree in FeatureTree selection dialog "New Feature Tree" the created feature tree does not set the protected title cache correctly. Is is set to false and therefore the titleCache is not stored correctly. FeatureTree should be created same way as in FeatureTree editor "New".

This is fixed. The titleCache is now created with protected=true

#20 Updated by Andreas Müller 10 days ago

  • Status changed from Resolved to Feedback
  • Assignee changed from Andreas Müller to Patrick Plitzner

Patrick Plitzner wrote:

Andreas Müller wrote:

Also the New Group dialog does not allow to enter a group name. The dialog is empty.
Also in New User dialog it is not possible to enter a username. Textfield is disabled.

Are these on purpose? If yes we should remove the "New Group" and "New User" buttons.

I would say that we remove "New group" and "New user" because those entities should be created and edited only in the corresponding bulk editor.

Agreed. Can you change this?

#21 Updated by Patrick Plitzner 10 days ago

  • Status changed from Feedback to Resolved
  • Assignee changed from Patrick Plitzner to Andreas Müller

Already done ;)

#22 Updated by Andreas Müller 10 days ago

  • Status changed from Resolved to Closed
  • Assignee changed from Andreas Müller to Patrick Plitzner
  • % Done changed from 50 to 100

Also the related issue seem to be fixed all. I think we can close this ticket.

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 40 MB)