You can replace this block of code by MCJavaStringToStringRef (remember, MCSTR can only be used on static c-string constants, which t_utfchars is not).