You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "vincent royer (JIRA)" <ji...@apache.org> on 2016/11/25 22:25:58 UTC

[jira] [Commented] (CASSANDRA-9626) Make C* work in all locales

    [ https://issues.apache.org/jira/browse/CASSANDRA-9626?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15696786#comment-15696786 ] 

vincent royer commented on CASSANDRA-9626:
------------------------------------------

Using the javassist maven plugin and the following class transformer can fix the cassandra byte-code to be "Locale-independant". 

public class StringLocaleTransformer extends ClassTransformer {

    public void applyTransformations(ClassPool pool, CtClass classToTransform) throws TransformationException {
        try {
            final CtMethod[] targetMethods = classToTransform.getDeclaredMethods();
            for (int i = 0; i < targetMethods.length; i++) {
                targetMethods[i].instrument(new ExprEditor() {
                    public void edit(final MethodCall m) throws CannotCompileException {
                        if ("java.lang.String".equals(m.getClassName())) {
                           if ("format".equals(m.getMethodName()) && m.getSignature().startsWith("(Ljava/lang/String;")) {
                               System.out.println("Modifing format() @ "+m.getFileName()+":"+m.getLineNumber());
                               m.replace("{$_ = java.lang.String.format(java.util.Locale.ROOT, $$);}");
                           } else if ("toUpperCase".equals(m.getMethodName()) && m.getSignature().startsWith("()")) {
                               System.out.println("Modifing toUpperCase() @ "+m.getFileName()+":"+m.getLineNumber());
                               m.replace("{$_ = $proceed(java.util.Locale.ROOT);}");
                           } else if ("toLowerCase".equals(m.getMethodName()) && m.getSignature().startsWith("()")) {
                               System.out.println("Modifing toLowerCase() @ "+m.getFileName()+":"+m.getLineNumber());
                               m.replace("{$_ = $proceed(java.util.Locale.ROOT);}");
                           }
                        }
                    }
                });
            }
        } catch (CannotCompileException e) {
            e.printStackTrace();
        }
    }
}

> Make C* work in all locales
> ---------------------------
>
>                 Key: CASSANDRA-9626
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-9626
>             Project: Cassandra
>          Issue Type: Improvement
>            Reporter: Robert Stupp
>            Priority: Minor
>         Attachments: 9626.txt
>
>
> Default locale and default charset has immediate effect on how strings are encoded and handles - e.g. via {{String.toLowerCase()}} or {{new String(byte[])}}.
> Problems with different default locales + charsets don't become obvious for US and most European regional settings. But some regional OS settings will cause severe errors. Example: {{"BILLY".toLowerCase()}} returns {{bılly}} with Locale tr_TR (take a look at the second letter - it's an i without the dot).
> (ref: http://blog.thetaphi.de/2012/07/default-locales-default-charsets-and.html)
> It's not a problem I'm currently facing, but it could become a problem for some users. A quick fix could be to set default locale and charset in the start scripts - maybe that's all we need.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)