groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 03/11: Fix potential bugs when Math.abs(Integer.MIN_VALUE)<0
Date Wed, 21 Aug 2019 09:24:03 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit fc4fa9aaa117160f457eb41286da5f07e0f80f07
Author: Bo Zhang <zhangbodut@gmail.com>
AuthorDate: Sat Aug 17 19:10:28 2019 +0800

    Fix potential bugs when Math.abs(Integer.MIN_VALUE)<0
    
    It is possible for a call to hashCode to return Integer.MIN_VALUE.
    Take the absolute value of such a hashcode and you'll still have a negative number.
    To fix the problem, cast it to long.
---
 src/main/java/groovy/lang/GroovyClassLoader.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/groovy/lang/GroovyClassLoader.java b/src/main/java/groovy/lang/GroovyClassLoader.java
index 262b232..2d726d9 100644
--- a/src/main/java/groovy/lang/GroovyClassLoader.java
+++ b/src/main/java/groovy/lang/GroovyClassLoader.java
@@ -270,7 +270,7 @@ public class GroovyClassLoader extends URLClassLoader {
      */
     public Class parseClass(String text) throws CompilationFailedException {
         return parseClass(text, "script" + System.currentTimeMillis() +
-                Math.abs(text.hashCode()) + ".groovy");
+                Math.abs((long) text.hashCode()) + ".groovy");
     }
 
     public synchronized String generateScriptName() {


Mime
View raw message