jiangzhendong / google-api-translate-java

Automatically exported from code.google.com/p/google-api-translate-java
0 stars 0 forks source link

IndexOutOfBoundsException when translating English to Arabic BETA #2

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Write the following code in a JSP:

if(request.getParameter("textToTranslate") != null 
    && request.getParameter("textToTranslate").trim()!="") {
        String textToTranslate = request.getParameter("textToTranslate");
        String translatedText = Translate.translate(textToTranslate,
Language.ENGLISH, Language.ARABIC);
        out.println(translatedText);
    }

The JSP must be passed some Arabic text from another page as form fields.

2. Run the page.

What is the expected output? What do you see instead?

The expected output is a page that has the Arabic Translation. It shows an
empty page with the following exception:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.StringBuffer.substring(StringBuffer.java:861)
    at com.google.api.translate.Translate.translate(Translate.java:47)
    at org.apache.jsp.translate_jsp._jspService(translate_jsp.java:59)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilt
erChain.java:269)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
java:188)
    at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:2
10)
    at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:1
74)
    at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108
)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
    at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConne
ction(Http11BaseProtocol.java:665)
    at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:52
8)
    at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorker
Thread.java:81)
    at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:68
5)
    at java.lang.Thread.run(Thread.java:799)

What version of the product are you using? On what operating system?
I am using version 0.2 on Windows XP and running the web application on
Tomcat v5.5.

Original issue reported on code.google.com by zab....@gmail.com on 31 Oct 2007 at 1:23

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I've added a new version, 0.21, with a fix for languages that read from right to
left. It shouldn't throw a null pointer now but I'm not sure whether the 
encoding
will be correct. I'll look into it further later.

Original comment by rich.mid...@gmail.com on 31 Oct 2007 at 9:15

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
You are right as it may have some encoding problems. I tried translating "How 
are
you" with the 0.21 API and the good thing is that there were no exceptions but 
still
the output is bad.

Please see the screenshot.

Original comment by zab....@gmail.com on 31 Oct 2007 at 6:12

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for your help on this Zab. I've released 0.22 which should work 
correctly now.

Original comment by rich.mid...@gmail.com on 3 Nov 2007 at 12:22