[ https://issues.apache.org/jira/browse/GROOVY-11749?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-11749: --------------------------------- Description: When working on getting the Matrix project to work with Groovy 5 I encountered the following differences compared to 4.0.28 for static compilation: f is a csv commons formatter. The setHeader method has the following signature: {code:java} f.setHeader(String... headers) {code} In 4.0.28 i used to be able to just cast a List<String> to a String[] like this: {code:groovy} if (val instanceof List) { f.setHeader(val as String[]) {code} But in Groovy 5 this gives me the following error: {code} java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class [Ljava.lang.String; (java.util.ArrayList and [Ljava.lang.String; are in module java.base of loader 'bootstrap') {code} A workaround is to use the Java way i.e: {code:groovy} if (val instanceof List) { f.setHeader(val.toArray(new String[0]) as String[]) {code} Another thing i hade to change was {code:groovy} static String asColumnName(int number) { StringBuilder sb = new StringBuilder() while (number-- > 0) { sb.append(('A' as char + (number % 26)) as char) number /= 26 } return sb.reverse().toString() } {code} Which no longer compiles: {code} .../SpreadsheetUtil.groovy: 45: [Static type checking] - Cannot assign value of type java.math.BigDecimal to variable of type int {code} but had to be changed to {code:groovy} static String asColumnName(int number) { StringBuilder sb = new StringBuilder() while (number-- > 0) { sb.append(('A' as char + (number % 26)) as char) number = (int) (number / 26) } return sb.reverse().toString() } {code} was: When working on getting the Matrix project to work with Groovy 5 I encountered the following differences compared to 4.0.28 for static compilation: f is a csv commons formatter. The setHeader method has the following signature: {code:java} f.setHeader(String... headers) {code} In 4.0.28 i used to be able to just cast a List<String> to a String[] like this: {code:groovy} if (val instanceof List) { f.setHeader(val as String[]) {code} But in Groovy 5 this gives me the following error: {code} java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class [Ljava.lang.String; (java.util.ArrayList and [Ljava.lang.String; are in module java.base of loader 'bootstrap') {code} A workaround is to use the Java way i.e: {code:groovy} if (val instanceof List) { f.setHeader(val.toArray(new String[0]) as String[]) {code} Another thing i hade to change was {code:groovy} static String asColumnName(int number) { StringBuilder sb = new StringBuilder() while (number-- > 0) { sb.append(('A' as char + (number % 26)) as char) *number /= 26* } return sb.reverse().toString() } {code} Which no longer compiles: {code} .../SpreadsheetUtil.groovy: 45: [Static type checking] - Cannot assign value of type java.math.BigDecimal to variable of type int {code} but had to be changed to {code:groovy} static String asColumnName(int number) { StringBuilder sb = new StringBuilder() while (number-- > 0) { sb.append(('A' as char + (number % 26)) as char) *number = (int) (number / 26)* } return sb.reverse().toString() } {code} > CompileStatic issues in Groovy 5 > -------------------------------- > > Key: GROOVY-11749 > URL: https://issues.apache.org/jira/browse/GROOVY-11749 > Project: Groovy > Issue Type: Bug > Environment: Groovy 5.0.0, Gradle 8.14.3, JVM: 21.0.6 > Reporter: Per Nyfelt > Priority: Major > > When working on getting the Matrix project to work with Groovy 5 I > encountered the following differences compared to 4.0.28 for static > compilation: > f is a csv commons formatter. The setHeader method has the following > signature: > {code:java} > f.setHeader(String... headers) > {code} > In 4.0.28 i used to be able to just cast a List<String> to a String[] like > this: > {code:groovy} > if (val instanceof List) { > f.setHeader(val as String[]) > {code} > But in Groovy 5 this gives me the following error: > {code} > java.lang.ClassCastException: class java.util.ArrayList cannot be cast to > class [Ljava.lang.String; (java.util.ArrayList and [Ljava.lang.String; are in > module java.base of loader 'bootstrap') > {code} > A workaround is to use the Java way i.e: > {code:groovy} > if (val instanceof List) { > f.setHeader(val.toArray(new String[0]) as String[]) > {code} > Another thing i hade to change was > {code:groovy} > static String asColumnName(int number) { > StringBuilder sb = new StringBuilder() > while (number-- > 0) { > sb.append(('A' as char + (number % 26)) as char) > number /= 26 > } > return sb.reverse().toString() > } > {code} > Which no longer compiles: > {code} > .../SpreadsheetUtil.groovy: 45: [Static type checking] - Cannot assign value > of type java.math.BigDecimal to variable of type int > {code} > but had to be changed to > {code:groovy} > static String asColumnName(int number) { > StringBuilder sb = new StringBuilder() > while (number-- > 0) { > sb.append(('A' as char + (number % 26)) as char) > number = (int) (number / 26) > } > return sb.reverse().toString() > } > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)