Author: tilman
Date: Sat Dec  8 12:36:10 2018
New Revision: 1848466

URL: http://svn.apache.org/viewvc?rev=1848466&view=rev
Log:
PDFBOX-4401: refactor for SonarQube

Modified:
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java?rev=1848466&r1=1848465&r2=1848466&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java 
(original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java 
Sat Dec  8 12:36:10 2018
@@ -404,44 +404,12 @@ public class PDFRenderer
                 Class.forName("sun.java2d.cmm.kcms.KcmsServiceProvider");
 
                 String version = System.getProperty("java.version");
-                if (version == null)
+                if (version == null ||
+                    isGoodVersion(version, "1.8.0_(\\d+)", 191) ||
+                    isGoodVersion(version, "9.0.(\\d+)", 4))
                 {
                     return;
                 }
-                Matcher matcher = 
Pattern.compile("1.8.0_(\\d+)").matcher(version);
-                if (matcher.matches() && matcher.groupCount() >= 1)
-                {
-                    try
-                    {
-                        int v = Integer.parseInt(matcher.group(1));
-                        if (v >= 191)
-                        {
-                            // LCMS no longer bad
-                            return;
-                        }
-                    }
-                    catch (NumberFormatException ex)
-                    {
-                        return;
-                    }
-                }
-                matcher = Pattern.compile("9.0.(\\d+)").matcher(version);
-                if (matcher.matches() && matcher.groupCount() >= 1)
-                {
-                    try
-                    {
-                        int v = Integer.parseInt(matcher.group(1));
-                        if (v >= 4)
-                        {
-                            // LCMS no longer bad
-                            return;
-                        }
-                    }
-                    catch (NumberFormatException ex)
-                    {
-                        return;
-                    }
-                }
                 LOG.info("Your current java version is: " + version);
                 LOG.info("To get higher rendering speed on old java 1.8 or 9 
versions,");
                 LOG.info("  update to the latest 1.8 or 9 version (>= 
1.8.0_191 or >= 9.0.4),");
@@ -456,6 +424,28 @@ public class PDFRenderer
         }
     }
 
+    private static boolean isGoodVersion(String version, String regex, int min)
+    {
+        Matcher matcher = Pattern.compile(regex).matcher(version);
+        if (matcher.matches() && matcher.groupCount() >= 1)
+        {
+            try
+            {
+                int v = Integer.parseInt(matcher.group(1));
+                if (v >= min)
+                {
+                    // LCMS no longer bad
+                    return true;
+                }
+            }
+            catch (NumberFormatException ex)
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private static boolean isMinJdk8()
     {
         // strategy from 
lucene-solr/lucene/core/src/java/org/apache/lucene/util/Constants.java


Reply via email to