Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how can this happen?

Reply
Thread Tools

how can this happen?

 
 
jahhaj
Guest
Posts: n/a
 
      11-18-2005
Here's the message I get from a PatternSyntaxException

Unknown character category {Digit} near index 8
\p{Digit}{1,2}
^

How can this be? {Digit} is a valid character category, it's in the
javadoc, it's even in the source code. (Incidentally the single \ is
how java reports the error, in the source I have "\\p{Digit}{1,2}")

I'm using java 1.4.2_06 and running under BEA Weblogic 8.1

john

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      11-18-2005
jahhaj wrote:
> Here's the message I get from a PatternSyntaxException
>
> Unknown character category {Digit} near index 8
> \p{Digit}{1,2}
> ^
>
> How can this be? {Digit} is a valid character category, it's in the
> javadoc, it's even in the source code. (Incidentally the single \ is
> how java reports the error, in the source I have "\\p{Digit}{1,2}")
>
> I'm using java 1.4.2_06 and running under BEA Weblogic 8.1


Works for me. Also 1.4.2._06, OS is Windows 2k Server, no app server.

robert

 
Reply With Quote
 
 
 
 
jahhaj
Guest
Posts: n/a
 
      11-18-2005

Robert Klemme wrote:
> jahhaj wrote:
> > Here's the message I get from a PatternSyntaxException
> >
> > Unknown character category {Digit} near index 8
> > \p{Digit}{1,2}
> > ^
> >
> > How can this be? {Digit} is a valid character category, it's in the
> > javadoc, it's even in the source code. (Incidentally the single \ is
> > how java reports the error, in the source I have "\\p{Digit}{1,2}")
> >
> > I'm using java 1.4.2_06 and running under BEA Weblogic 8.1

>
> Works for me. Also 1.4.2._06, OS is Windows 2k Server, no app server.
>
> robert


Works for me as well when I run as a standalone Java app, baffling.

john

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-18-2005
On 18 Nov 2005 04:53:40 -0800, "jahhaj" <>
wrote, quoted or indirectly quoted someone who said :

>Unknown character category {Digit} near index 8
>\p{Digit}{1,2}


you did not post your code so I wrote this SSCCE

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* snippet &trade; to demonstrate a problem with regex
*/
public class Regex4
{
private static final Pattern p =
Pattern.compile("(\\p{Digit}){1,2}");

/**
* test harness
*
* @param args not used
*/
public static void main ( String[] args )
{

// format 1
Matcher m = p.matcher("89");

m.matches();
int count = m.groupCount() + 1;

// display groups found
for ( int i=0; i<count; i++ )
{
System.out.println(m.group(i));
}

}
}

When I ran it on JDK 1.5.0_05
it gave the following results:
89
9
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
jahhaj
Guest
Posts: n/a
 
      11-18-2005

Roedy Green wrote:
> On 18 Nov 2005 04:53:40 -0800, "jahhaj" <>
> wrote, quoted or indirectly quoted someone who said :
>
> >Unknown character category {Digit} near index 8
> >\p{Digit}{1,2}

>
> you did not post your code so I wrote this SSCCE
>


My real code is a few lines inside a large J2EE application. I know
that if I extract the code and run it in a different environment then
it will work fine. My interest is in suggestions for what could
possibily be going wrong for the JVM not to recognise a perfectly
standard character category.

If you look at the source for Pattern then the character categories are
looked up in a simple map, in a single place in the code. How could
this go wrong? That's my question.

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      11-18-2005
jahhaj wrote:
> Roedy Green wrote:
>> On 18 Nov 2005 04:53:40 -0800, "jahhaj" <>
>> wrote, quoted or indirectly quoted someone who said :
>>
>>> Unknown character category {Digit} near index 8
>>> \p{Digit}{1,2}

>>
>> you did not post your code so I wrote this SSCCE
>>

>
> My real code is a few lines inside a large J2EE application. I know
> that if I extract the code and run it in a different environment then
> it will work fine. My interest is in suggestions for what could
> possibily be going wrong for the JVM not to recognise a perfectly
> standard character category.
>
> If you look at the source for Pattern then the character categories
> are looked up in a simple map, in a single place in the code. How
> could this go wrong? That's my question.


Maybe some wired threading or class loading issue... Just a wild guess.

robert

 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      11-18-2005
jahhaj wrote:

> My real code is a few lines inside a large J2EE application. I know
> that if I extract the code and run it in a different environment then
> it will work fine. My interest is in suggestions for what could
> possibily be going wrong for the JVM not to recognise a perfectly
> standard character category.
>
> If you look at the source for Pattern then the character categories are
> looked up in a simple map, in a single place in the code. How could
> this go wrong? That's my question.


The only thing I can think of is that your code is somehow picking up a
different implementation of Pattern when it's runing in your J2EE environment.
Might be worth scanning all the directories, JARs, etc, to see if there are any
candidates for confusion.

-- chris


 
Reply With Quote
 
jahhaj
Guest
Posts: n/a
 
      11-18-2005
> >
> > If you look at the source for Pattern then the character categories
> > are looked up in a simple map, in a single place in the code. How
> > could this go wrong? That's my question.

>
> Maybe some wired threading or class loading issue... Just a wild guess.
>
> robert


Hmm, I'm no java expert but if you look at the code in Pattern you see
this


private Node retrieveCategoryNode(String name) {
if (categories == null) {
int cns = categoryNodes.length;
categories = new HashMap((int)(cns/.75) + 1);
for (int x=0; x<cns; x++)
categories.put(categoryNames[x], categoryNodes[x]);
}
Node n = (Node)categories.get(name);
if (n != null)
return n;

return familyError(name, "Unknown character category {");
}

categories is a HashMap of the known categories. It's a static member.
The thing that strikes me is that the creation of the map is not
synchronised, so is it possible that one thread could be in the process
of populating the categories when another thread comes along and uses
the part populated map?

As I say, I'm no expert in java. Could someone with more expertise
confirm if this is plausible?

 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      11-18-2005
jahhaj wrote:

> Hmm, I'm no java expert but if you look at the code in Pattern you see
> this
>
>
> private Node retrieveCategoryNode(String name) {
> if (categories == null) {
> int cns = categoryNodes.length;
> categories = new HashMap((int)(cns/.75) + 1);
> for (int x=0; x<cns; x++)
> categories.put(categoryNames[x], categoryNodes[x]);
> }
> Node n = (Node)categories.get(name);
> if (n != null)
> return n;
>
> return familyError(name, "Unknown character category {");
> }
>
> categories is a HashMap of the known categories. It's a static member.


Ugh! Unless there's something subtle that I've missed, that code is completely
broken. It isn't even /nearly/ right (it could at least wait unless the new
HashMap was populated before assigning it to the 'categories' variable -- which
would still be technically incorrect).

That code has been completely replaced in 1.5.0 by something that /is/ correct
(I think).

Can you force the Pattern initalisation to happen early (before any of your
real threads are running) by compiling a throwaway Regex during some sort of
system initialisation phase ?

-- chris


 
Reply With Quote
 
Thomas G. Marshall
Guest
Posts: n/a
 
      11-18-2005
jahhaj coughed up:
> Roedy Green wrote:
>> On 18 Nov 2005 04:53:40 -0800, "jahhaj" <>
>> wrote, quoted or indirectly quoted someone who said :
>>
>>> Unknown character category {Digit} near index 8
>>> \p{Digit}{1,2}

>>
>> you did not post your code so I wrote this SSCCE
>>

>
> My real code is a few lines inside a large J2EE application. I know
> that if I extract the code and run it in a different environment then
> it will work fine.


Two ideas pulled out of someplace fairly dark:

1. Don't run it in a different environment. Extract it and keep it as much
as possible in the /same/ environment.

2. Don't "extract" it at all. Instead /pair down/ the problem code as much
as you can, possibly by putting in the testing code around the issue, and
keep testing until you remove something and see the problem go away.

This is a technique that works very well to expose many things. Even if
your paired down version ends up looking just like the extracted version you
already attempted, there might be a smidgeon of a detail missing that will
illuminate the problem.

I hope this applies to your issue. YMM(ofcourse)V.


> My interest is in suggestions for what could
> possibily be going wrong for the JVM not to recognise a perfectly
> standard character category.
>
> If you look at the source for Pattern then the character categories are
> looked up in a simple map, in a single place in the code. How could
> this go wrong? That's my question.




--
Onedoctortoanother:"Ifthisismyrectalthermometer,wh erethehell'smypen???"



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Groovy be used in an applet and/or can it generate the Java bytecodes that then can be used in an applet? Casey Hawthorne Java 1 03-18-2009 12:56 AM
Word Docs Won't Open, Can't Be E-Mailed, Can't Be Deleted, Can't Be Copied, Etc. Martin Computer Support 16 02-24-2009 07:35 PM
Wireless can get internet but can't see network -- can when wired 02befree Computer Support 0 12-24-2007 09:10 PM
SOLVED - can't open file in windows media player / WMP. But can in VLC - video LAN .. Now can in WMP jameshanley39@yahoo.co.uk Computer Information 2 09-19-2007 02:53 AM
Windows can see mapped drives, but applications can't? =?Utf-8?B?RGFuaWVsIEVpY2hvcm4=?= Wireless Networking 3 11-18-2004 11:03 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57