8054215: Use com.sun.tools.javac.util.Assert instead of 'assert'
authoralundblad
Thu, 14 Aug 2014 13:05:49 +0200
changeset 26104 34de7e01b3c1
parent 26103 3f96599b20da
child 26105 30e8bff3803b
8054215: Use com.sun.tools.javac.util.Assert instead of 'assert' Summary: Replaced assert keyword with methods from com.sun.tools.javac.util.Assert Reviewed-by: jfranck
langtools/src/share/classes/com/sun/tools/sjavac/BuildState.java
langtools/src/share/classes/com/sun/tools/sjavac/Package.java
langtools/src/share/classes/com/sun/tools/sjavac/Util.java
langtools/src/share/classes/com/sun/tools/sjavac/comp/Dependencies.java
langtools/src/share/classes/com/sun/tools/sjavac/server/PortFile.java
--- a/langtools/src/share/classes/com/sun/tools/sjavac/BuildState.java	Wed Aug 13 15:47:58 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/BuildState.java	Thu Aug 14 13:05:49 2014 +0200
@@ -31,6 +31,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import com.sun.tools.javac.util.Assert;
+
 /**
  * The build state class captures the source code and generated artifacts
  * from a build. There are usually two build states, the previous one (prev),
@@ -75,7 +77,7 @@
      */
     Module findModuleFromPackageName(String pkg) {
         int cp = pkg.indexOf(':');
-        assert(cp != -1);
+        Assert.check(cp != -1);
         String mod = pkg.substring(0, cp);
         return lookupModule(mod);
     }
@@ -94,7 +96,7 @@
             for (Map.Entry<String,Package> j : i.packages().entrySet()) {
                 Package p = packages.get(j.getKey());
                 // Check that no two different packages are stored under same name.
-                assert(p == null || p == j.getValue());
+                Assert.check(p == null || p == j.getValue());
                 if (p == null) {
                     p = j.getValue();
                     packages.put(j.getKey(),j.getValue());
@@ -102,7 +104,7 @@
                 for (Map.Entry<String,Source> k : p.sources().entrySet()) {
                     Source s = sources.get(k.getKey());
                     // Check that no two different sources are stored under same name.
-                    assert(s == null || s == k.getValue());
+                    Assert.check(s == null || s == k.getValue());
                     if (s == null) {
                         s = k.getValue();
                         sources.put(k.getKey(), k.getValue());
@@ -111,7 +113,7 @@
                 for (Map.Entry<String,File> g : p.artifacts().entrySet()) {
                     File f = artifacts.get(g.getKey());
                     // Check that no two artifacts are stored under the same file.
-                    assert(f == null || f == g.getValue());
+                    Assert.check(f == null || f == g.getValue());
                     if (f == null) {
                         f = g.getValue();
                         artifacts.put(g.getKey(), g.getValue());
@@ -134,13 +136,13 @@
             for (Map.Entry<String,Package> j : i.packages().entrySet()) {
                 Package p = packages.get(j.getKey());
                 // Check that no two different packages are stored under same name.
-                assert(p == null || p == j.getValue());
+                Assert.check(p == null || p == j.getValue());
                 p = j.getValue();
                 packages.put(j.getKey(),j.getValue());
                 for (Map.Entry<String,File> g : p.artifacts().entrySet()) {
                     File f = artifacts.get(g.getKey());
                     // Check that no two artifacts are stored under the same file.
-                    assert(f == null || f == g.getValue());
+                    Assert.check(f == null || f == g.getValue());
                     artifacts.put(g.getKey(), g.getValue());
                 }
             }
--- a/langtools/src/share/classes/com/sun/tools/sjavac/Package.java	Wed Aug 13 15:47:58 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/Package.java	Thu Aug 14 13:05:49 2014 +0200
@@ -35,6 +35,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import com.sun.tools.javac.util.Assert;
 
 /**
  * The Package class maintains meta information about a package.
@@ -83,9 +84,9 @@
 
     public Package(Module m, String n) {
         int c = n.indexOf(":");
-        assert(c != -1);
+        Assert.check(c != -1);
         String mn = n.substring(0,c);
-        assert(m.name().equals(m.name()));
+        Assert.check(m.name().equals(m.name()));
         name = n;
         dirname = n.replace('.', File.separatorChar);
         if (m.name().length() > 0) {
@@ -256,7 +257,7 @@
     }
 
     public void setArtifacts(Set<URI> as) {
-        assert(!artifacts.isEmpty());
+        Assert.check(!artifacts.isEmpty());
         artifacts = new HashMap<>();
         addArtifacts(as);
     }
--- a/langtools/src/share/classes/com/sun/tools/sjavac/Util.java	Wed Aug 13 15:47:58 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/Util.java	Thu Aug 14 13:05:49 2014 +0200
@@ -62,7 +62,8 @@
 
     public static String justPackageName(String pkgName) {
         int c = pkgName.indexOf(":");
-        assert(c != -1);
+        if (c == -1)
+            throw new IllegalArgumentException("Expected ':' in package name (" + pkgName + ")");
         return pkgName.substring(c+1);
     }
 
--- a/langtools/src/share/classes/com/sun/tools/sjavac/comp/Dependencies.java	Wed Aug 13 15:47:58 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/comp/Dependencies.java	Thu Aug 14 13:05:49 2014 +0200
@@ -34,6 +34,7 @@
 import java.util.Set;
 
 import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.util.Assert;
 import com.sun.tools.javac.util.Context;
 import com.sun.tools.javac.util.Log;
 import com.sun.tools.javac.util.Name;
@@ -154,7 +155,7 @@
         Name n = ((ClassSymbol)e).fullname;
         Name p = ((ClassSymbol)e).packge().fullname;
         StringBuffer sb = publicApiPerClass.get(n);
-        assert(sb == null);
+        Assert.check(sb == null);
         sb = new StringBuffer();
         PubapiVisitor v = new PubapiVisitor(sb);
         v.visit(e);
--- a/langtools/src/share/classes/com/sun/tools/sjavac/server/PortFile.java	Wed Aug 13 15:47:58 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/server/PortFile.java	Thu Aug 14 13:05:49 2014 +0200
@@ -33,6 +33,7 @@
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 import java.nio.channels.FileLockInterruptionException;
+import com.sun.tools.javac.util.Assert;
 import com.sun.tools.sjavac.Log;
 
 /**
@@ -130,7 +131,7 @@
      * If so, then we can acquire the tcp/ip port on localhost.
      */
     public int getPort() {
-        assert(containsPortInfo);
+        Assert.check(containsPortInfo);
         return serverPort;
     }
 
@@ -138,7 +139,7 @@
      * If so, then we can acquire the server cookie.
      */
     public long getCookie() {
-        assert(containsPortInfo);
+        Assert.check(containsPortInfo);
         return serverCookie;
     }
 
@@ -146,7 +147,7 @@
      * Store the values into the locked port file.
      */
     public void setValues(int port, long cookie) throws IOException {
-        assert(lock != null);
+        Assert.check(lock != null);
         rwfile.seek(0);
         // Write the magic nr that identifes a port file.
         rwfile.writeInt(magicNr);
@@ -191,7 +192,7 @@
      * Unlock the port file.
      */
     public void unlock() throws IOException {
-        assert(lock != null);
+        Assert.check(lock != null);
         lock.release();
         lock = null;
     }