You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (JIRA)" <ji...@apache.org> on 2018/05/17 05:54:00 UTC
[jira] [Resolved] (GROOVY-6631) Static compilation fails around
byte arrays
[ https://issues.apache.org/jira/browse/GROOVY-6631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Sun resolved GROOVY-6631.
--------------------------------
Resolution: Not A Problem
Assignee: Daniel Sun
`i / 2` will yield a `BigDecimal`, e.g. 1 / 2 yields 0.5, not 0.
`data[i / 2]` should be modified as `data[(int) (i / 2)]`, the complete code is:
{code:java}
@groovy.transform.CompileStatic
class Test {
byte[] parseStructuredString(String s) {
byte[] data = new byte[s.length() / 2];
for (int i = 0; i < s.length(); i += 2) {
data[(int) (i / 2)] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16));
}
return data
}
}
{code}
> Static compilation fails around byte arrays
> -------------------------------------------
>
> Key: GROOVY-6631
> URL: https://issues.apache.org/jira/browse/GROOVY-6631
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 2.3.0, 2.4.0-rc-1
> Reporter: Dimitar Dimitrov
> Assignee: Daniel Sun
> Priority: Major
>
> {code}
> @groovy.transform.CompileStatic
> class Test {
> byte[] parseStructuredString(String s) {
> byte[] data = new byte[s.length() / 2];
> for (int i = 0; i < s.length(); i += 2) {
> data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16));
> }
> return data
> }
> }
> {code}
> Error:(11, 13) Groovyc: [Static type checking] - Cannot find matching method [B#getAt(java.math.BigDecimal). Please check if the declared type is right and if the method exists.
> Error:(11, 27) Groovyc: [Static type checking] - Cannot assign value of type byte to variable of type byte[]
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)