Project

General

Profile

Actions

bug #8041

closed

PatternSyntaxException in FeatureTreeSelectionDialog

Added by Patrick Plitzner over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Highest
Assignee:
Patrick Plitzner
Category:
taxeditor
Target version:
Start date:
Due date:
% Done:

100%

Estimated time:
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)

Files

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

Updated by Katja Luther over 4 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 50
Actions #2

Updated by Andreas Müller over 4 years ago

  • Target version changed from Unassigned CDM tickets to Release 5.5
Actions #3

Updated by Katja Luther over 4 years ago

please review

Actions #4

Updated by Patrick Plitzner over 4 years 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.

Actions #5

Updated by Andreas Müller over 4 years 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.

Actions #6

Updated by Patrick Plitzner over 4 years 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 '.'

Actions #7

Updated by Andreas Müller over 4 years 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.

Actions #8

Updated by Andreas Müller over 4 years 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.

Actions #9

Updated by Andreas Müller over 4 years ago

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

Actions #10

Updated by Patrick Plitzner over 4 years 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.

Actions #11

Updated by Patrick Plitzner over 4 years 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.

Actions #12

Updated by Patrick Plitzner over 4 years 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.

Actions #13

Updated by Andreas Müller over 4 years ago

  • Priority changed from New to Highest
Actions #14

Updated by Andreas Müller over 4 years 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".

Actions #15

Updated by Andreas Müller over 4 years 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.

Actions #16

Updated by Andreas Müller over 4 years 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.

Actions #17

Updated by Patrick Plitzner over 4 years 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

Actions #18

Updated by Patrick Plitzner over 4 years 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.

Actions #19

Updated by Patrick Plitzner over 4 years 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

Actions #20

Updated by Andreas Müller over 4 years 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?

Actions #21

Updated by Patrick Plitzner over 4 years ago

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

Already done ;)

Actions #22

Updated by Andreas Müller over 4 years 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.

Actions

Also available in: Atom PDF