You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@directory.apache.org by Flavio Mattos <fl...@gmail.com> on 2014/01/10 07:56:05 UTC

Re: ArrayIndexOutOfBoundsException with special characters - Strings.TO_LOWER_CASE

After decompiling the class Strings I was able to see that this API tries
to
lower-case everything.  The TO_LOWER_CASE array (char [])  does not have any
chinese/japanese character that is why the ArrayIndexOutOfBoundsException
happens... The question is: What now? should I override those methods?
Is there another way?

Thanks


On Thu, Jan 9, 2014 at 6:40 PM, Flavio Mattos <fl...@gmail.com>wrote:

> hi guys...
>
> I am facing an java.lang.ArrayIndexOutOfBoundsException: 33539
> when I try to call the constructor to create an entry..
>
> Entry entry = new
> DefaultEntry("uid=netbeans,ou=customer_service,ou=employees,dc=example,dc=com",
>                 "cn: netbeans",
>                 "sn: netbeans",
>                 "givenName: 范",
>                 "mail: test@test.com,
>                 "userPassword: {SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=",
>                 "objectClass: inetOrgPerson",
>                 "objectClass: organizationalPerson",
>                 "objectClass: person",
>                 "objectClass: top"
>         );
>
> Does anybody have any idea?
> I have tried to use Base64.encodeBase64String("范".getBytes());
> It gives me something like 6IyD, which is correct, but when I look in the
> LDAP studio it still like 6IyD
>
>
>
> Thanks
>

Re: ArrayIndexOutOfBoundsException with special characters - Strings.TO_LOWER_CASE

Posted by Flavio Mattos <fl...@gmail.com>.
Yes I have tried it and it kind of works, but the problem is when I go to
the Apache Studio it shows me like a simple string.. With 2 operations I
can see the special characters
In their original value

Thanks
Flavio


On Friday, January 10, 2014, Emmanuel Lécharny wrote:

> Le 1/11/14 4:02 AM, Flavio Mattos a écrit :
> > Hi Emmanuel, the ticket has been created
> > https://issues.apache.org/jira/browse/DIRAPI-172
> >
> > I found a work around for that problem, I insert the entry using
> > encodeBase64 and after the insert I update the entry using ModifyRequest,
> > using the original special character without any encoding.. And it
> works..
>
> Have you tested the workaround I sugested ? It should work, without
> having to do 2 operations (Add and Modify).
>
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>

Re: ArrayIndexOutOfBoundsException with special characters - Strings.TO_LOWER_CASE

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 1/11/14 4:02 AM, Flavio Mattos a écrit :
> Hi Emmanuel, the ticket has been created
> https://issues.apache.org/jira/browse/DIRAPI-172
>
> I found a work around for that problem, I insert the entry using
> encodeBase64 and after the insert I update the entry using ModifyRequest,
> using the original special character without any encoding.. And it works..

Have you tested the workaround I sugested ? It should work, without
having to do 2 operations (Add and Modify).


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: ArrayIndexOutOfBoundsException with special characters - Strings.TO_LOWER_CASE

Posted by Flavio Mattos <fl...@gmail.com>.
Hi Emmanuel, the ticket has been created
https://issues.apache.org/jira/browse/DIRAPI-172

I found a work around for that problem, I insert the entry using
encodeBase64 and after the insert I update the entry using ModifyRequest,
using the original special character without any encoding.. And it works..

Thanks


On Fri, Jan 10, 2014 at 12:20 AM, Emmanuel Lécharny <el...@gmail.com>wrote:

> Le 1/10/14 8:45 AM, Flavio Mattos a écrit :
> > Emmanuel, thanks for the answer..
> > About the jira, should it be an improvement, new feature or bug?
>
> Improvement, I think.
>
> FYI, I have created another JIRA for the single quote pb :
> https://issues.apache.org/jira/browse/DIRAPI-171
>
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>

Re: ArrayIndexOutOfBoundsException with special characters - Strings.TO_LOWER_CASE

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 1/10/14 8:45 AM, Flavio Mattos a écrit :
> Emmanuel, thanks for the answer..
> About the jira, should it be an improvement, new feature or bug?

Improvement, I think.

FYI, I have created another JIRA for the single quote pb :
https://issues.apache.org/jira/browse/DIRAPI-171


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Re: ArrayIndexOutOfBoundsException with special characters - Strings.TO_LOWER_CASE

Posted by Flavio Mattos <fl...@gmail.com>.
Emmanuel, thanks for the answer..
About the jira, should it be an improvement, new feature or bug?

Thanks again

Flavio


On Thu, Jan 9, 2014 at 11:22 PM, Emmanuel Lécharny <el...@gmail.com>wrote:

> Le 1/10/14 7:56 AM, Flavio Mattos a écrit :
> > After decompiling the class Strings I was able to see that this API tries
> > to
> > lower-case everything.  The TO_LOWER_CASE array (char [])  does not have
> any
> > chinese/japanese character that is why the ArrayIndexOutOfBoundsException
> > happens... The question is: What now? should I override those methods?
> > Is there another way?
>
> Well, you are not supposed to use anything but ASCII chars in a LDIF
> based entry (http://www.ietf.org/rfc/rfc2849.txt):
>
> attrval-spec             = AttributeDescription value-spec SEP
>
> value-spec               = ":" (    FILL 0*1(SAFE-STRING) /
>                                 ":" FILL (BASE64-STRING) /
>                                 "<" FILL url)
>
> SAFE-STRING              = [SAFE-INIT-CHAR *SAFE-CHAR]
>
> SAFE-CHAR                = %x01-09 / %x0B-0C / %x0E-7F
>                            ; any value <= 127 decimal except NUL, LF,
>                            ; and CR
>
> SAFE-INIT-CHAR           = %x01-09 / %x0B-0C / %x0E-1F /
>                            %x21-39 / %x3B / %x3D-7F
>                            ; any value <= 127 except NUL, LF, CR,
>                            ; SPACE, colon (":", ASCII 58 decimal)
>                            ; and less-than ("<" , ASCII 60 decimal)
>
>
> The char you are using is well out of this scope. What you must do is to
> base-64 encode the String, like in :
>
>         Entry entry = new
>
>
> DefaultEntry("uid=netbeans,ou=customer_service,ou=employees,dc=example,dc=com",
>                             "cn: netbeans",
>                             "sn: netbeans",
>                             "givenName::", new String( Base64.encode(
> Strings.getBytesUtf8( "范" ) ) ),
>                             "mail: test@test.com",
>                             "userPassword:
> {SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=",
>                             "objectClass: inetOrgPerson",
>                             "objectClass: organizationalPerson",
>                             "objectClass: person",
>                             "objectClass: top"
>                     );
>
> I admit this is not exactly convenient, for many reasons :
>
> o you should not get an ArrayIndexOutOfBoundsException, but a better
> exception that tells you what's really wrong
> o the conversion should be automatic assuming the value is not an ASCII
> char. I would rather have something like :
>
>         Entry entry = new
>
>
> DefaultEntry("uid=netbeans,ou=customer_service,ou=employees,dc=example,dc=com",
>                             "cn: netbeans",
>                             "sn: netbeans",
>                             "givenName", "范", // or "giveName:", "范",
> or even "givenName::", "范", or even better "givenName: 范",
>                             ...
>                     );
> where the "范" string is automatically converted to a Base 64 String,
> and the '::' being automatically added
> o I must warn you that using "范" as a String in some java code is
> really a bad idea : it forces you to use a 'UTF-8' file format, which
> may be lost if someone is convertng your file to another charset. I
> would rather suggest you to use '\U8303'. Note that it won't fix the
> issue you have.
>
> I consider that my initial proposal is just a workaround, and my
> suggestion should be implemented. Woudl you be kind enough to fill a
> JIRA so that we don't forget to fix this ?
>
> Sidenote : the Entry.toString method is not convenient either. It adds '
> around a binary values (a pb you already mentionned in a previous post).
> We should rather show the value as a base64 encoded String (and provide
> anotehr toString() method if we want to expose the binary value as a hex
> string).
>
> Many thanks !
>
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>

Re: ArrayIndexOutOfBoundsException with special characters - Strings.TO_LOWER_CASE

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 1/10/14 7:56 AM, Flavio Mattos a écrit :
> After decompiling the class Strings I was able to see that this API tries
> to
> lower-case everything.  The TO_LOWER_CASE array (char [])  does not have any
> chinese/japanese character that is why the ArrayIndexOutOfBoundsException
> happens... The question is: What now? should I override those methods?
> Is there another way?

Well, you are not supposed to use anything but ASCII chars in a LDIF
based entry (http://www.ietf.org/rfc/rfc2849.txt):

attrval-spec             = AttributeDescription value-spec SEP

value-spec               = ":" (    FILL 0*1(SAFE-STRING) /
                                ":" FILL (BASE64-STRING) /
                                "<" FILL url)

SAFE-STRING              = [SAFE-INIT-CHAR *SAFE-CHAR]

SAFE-CHAR                = %x01-09 / %x0B-0C / %x0E-7F
                           ; any value <= 127 decimal except NUL, LF,
                           ; and CR

SAFE-INIT-CHAR           = %x01-09 / %x0B-0C / %x0E-1F /
                           %x21-39 / %x3B / %x3D-7F
                           ; any value <= 127 except NUL, LF, CR,
                           ; SPACE, colon (":", ASCII 58 decimal)
                           ; and less-than ("<" , ASCII 60 decimal)


The char you are using is well out of this scope. What you must do is to
base-64 encode the String, like in :

        Entry entry = new
           
DefaultEntry("uid=netbeans,ou=customer_service,ou=employees,dc=example,dc=com",
                            "cn: netbeans",
                            "sn: netbeans",
                            "givenName::", new String( Base64.encode(
Strings.getBytesUtf8( "范" ) ) ),
                            "mail: test@test.com",
                            "userPassword:
{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=",
                            "objectClass: inetOrgPerson",
                            "objectClass: organizationalPerson",
                            "objectClass: person",
                            "objectClass: top"
                    );

I admit this is not exactly convenient, for many reasons :

o you should not get an ArrayIndexOutOfBoundsException, but a better
exception that tells you what's really wrong
o the conversion should be automatic assuming the value is not an ASCII
char. I would rather have something like :

        Entry entry = new
           
DefaultEntry("uid=netbeans,ou=customer_service,ou=employees,dc=example,dc=com",
                            "cn: netbeans",
                            "sn: netbeans",
                            "givenName", "范", // or "giveName:", "范",
or even "givenName::", "范", or even better "givenName: 范",
                            ...
                    );
where the "范" string is automatically converted to a Base 64 String,
and the '::' being automatically added
o I must warn you that using "范" as a String in some java code is
really a bad idea : it forces you to use a 'UTF-8' file format, which
may be lost if someone is convertng your file to another charset. I
would rather suggest you to use '\U8303'. Note that it won't fix the
issue you have.

I consider that my initial proposal is just a workaround, and my
suggestion should be implemented. Woudl you be kind enough to fill a
JIRA so that we don't forget to fix this ?

Sidenote : the Entry.toString method is not convenient either. It adds '
around a binary values (a pb you already mentionned in a previous post).
We should rather show the value as a base64 encoded String (and provide
anotehr toString() method if we want to expose the binary value as a hex
string).

Many thanks !


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com