You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "David Estes (Jira)" <ji...@apache.org> on 2020/04/20 16:58:00 UTC

[jira] [Updated] (GROOVY-9517) CompileStatic typeCasting runtime error from Class Array to Class List

     [ https://issues.apache.org/jira/browse/GROOVY-9517?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

David Estes updated GROOVY-9517:
--------------------------------
    Description: 
After upgrading asset-pipeline-core from groovy 2.0.7 to 2.4.15 then 2.4.19 . A bug was identified with @CompileStatic not properly handling runtime type casting when sorting an Array instead of a List

 

Example

 

Create File TestFile.groovy
{code:java}
import groovy.transform.CompileStaticpublic class TestFile {	
    static void main(String[] args) {
        File file = new File('.')
        TestFile testFile = new TestFile()
        testFile.listSortedFiles(file)
    }

    @CompileStatic
    void listSortedFiles(File directory) {
        File[] files = directory.listFiles()
        files = files?.sort { File a, File b -> a.name.compareTo b.name } as File[]
        for(File file in files) {
        }
    }
	
		
}

{code}
Then simply run:
{code:java}
groovy TestFile.groovy
{code}
 

Exception:

 
{code:java}
Caught: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.io.File;
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.io.File;
	at TestFile.listSortedFiles(TestFile.groovy:15)
	at TestFile$listSortedFiles.call(Unknown Source)
	at TestFile.main(TestFile.groovy:8)
{code}
 

  was:
After upgrading asset-pipeline-core from groovy 2.0.7 to 2.4.15 then 2.4.19 . A bug was identified with @CompileStatic not properly handling runtime type casting when sorting an Array instead of a List

 

Example

 

Create File TestFile.groovy
{code:java}
import groovy.transform.CompileStaticpublic class TestFile {	static void main(String[] args) {
		File file = new File('.')
		TestFile testFile = new TestFile()
		testFile.listSortedFiles(file)
	}
	@CompileStatic
	void listSortedFiles(File directory) {
		File[] files = directory.listFiles()
		files = files?.sort { File a, File b -> a.name.compareTo b.name } as File[]
		for(File file in files) {
		}
	}
	
		
}

{code}
Then simply run:
{code:java}
groovy TestFile.groovy
{code}
 

Exception:

 
{code:java}
Caught: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.io.File;
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.io.File;
	at TestFile.listSortedFiles(TestFile.groovy:15)
	at TestFile$listSortedFiles.call(Unknown Source)
	at TestFile.main(TestFile.groovy:8)
{code}
 


> CompileStatic typeCasting runtime error from Class Array to Class List
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-9517
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9517
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.0, 2.4.19, 3.0.2, 3.0.3
>         Environment: Java: openjdk version "1.8.0_242"
> OS: OS X Catalina 10.15.3
> Groovy: 2.4.19
>            Reporter: David Estes
>            Priority: Major
>              Labels: CompileStatic
>
> After upgrading asset-pipeline-core from groovy 2.0.7 to 2.4.15 then 2.4.19 . A bug was identified with @CompileStatic not properly handling runtime type casting when sorting an Array instead of a List
>  
> Example
>  
> Create File TestFile.groovy
> {code:java}
> import groovy.transform.CompileStaticpublic class TestFile {	
>     static void main(String[] args) {
>         File file = new File('.')
>         TestFile testFile = new TestFile()
>         testFile.listSortedFiles(file)
>     }
>     @CompileStatic
>     void listSortedFiles(File directory) {
>         File[] files = directory.listFiles()
>         files = files?.sort { File a, File b -> a.name.compareTo b.name } as File[]
>         for(File file in files) {
>         }
>     }
> 	
> 		
> }
> {code}
> Then simply run:
> {code:java}
> groovy TestFile.groovy
> {code}
>  
> Exception:
>  
> {code:java}
> Caught: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.io.File;
> java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.io.File;
> 	at TestFile.listSortedFiles(TestFile.groovy:15)
> 	at TestFile$listSortedFiles.call(Unknown Source)
> 	at TestFile.main(TestFile.groovy:8)
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)