From 70ec72585d401c8dbb1eeca0310935bdba3d3974 Mon Sep 17 00:00:00 2001
From: Xiomara Jayasena
Date: Tue, 4 Dec 2007 16:28:05 -0800
Subject: [PATCH 001/126] Added tag jdk7-b24 for changeset fd16c54261b3
---
.hgtags-top-repo | 1 +
1 file changed, 1 insertion(+)
create mode 100644 .hgtags-top-repo
diff --git a/.hgtags-top-repo b/.hgtags-top-repo
new file mode 100644
index 00000000000..ff06c88a2bf
--- /dev/null
+++ b/.hgtags-top-repo
@@ -0,0 +1 @@
+cfeea66a3fa8ca3686a7cfa2d0ce8ab0169f168d jdk7-b24
From 7828a7dee6d967804cb355a8a7c9a0fad3dcc920 Mon Sep 17 00:00:00 2001
From: Xiomara Jayasena
Date: Tue, 4 Dec 2007 16:28:13 -0800
Subject: [PATCH 002/126] Added tag jdk7-b24 for changeset 02bb8761fcce
---
corba/.hgtags | 1 +
1 file changed, 1 insertion(+)
create mode 100644 corba/.hgtags
diff --git a/corba/.hgtags b/corba/.hgtags
new file mode 100644
index 00000000000..f50e5065b96
--- /dev/null
+++ b/corba/.hgtags
@@ -0,0 +1 @@
+55540e827aef970ecc010b7e06b912d991c8e3ce jdk7-b24
From dcbf4ea9ee880b926385c29053519e4bb9a41a89 Mon Sep 17 00:00:00 2001
From: Xiomara Jayasena
Date: Tue, 4 Dec 2007 16:28:18 -0800
Subject: [PATCH 003/126] Added tag jdk7-b24 for changeset 489c9b5090e2
---
hotspot/.hgtags | 1 +
1 file changed, 1 insertion(+)
create mode 100644 hotspot/.hgtags
diff --git a/hotspot/.hgtags b/hotspot/.hgtags
new file mode 100644
index 00000000000..c3230a6f10b
--- /dev/null
+++ b/hotspot/.hgtags
@@ -0,0 +1 @@
+a61af66fc99eb5ec9d50c05b0c599757b1289ceb jdk7-b24
From 3dde8f95e5834baac1eca32582026d2a35dc1721 Mon Sep 17 00:00:00 2001
From: Xiomara Jayasena
Date: Tue, 4 Dec 2007 16:28:22 -0800
Subject: [PATCH 004/126] Added tag jdk7-b24 for changeset 7f561c08de6b
---
jaxp/.hgtags | 1 +
1 file changed, 1 insertion(+)
create mode 100644 jaxp/.hgtags
diff --git a/jaxp/.hgtags b/jaxp/.hgtags
new file mode 100644
index 00000000000..0c27eee3f67
--- /dev/null
+++ b/jaxp/.hgtags
@@ -0,0 +1 @@
+6ce5f4757bde08f7470cbb9f0b46da8f2f3d4f56 jdk7-b24
From fcc15c26e24ffb7ff91d99084fca13eb9f644e8a Mon Sep 17 00:00:00 2001
From: Xiomara Jayasena
Date: Tue, 4 Dec 2007 16:28:24 -0800
Subject: [PATCH 005/126] Added tag jdk7-b24 for changeset 474761f14bca
---
jaxws/.hgtags | 1 +
1 file changed, 1 insertion(+)
create mode 100644 jaxws/.hgtags
diff --git a/jaxws/.hgtags b/jaxws/.hgtags
new file mode 100644
index 00000000000..f96f9279308
--- /dev/null
+++ b/jaxws/.hgtags
@@ -0,0 +1 @@
+0961a4a211765fea071b8dac419003ee0c3d5973 jdk7-b24
From e40791d448cfe4acb83eaba17d0d56bb4917e2af Mon Sep 17 00:00:00 2001
From: Xiomara Jayasena
Date: Tue, 4 Dec 2007 16:28:33 -0800
Subject: [PATCH 006/126] Added tag jdk7-b24 for changeset 90ce3da70b43
---
jdk/.hgtags | 1 +
1 file changed, 1 insertion(+)
create mode 100644 jdk/.hgtags
diff --git a/jdk/.hgtags b/jdk/.hgtags
new file mode 100644
index 00000000000..898e4a75668
--- /dev/null
+++ b/jdk/.hgtags
@@ -0,0 +1 @@
+37a05a11f281b4d238e2f9e7ebb67c63f64d0e77 jdk7-b24
From fde483bc31506313b228b55c163dc7cd3716ea04 Mon Sep 17 00:00:00 2001
From: Mark Reinhold
Date: Fri, 29 Feb 2008 20:03:57 -0800
Subject: [PATCH 007/126] 6669216: Add jcheck configuration directories
Reviewed-by: ohair, xdono
---
.jcheck/conf | 1 +
1 file changed, 1 insertion(+)
create mode 100644 .jcheck/conf
diff --git a/.jcheck/conf b/.jcheck/conf
new file mode 100644
index 00000000000..d8227cd90e3
--- /dev/null
+++ b/.jcheck/conf
@@ -0,0 +1 @@
+project=jdk7
From 5529465023ff79b998cc7ebc248db4eaa3953cc1 Mon Sep 17 00:00:00 2001
From: Mark Reinhold
Date: Fri, 29 Feb 2008 20:03:57 -0800
Subject: [PATCH 008/126] 6669216: Add jcheck configuration directories
Reviewed-by: ohair, xdono
---
corba/.jcheck/conf | 1 +
1 file changed, 1 insertion(+)
create mode 100644 corba/.jcheck/conf
diff --git a/corba/.jcheck/conf b/corba/.jcheck/conf
new file mode 100644
index 00000000000..d8227cd90e3
--- /dev/null
+++ b/corba/.jcheck/conf
@@ -0,0 +1 @@
+project=jdk7
From 1559ee2a70904af7e487f9bbfece5ff8c41737d4 Mon Sep 17 00:00:00 2001
From: Mark Reinhold
Date: Fri, 29 Feb 2008 20:03:58 -0800
Subject: [PATCH 009/126] 6669216: Add jcheck configuration directories
Reviewed-by: ohair, xdono
---
hotspot/.jcheck/conf | 1 +
1 file changed, 1 insertion(+)
create mode 100644 hotspot/.jcheck/conf
diff --git a/hotspot/.jcheck/conf b/hotspot/.jcheck/conf
new file mode 100644
index 00000000000..d8227cd90e3
--- /dev/null
+++ b/hotspot/.jcheck/conf
@@ -0,0 +1 @@
+project=jdk7
From c5ef8d3eaf301ae73e33cfc9080904b3f5cd2c5f Mon Sep 17 00:00:00 2001
From: Mark Reinhold
Date: Fri, 29 Feb 2008 20:03:59 -0800
Subject: [PATCH 010/126] 6669216: Add jcheck configuration directories
Reviewed-by: ohair, xdono
---
jaxp/.jcheck/conf | 1 +
1 file changed, 1 insertion(+)
create mode 100644 jaxp/.jcheck/conf
diff --git a/jaxp/.jcheck/conf b/jaxp/.jcheck/conf
new file mode 100644
index 00000000000..d8227cd90e3
--- /dev/null
+++ b/jaxp/.jcheck/conf
@@ -0,0 +1 @@
+project=jdk7
From f7a57b1ea2cf7cb235282ea20d8a1193f4192361 Mon Sep 17 00:00:00 2001
From: Mark Reinhold
Date: Fri, 29 Feb 2008 20:03:59 -0800
Subject: [PATCH 011/126] 6669216: Add jcheck configuration directories
Reviewed-by: ohair, xdono
---
jaxws/.jcheck/conf | 1 +
1 file changed, 1 insertion(+)
create mode 100644 jaxws/.jcheck/conf
diff --git a/jaxws/.jcheck/conf b/jaxws/.jcheck/conf
new file mode 100644
index 00000000000..d8227cd90e3
--- /dev/null
+++ b/jaxws/.jcheck/conf
@@ -0,0 +1 @@
+project=jdk7
From 1fd0bb237006dac486dc5748da91a17528d189c0 Mon Sep 17 00:00:00 2001
From: Mark Reinhold
Date: Fri, 29 Feb 2008 20:04:01 -0800
Subject: [PATCH 012/126] 6669216: Add jcheck configuration directories
Reviewed-by: ohair, xdono
---
jdk/.jcheck/conf | 1 +
1 file changed, 1 insertion(+)
create mode 100644 jdk/.jcheck/conf
diff --git a/jdk/.jcheck/conf b/jdk/.jcheck/conf
new file mode 100644
index 00000000000..d8227cd90e3
--- /dev/null
+++ b/jdk/.jcheck/conf
@@ -0,0 +1 @@
+project=jdk7
From 104cc8635953e92ea90fa9eeabd8b28ace693a7e Mon Sep 17 00:00:00 2001
From: Eamonn McManus
Date: Mon, 3 Mar 2008 10:32:38 +0100
Subject: [PATCH 013/126] 6602310: Extensions to Query API for JMX 2.0 6604768:
IN queries require their arguments to be constants
New JMX query language and support for dotted attributes in queries.
Reviewed-by: dfuchs
---
.../com/sun/jmx/mbeanserver/Introspector.java | 36 +
.../classes/javax/management/AndQueryExp.java | 23 +-
.../javax/management/AttributeValueExp.java | 87 +-
.../javax/management/BetweenQueryExp.java | 33 +-
.../javax/management/BinaryOpValueExp.java | 70 +-
.../javax/management/BinaryRelQueryExp.java | 29 +-
.../javax/management/BooleanValueExp.java | 6 +
.../classes/javax/management/InQueryExp.java | 14 +-
.../javax/management/MatchQueryExp.java | 27 +-
.../classes/javax/management/NotQueryExp.java | 6 +
.../javax/management/NumericValueExp.java | 17 +-
.../classes/javax/management/ObjectName.java | 9 +-
.../classes/javax/management/OrQueryExp.java | 22 +-
.../QualifiedAttributeValueExp.java | 15 +-
.../share/classes/javax/management/Query.java | 412 +++++++++-
.../classes/javax/management/QueryEval.java | 2 +-
.../classes/javax/management/QueryExp.java | 7 +-
.../classes/javax/management/QueryParser.java | 663 +++++++++++++++
.../javax/management/StringValueExp.java | 2 +-
.../javax/management/ToQueryString.java | 38 +
.../javax/management/monitor/Monitor.java | 41 +-
.../management/query/QueryDottedAttrTest.java | 192 +++++
.../management/query/QueryExpStringTest.java | 108 ++-
.../management/query/QueryParseTest.java | 778 ++++++++++++++++++
24 files changed, 2488 insertions(+), 149 deletions(-)
create mode 100644 jdk/src/share/classes/javax/management/QueryParser.java
create mode 100644 jdk/src/share/classes/javax/management/ToQueryString.java
create mode 100644 jdk/test/javax/management/query/QueryDottedAttrTest.java
create mode 100644 jdk/test/javax/management/query/QueryParseTest.java
diff --git a/jdk/src/share/classes/com/sun/jmx/mbeanserver/Introspector.java b/jdk/src/share/classes/com/sun/jmx/mbeanserver/Introspector.java
index b68fd28ffa7..2a72f3d222f 100644
--- a/jdk/src/share/classes/com/sun/jmx/mbeanserver/Introspector.java
+++ b/jdk/src/share/classes/com/sun/jmx/mbeanserver/Introspector.java
@@ -43,6 +43,13 @@ import javax.management.MBeanInfo;
import javax.management.NotCompliantMBeanException;
import com.sun.jmx.mbeanserver.Util;
+import com.sun.jmx.remote.util.EnvHelp;
+import java.beans.BeanInfo;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import javax.management.AttributeNotFoundException;
+import javax.management.openmbean.CompositeData;
/**
* This class contains the methods for performing all the tests needed to verify
@@ -482,4 +489,33 @@ public class Introspector {
return null;
}
+
+ public static Object elementFromComplex(Object complex, String element)
+ throws AttributeNotFoundException {
+ try {
+ if (complex.getClass().isArray() && element.equals("length")) {
+ return Array.getLength(complex);
+ } else if (complex instanceof CompositeData) {
+ return ((CompositeData) complex).get(element);
+ } else {
+ // Java Beans introspection
+ //
+ BeanInfo bi = java.beans.Introspector.getBeanInfo(complex.getClass());
+ PropertyDescriptor[] pds = bi.getPropertyDescriptors();
+ for (PropertyDescriptor pd : pds)
+ if (pd.getName().equals(element))
+ return pd.getReadMethod().invoke(complex);
+ throw new AttributeNotFoundException(
+ "Could not find the getter method for the property " +
+ element + " using the Java Beans introspector");
+ }
+ } catch (InvocationTargetException e) {
+ throw new IllegalArgumentException(e);
+ } catch (AttributeNotFoundException e) {
+ throw e;
+ } catch (Exception e) {
+ throw EnvHelp.initCause(
+ new AttributeNotFoundException(e.getMessage()), e);
+ }
+ }
}
diff --git a/jdk/src/share/classes/javax/management/AndQueryExp.java b/jdk/src/share/classes/javax/management/AndQueryExp.java
index 6f61f503f1e..9571c06779e 100644
--- a/jdk/src/share/classes/javax/management/AndQueryExp.java
+++ b/jdk/src/share/classes/javax/management/AndQueryExp.java
@@ -104,4 +104,25 @@ class AndQueryExp extends QueryEval implements QueryExp {
return "(" + exp1 + ") and (" + exp2 + ")";
}
- }
+ @Override
+ String toQueryString() {
+ // Parentheses are only added if needed to disambiguate.
+ return parens(exp1) + " and " + parens(exp2);
+ }
+
+ // Add parens if needed to disambiguate an expression such as
+ // Query.and(Query.or(a, b), c). We need to return
+ // (a or b) and c
+ // in such a case, because
+ // a or b and c
+ // would mean
+ // a or (b and c)
+ private static String parens(QueryExp exp) {
+ String s = Query.toString(exp);
+ if (exp instanceof OrQueryExp)
+ return "(" + s + ")";
+ else
+ return s;
+ }
+
+}
diff --git a/jdk/src/share/classes/javax/management/AttributeValueExp.java b/jdk/src/share/classes/javax/management/AttributeValueExp.java
index f520bbaf06c..d986aba7218 100644
--- a/jdk/src/share/classes/javax/management/AttributeValueExp.java
+++ b/jdk/src/share/classes/javax/management/AttributeValueExp.java
@@ -26,12 +26,17 @@
package javax.management;
-// RI import
-import javax.management.MBeanServer;
+import com.sun.jmx.mbeanserver.Introspector;
+import java.io.IOException;
+import java.io.ObjectInputStream;
/**
- * Represents attributes used as arguments to relational constraints.
- * An AttributeValueExp may be used anywhere a ValueExp is required.
+ * Represents attributes used as arguments to relational constraints.
+ * Instances of this class are usually obtained using {@link Query#attr(String)
+ * Query.attr}.
+ *
+ * An AttributeValueExp may be used anywhere a
+ * ValueExp is required.
*
* @since 1.5
*/
@@ -46,6 +51,8 @@ public class AttributeValueExp implements ValueExp {
*/
private String attr;
+ private transient int dotIndex;
+
/**
* An AttributeValueExp with a null attribute.
* @deprecated An instance created with this constructor cannot be
@@ -64,6 +71,18 @@ public class AttributeValueExp implements ValueExp {
*/
public AttributeValueExp(String attr) {
this.attr = attr;
+ setDotIndex();
+ }
+
+ private void setDotIndex() {
+ if (attr != null)
+ dotIndex = attr.indexOf('.');
+ }
+
+ private void readObject(ObjectInputStream in)
+ throws ClassNotFoundException, IOException {
+ in.defaultReadObject();
+ setDotIndex();
}
/**
@@ -76,7 +95,13 @@ public class AttributeValueExp implements ValueExp {
}
/**
- * Applies the AttributeValueExp on an MBean.
+ *
Applies the AttributeValueExp on an MBean.
+ * This method calls {@link #getAttribute getAttribute(name)} and wraps
+ * the result as a {@code ValueExp}. The value returned by
+ * {@code getAttribute} must be a {@code Number}, {@code String},
+ * or {@code Boolean}; otherwise this method throws a
+ * {@code BadAttributeValueExpException}, which will cause
+ * the containing query to be false for this {@code name}.
*
* @param name The name of the MBean on which the AttributeValueExp will be applied.
*
@@ -88,6 +113,7 @@ public class AttributeValueExp implements ValueExp {
* @exception BadBinaryOpValueExpException
*
*/
+ @Override
public ValueExp apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException,
BadAttributeValueExpException, InvalidApplicationException {
Object result = getAttribute(name);
@@ -106,8 +132,9 @@ public class AttributeValueExp implements ValueExp {
/**
* Returns the string representing its value.
*/
+ @Override
public String toString() {
- return attr;
+ return QueryParser.quoteId(attr);
}
@@ -115,18 +142,38 @@ public class AttributeValueExp implements ValueExp {
* Sets the MBean server on which the query is to be performed.
*
* @param s The MBean server on which the query is to be performed.
+ *
+ * @deprecated This method has no effect. The MBean Server used to
+ * obtain an attribute value is {@link QueryEval#getMBeanServer()}.
*/
/* There is no need for this method, because if a query is being
evaluted an AttributeValueExp can only appear inside a QueryExp,
and that QueryExp will itself have done setMBeanServer. */
+ @Deprecated
+ @Override
public void setMBeanServer(MBeanServer s) {
}
/**
- * Return the value of the given attribute in the named MBean.
+ * Return the value of the given attribute in the named MBean.
* If the attempt to access the attribute generates an exception,
- * return null.
+ * return null.
+ *
+ * Let n be the {@linkplain #getAttributeName attribute
+ * name}. Then this method proceeds as follows. First it calls
+ * {@link MBeanServer#getAttribute getAttribute(name, n)}. If that
+ * generates an {@link AttributeNotFoundException}, and if n
+ * contains at least one dot ({@code .}), then the method calls {@code
+ * getAttribute(name, }n{@code .substring(0, }n{@code
+ * .indexOf('.')))}; in other words it calls {@code getAttribute}
+ * with the substring of n before the first dot. Then it
+ * extracts a component from the retrieved value, as described in the documentation for the {@code
+ * monitor} package.
+ *
+ * The MBean Server used is the one returned by {@link
+ * QueryEval#getMBeanServer()}.
*
* @param name the name of the MBean whose attribute is to be returned.
*
@@ -139,10 +186,34 @@ public class AttributeValueExp implements ValueExp {
MBeanServer server = QueryEval.getMBeanServer();
+ try {
return server.getAttribute(name, attr);
+ } catch (AttributeNotFoundException e) {
+ if (dotIndex < 0)
+ throw e;
+ }
+
+ String toGet = attr.substring(0, dotIndex);
+
+ Object value = server.getAttribute(name, toGet);
+
+ return extractElement(value, attr.substring(dotIndex + 1));
} catch (Exception re) {
return null;
}
}
+ private Object extractElement(Object value, String elementWithDots)
+ throws AttributeNotFoundException {
+ while (true) {
+ int dot = elementWithDots.indexOf('.');
+ String element = (dot < 0) ?
+ elementWithDots : elementWithDots.substring(0, dot);
+ value = Introspector.elementFromComplex(value, element);
+ if (dot < 0)
+ return value;
+ elementWithDots = elementWithDots.substring(dot + 1);
+ }
+ }
+
}
diff --git a/jdk/src/share/classes/javax/management/BetweenQueryExp.java b/jdk/src/share/classes/javax/management/BetweenQueryExp.java
index 247c6b4bab7..4079f637961 100644
--- a/jdk/src/share/classes/javax/management/BetweenQueryExp.java
+++ b/jdk/src/share/classes/javax/management/BetweenQueryExp.java
@@ -109,34 +109,25 @@ class BetweenQueryExp extends QueryEval implements QueryExp {
ValueExp val1 = exp1.apply(name);
ValueExp val2 = exp2.apply(name);
ValueExp val3 = exp3.apply(name);
- String sval1;
- String sval2;
- String sval3;
- double dval1;
- double dval2;
- double dval3;
- long lval1;
- long lval2;
- long lval3;
boolean numeric = val1 instanceof NumericValueExp;
if (numeric) {
if (((NumericValueExp)val1).isLong()) {
- lval1 = ((NumericValueExp)val1).longValue();
- lval2 = ((NumericValueExp)val2).longValue();
- lval3 = ((NumericValueExp)val3).longValue();
+ long lval1 = ((NumericValueExp)val1).longValue();
+ long lval2 = ((NumericValueExp)val2).longValue();
+ long lval3 = ((NumericValueExp)val3).longValue();
return lval2 <= lval1 && lval1 <= lval3;
} else {
- dval1 = ((NumericValueExp)val1).doubleValue();
- dval2 = ((NumericValueExp)val2).doubleValue();
- dval3 = ((NumericValueExp)val3).doubleValue();
+ double dval1 = ((NumericValueExp)val1).doubleValue();
+ double dval2 = ((NumericValueExp)val2).doubleValue();
+ double dval3 = ((NumericValueExp)val3).doubleValue();
return dval2 <= dval1 && dval1 <= dval3;
}
} else {
- sval1 = ((StringValueExp)val1).toString();
- sval2 = ((StringValueExp)val2).toString();
- sval3 = ((StringValueExp)val3).toString();
+ String sval1 = ((StringValueExp)val1).getValue();
+ String sval2 = ((StringValueExp)val2).getValue();
+ String sval3 = ((StringValueExp)val3).getValue();
return sval2.compareTo(sval1) <= 0 && sval1.compareTo(sval3) <= 0;
}
}
@@ -148,4 +139,8 @@ class BetweenQueryExp extends QueryEval implements QueryExp {
return "(" + exp1 + ") between (" + exp2 + ") and (" + exp3 + ")";
}
- }
+ @Override
+ String toQueryString() {
+ return exp1 + " between " + exp2 + " and " + exp3;
+ }
+}
diff --git a/jdk/src/share/classes/javax/management/BinaryOpValueExp.java b/jdk/src/share/classes/javax/management/BinaryOpValueExp.java
index 536f1f61566..138258b9d2a 100644
--- a/jdk/src/share/classes/javax/management/BinaryOpValueExp.java
+++ b/jdk/src/share/classes/javax/management/BinaryOpValueExp.java
@@ -167,12 +167,74 @@ class BinaryOpValueExp extends QueryEval implements ValueExp {
*/
public String toString() {
try {
- return exp1 + " " + opString() + " " + exp2;
+ return parens(exp1, true) + " " + opString() + " " + parens(exp2, false);
} catch (BadBinaryOpValueExpException ex) {
return "invalid expression";
}
}
+ /*
+ * Add parentheses to the given subexpression if necessary to
+ * preserve meaning. Suppose this BinaryOpValueExp is
+ * Query.times(Query.plus(Query.attr("A"), Query.attr("B")), Query.attr("C")).
+ * Then the original toString() logic would return A + B * C.
+ * We check precedences in order to return (A + B) * C, which is the
+ * meaning of the ValueExp.
+ *
+ * We need to add parentheses if the unparenthesized expression would
+ * be parsed as a different ValueExp from the original.
+ * We cannot omit parentheses even when mathematically
+ * the result would be equivalent, because we do not know whether the
+ * numeric values will be integer or floating-point. Addition and
+ * multiplication are associative for integers but not always for
+ * floating-point.
+ *
+ * So the rule is that we omit parentheses if the ValueExp
+ * is (A op1 B) op2 C and the precedence of op1 is greater than or
+ * equal to that of op2; or if the ValueExp is A op1 (B op2 C) and
+ * the precedence of op2 is greater than that of op1. (There are two
+ * precedences: that of * and / is greater than that of + and -.)
+ * The case of (A op1 B) op2 (C op3 D) applies each rule in turn.
+ *
+ * The following examples show the rules in action. On the left,
+ * the original ValueExp. On the right, the string representation.
+ *
+ * (A + B) + C A + B + C
+ * (A * B) + C A * B + C
+ * (A + B) * C (A + B) * C
+ * (A * B) * C A * B * C
+ * A + (B + C) A + (B + C)
+ * A + (B * C) A + B * C
+ * A * (B + C) A * (B + C)
+ * A * (B * C) A * (B * C)
+ */
+ private String parens(ValueExp subexp, boolean left)
+ throws BadBinaryOpValueExpException {
+ boolean omit;
+ if (subexp instanceof BinaryOpValueExp) {
+ int subop = ((BinaryOpValueExp) subexp).op;
+ if (left)
+ omit = (precedence(subop) >= precedence(op));
+ else
+ omit = (precedence(subop) > precedence(op));
+ } else
+ omit = true;
+
+ if (omit)
+ return subexp.toString();
+ else
+ return "(" + subexp + ")";
+ }
+
+ private int precedence(int xop) throws BadBinaryOpValueExpException {
+ switch (xop) {
+ case Query.PLUS: case Query.MINUS: return 0;
+ case Query.TIMES: case Query.DIV: return 1;
+ default:
+ throw new BadBinaryOpValueExpException(this);
+ }
+ }
+
private String opString() throws BadBinaryOpValueExpException {
switch (op) {
case Query.PLUS:
@@ -188,4 +250,10 @@ class BinaryOpValueExp extends QueryEval implements ValueExp {
throw new BadBinaryOpValueExpException(this);
}
+ @Deprecated
+ public void setMBeanServer(MBeanServer s) {
+ super.setMBeanServer(s);
+ }
+
+
}
diff --git a/jdk/src/share/classes/javax/management/BinaryRelQueryExp.java b/jdk/src/share/classes/javax/management/BinaryRelQueryExp.java
index 47809f35d9d..2e740aee2bd 100644
--- a/jdk/src/share/classes/javax/management/BinaryRelQueryExp.java
+++ b/jdk/src/share/classes/javax/management/BinaryRelQueryExp.java
@@ -108,20 +108,12 @@ class BinaryRelQueryExp extends QueryEval implements QueryExp {
BadAttributeValueExpException, InvalidApplicationException {
Object val1 = exp1.apply(name);
Object val2 = exp2.apply(name);
- String sval1;
- String sval2;
- double dval1;
- double dval2;
- long lval1;
- long lval2;
- boolean bval1;
- boolean bval2;
boolean numeric = val1 instanceof NumericValueExp;
boolean bool = val1 instanceof BooleanValueExp;
if (numeric) {
if (((NumericValueExp)val1).isLong()) {
- lval1 = ((NumericValueExp)val1).longValue();
- lval2 = ((NumericValueExp)val2).longValue();
+ long lval1 = ((NumericValueExp)val1).longValue();
+ long lval2 = ((NumericValueExp)val2).longValue();
switch (relOp) {
case Query.GT:
@@ -136,8 +128,8 @@ class BinaryRelQueryExp extends QueryEval implements QueryExp {
return lval1 == lval2;
}
} else {
- dval1 = ((NumericValueExp)val1).doubleValue();
- dval2 = ((NumericValueExp)val2).doubleValue();
+ double dval1 = ((NumericValueExp)val1).doubleValue();
+ double dval2 = ((NumericValueExp)val2).doubleValue();
switch (relOp) {
case Query.GT:
@@ -155,8 +147,8 @@ class BinaryRelQueryExp extends QueryEval implements QueryExp {
} else if (bool) {
- bval1 = ((BooleanValueExp)val1).getValue().booleanValue();
- bval2 = ((BooleanValueExp)val2).getValue().booleanValue();
+ boolean bval1 = ((BooleanValueExp)val1).getValue().booleanValue();
+ boolean bval2 = ((BooleanValueExp)val2).getValue().booleanValue();
switch (relOp) {
case Query.GT:
@@ -172,8 +164,8 @@ class BinaryRelQueryExp extends QueryEval implements QueryExp {
}
} else {
- sval1 = ((StringValueExp)val1).getValue();
- sval2 = ((StringValueExp)val2).getValue();
+ String sval1 = ((StringValueExp)val1).getValue();
+ String sval2 = ((StringValueExp)val2).getValue();
switch (relOp) {
case Query.GT:
@@ -199,6 +191,11 @@ class BinaryRelQueryExp extends QueryEval implements QueryExp {
return "(" + exp1 + ") " + relOpString() + " (" + exp2 + ")";
}
+ @Override
+ String toQueryString() {
+ return exp1 + " " + relOpString() + " " + exp2;
+ }
+
private String relOpString() {
switch (relOp) {
case Query.GT:
diff --git a/jdk/src/share/classes/javax/management/BooleanValueExp.java b/jdk/src/share/classes/javax/management/BooleanValueExp.java
index 6dc569744cf..7a5348fd0ab 100644
--- a/jdk/src/share/classes/javax/management/BooleanValueExp.java
+++ b/jdk/src/share/classes/javax/management/BooleanValueExp.java
@@ -84,4 +84,10 @@ class BooleanValueExp extends QueryEval implements ValueExp {
return this;
}
+ @Deprecated
+ public void setMBeanServer(MBeanServer s) {
+ super.setMBeanServer(s);
+ }
+
+
}
diff --git a/jdk/src/share/classes/javax/management/InQueryExp.java b/jdk/src/share/classes/javax/management/InQueryExp.java
index 01f2c503a1b..103ba3b8633 100644
--- a/jdk/src/share/classes/javax/management/InQueryExp.java
+++ b/jdk/src/share/classes/javax/management/InQueryExp.java
@@ -91,21 +91,23 @@ class InQueryExp extends QueryEval implements QueryExp {
* @exception BadAttributeValueExpException
* @exception InvalidApplicationException
*/
- public boolean apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException,
+ public boolean apply(ObjectName name)
+ throws BadStringOperationException, BadBinaryOpValueExpException,
BadAttributeValueExpException, InvalidApplicationException {
if (valueList != null) {
ValueExp v = val.apply(name);
boolean numeric = v instanceof NumericValueExp;
- for (int i = 0; i < valueList.length; i++) {
+ for (ValueExp element : valueList) {
+ element = element.apply(name);
if (numeric) {
- if (((NumericValueExp)valueList[i]).doubleValue() ==
- ((NumericValueExp)v).doubleValue()) {
+ if (((NumericValueExp) element).doubleValue() ==
+ ((NumericValueExp) v).doubleValue()) {
return true;
}
} else {
- if (((StringValueExp)valueList[i]).getValue().equals(
- ((StringValueExp)v).getValue())) {
+ if (((StringValueExp) element).getValue().equals(
+ ((StringValueExp) v).getValue())) {
return true;
}
}
diff --git a/jdk/src/share/classes/javax/management/MatchQueryExp.java b/jdk/src/share/classes/javax/management/MatchQueryExp.java
index 12e42769ffd..779fac1989f 100644
--- a/jdk/src/share/classes/javax/management/MatchQueryExp.java
+++ b/jdk/src/share/classes/javax/management/MatchQueryExp.java
@@ -113,7 +113,32 @@ class MatchQueryExp extends QueryEval implements QueryExp {
}
private static String likeTranslate(String s) {
- return s.replace('?', '_').replace('*', '%');
+ StringBuilder sb = new StringBuilder();
+ int c;
+ for (int i = 0; i < s.length(); i += Character.charCount(c)) {
+ c = s.codePointAt(i);
+ switch (c) {
+ case '\\':
+ i += Character.charCount(c);
+ sb.append('\\');
+ if (i < s.length()) {
+ c = s.codePointAt(i);
+ sb.appendCodePoint(c);
+ }
+ break;
+ case '*':
+ sb.append('%'); break;
+ case '?':
+ sb.append('_'); break;
+ case '%':
+ sb.append("\\%"); break;
+ case '_':
+ sb.append("\\_"); break;
+ default:
+ sb.appendCodePoint(c); break;
+ }
+ }
+ return sb.toString();
}
/*
diff --git a/jdk/src/share/classes/javax/management/NotQueryExp.java b/jdk/src/share/classes/javax/management/NotQueryExp.java
index a099152012a..ef2dc57b797 100644
--- a/jdk/src/share/classes/javax/management/NotQueryExp.java
+++ b/jdk/src/share/classes/javax/management/NotQueryExp.java
@@ -86,8 +86,14 @@ class NotQueryExp extends QueryEval implements QueryExp {
/**
* Returns the string representing the object.
*/
+ @Override
public String toString() {
return "not (" + exp + ")";
}
+ @Override
+ String toQueryString() {
+ return "not (" + Query.toString(exp) + ")";
+ }
+
}
diff --git a/jdk/src/share/classes/javax/management/NumericValueExp.java b/jdk/src/share/classes/javax/management/NumericValueExp.java
index bd8da33eaab..c823a93deb4 100644
--- a/jdk/src/share/classes/javax/management/NumericValueExp.java
+++ b/jdk/src/share/classes/javax/management/NumericValueExp.java
@@ -151,11 +151,18 @@ class NumericValueExp extends QueryEval implements ValueExp {
* Returns the string representing the object
*/
public String toString() {
+ if (val == null)
+ return "null";
if (val instanceof Long || val instanceof Integer)
{
- return String.valueOf(val.longValue());
+ return Long.toString(val.longValue());
}
- return String.valueOf(val.doubleValue());
+ double d = val.doubleValue();
+ if (Double.isInfinite(d))
+ return (d > 0) ? "(1.0 / 0.0)" : "(-1.0 / 0.0)";
+ if (Double.isNaN(d))
+ return "(0.0 / 0.0)";
+ return Double.toString(d);
}
/**
@@ -244,4 +251,10 @@ class NumericValueExp extends QueryEval implements ValueExp {
out.defaultWriteObject();
}
}
+
+ @Deprecated
+ public void setMBeanServer(MBeanServer s) {
+ super.setMBeanServer(s);
+ }
+
}
diff --git a/jdk/src/share/classes/javax/management/ObjectName.java b/jdk/src/share/classes/javax/management/ObjectName.java
index 8721bb62d18..cef869510b1 100644
--- a/jdk/src/share/classes/javax/management/ObjectName.java
+++ b/jdk/src/share/classes/javax/management/ObjectName.java
@@ -222,7 +222,8 @@ import javax.management.QueryExp;
* @since 1.5
*/
@SuppressWarnings("serial") // don't complain serialVersionUID not constant
-public class ObjectName implements Comparable, QueryExp {
+public class ObjectName extends ToQueryString
+ implements Comparable, QueryExp {
/**
* A structure recording property structure and
@@ -1779,10 +1780,16 @@ public class ObjectName implements Comparable, QueryExp {
*
* @return a string representation of this object name.
*/
+ @Override
public String toString() {
return getSerializedNameString();
}
+ @Override
+ String toQueryString() {
+ return "LIKE " + Query.value(toString());
+ }
+
/**
* Compares the current object name with another object name. Two
* ObjectName instances are equal if and only if their canonical
diff --git a/jdk/src/share/classes/javax/management/OrQueryExp.java b/jdk/src/share/classes/javax/management/OrQueryExp.java
index 772a32385ae..e1ca5122f28 100644
--- a/jdk/src/share/classes/javax/management/OrQueryExp.java
+++ b/jdk/src/share/classes/javax/management/OrQueryExp.java
@@ -98,9 +98,29 @@ class OrQueryExp extends QueryEval implements QueryExp {
}
/**
- * Returns a string representation of this AndQueryExp
+ * Returns a string representation of this OrQueryExp
*/
public String toString() {
return "(" + exp1 + ") or (" + exp2 + ")";
}
+
+ @Override
+ String toQueryString() {
+ return parens(exp1) + " or " + parens(exp2);
+ }
+
+ // Add parentheses to avoid possible confusion. If we have an expression
+ // such as Query.or(Query.and(a, b), c), then we return
+ // (a and b) or c
+ // rather than just
+ // a and b or c
+ // In fact the precedence rules are such that the parentheses are not
+ // strictly necessary, but omitting them would be confusing.
+ private static String parens(QueryExp exp) {
+ String s = Query.toString(exp);
+ if (exp instanceof AndQueryExp)
+ return "(" + s + ")";
+ else
+ return s;
+ }
}
diff --git a/jdk/src/share/classes/javax/management/QualifiedAttributeValueExp.java b/jdk/src/share/classes/javax/management/QualifiedAttributeValueExp.java
index fe7ce41a012..3934d27084f 100644
--- a/jdk/src/share/classes/javax/management/QualifiedAttributeValueExp.java
+++ b/jdk/src/share/classes/javax/management/QualifiedAttributeValueExp.java
@@ -27,9 +27,11 @@ package javax.management;
/**
- * This class represents indexed attributes used as arguments to relational
- * constraints. An QualifiedAttributeValueExp may be used anywhere a
- * ValueExp is required.
+ * Represents attributes used as arguments to relational constraints,
+ * where the attribute must be in an MBean of a specified {@linkplain
+ * MBeanInfo#getClassName() class}. A QualifiedAttributeValueExp may be used
+ * anywhere a ValueExp is required.
+ *
* @serial include
*
* @since 1.5
@@ -48,7 +50,9 @@ class QualifiedAttributeValueExp extends AttributeValueExp {
/**
* Basic Constructor.
+ * @deprecated see {@link AttributeValueExp#AttributeValueExp()}
*/
+ @Deprecated
public QualifiedAttributeValueExp() {
}
@@ -81,6 +85,7 @@ class QualifiedAttributeValueExp extends AttributeValueExp {
* @exception BadAttributeValueExpException
* @exception InvalidApplicationException
*/
+ @Override
public ValueExp apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException,
BadAttributeValueExpException, InvalidApplicationException {
try {
@@ -105,9 +110,11 @@ class QualifiedAttributeValueExp extends AttributeValueExp {
/**
* Returns the string representing its value
*/
+ @Override
public String toString() {
if (className != null) {
- return className + "." + super.toString();
+ return QueryParser.quoteId(className) + "#" +
+ QueryParser.quoteId(super.toString());
} else {
return super.toString();
}
diff --git a/jdk/src/share/classes/javax/management/Query.java b/jdk/src/share/classes/javax/management/Query.java
index 84a71da510b..d3b461da75d 100644
--- a/jdk/src/share/classes/javax/management/Query.java
+++ b/jdk/src/share/classes/javax/management/Query.java
@@ -27,19 +27,346 @@ package javax.management;
/**
- *
Constructs query object constraints. The static methods provided
- * return query expressions that may be used in listing and
- * enumerating MBeans. Individual constraint construction methods
- * allow only appropriate types as arguments. Composition of calls can
- * construct arbitrary nestings of constraints, as the following
- * example illustrates:
+ * Constructs query object constraints.
+ *
+ * The MBean Server can be queried for MBeans that meet a particular
+ * condition, using its {@link MBeanServer#queryNames queryNames} or
+ * {@link MBeanServer#queryMBeans queryMBeans} method. The {@link QueryExp}
+ * parameter to the method can be any implementation of the interface
+ * {@code QueryExp}, but it is usually best to obtain the {@code QueryExp}
+ * value by calling the static methods in this class. This is particularly
+ * true when querying a remote MBean Server: a custom implementation of the
+ * {@code QueryExp} interface might not be present in the remote MBean Server,
+ * but the methods in this class return only standard classes that are
+ * part of the JMX implementation.
+ *
+ * There are two ways to create {@code QueryExp} objects using the methods
+ * in this class. The first is to build them by chaining together calls to
+ * the various methods. The second is to use the Query Language described
+ * below and produce the {@code QueryExp} by calling
+ * {@link #fromString Query.fromString}. The two ways are equivalent:
+ * every {@code QueryExp} returned by {@code fromString} can also be
+ * constructed by chaining method calls.
+ *
+ * As an example, suppose you wanted to find all MBeans where the {@code
+ * Enabled} attribute is {@code true} and the {@code Owner} attribute is {@code
+ * "Duke"}. Here is how you could construct the appropriate {@code QueryExp} by
+ * chaining together method calls:
*
*
- * QueryExp exp = Query.and(Query.gt(Query.attr("age"),Query.value(5)),
- * Query.match(Query.attr("name"),
- * Query.value("Smith")));
+ * QueryExp query =
+ * Query.and(Query.eq(Query.attr("Enabled"), Query.value(true)),
+ * Query.eq(Query.attr("Owner"), Query.value("Duke")));
*
*
+ * Here is how you could construct the same {@code QueryExp} using the
+ * Query Language:
+ *
+ *
+ * QueryExp query = Query.fromString("Enabled = true and Owner = 'Duke'");
+ *
+ *
+ * The principal advantage of the method-chaining approach is that the
+ * compiler will check that the query makes sense. The principal advantage
+ * of the Query Language approach is that it is easier to write and especially
+ * read.
+ *
+ *
+ * Query Language
+ *
+ * The query language is closely modeled on the WHERE clause of
+ * SQL SELECT statements. The formal specification of the language
+ * appears below, but it is probably easier to
+ * understand it with examples such as the following.
+ *
+ *
+ * - {@code Message = 'OK'}
+ *
- Selects MBeans that have a {@code Message} attribute whose value
+ * is the string {@code OK}.
+ *
+ *
- {@code FreeSpacePercent < 10}
+ *
- Selects MBeans that have a {@code FreeSpacePercent} attribute whose
+ * value is a number less than 10.
+ *
+ *
- {@code FreeSpacePercent < 10 and WarningSent = false}
+ *
- Selects the same MBeans as the previous example, but they must
+ * also have a boolean attribute {@code WarningSent} whose value
+ * is false.
+ *
+ *
- {@code SpaceUsed > TotalSpace * (2.0 / 3.0)}
+ *
- Selects MBeans that have {@code SpaceUsed} and {@code TotalSpace}
+ * attributes where the first is more than two-thirds the second.
+ *
+ *
- {@code not (FreeSpacePercent between 10 and 90)}
+ *
- Selects MBeans that have a {@code FreeSpacePercent} attribute whose
+ * value is not between 10 and 90, inclusive.
+ *
+ *
- {@code FreeSpacePercent not between 10 and 90}
+ *
- Another way of writing the previous query.
+ *
+ *
- {@code Status in ('STOPPED', 'STARTING', 'STARTED')}
+ *
- Selects MBeans that have a {@code Status} attribute whose value
+ * is one of those three strings.
+ *
+ *
- {@code Message like 'OK: %'}
+ *
- Selects MBeans that have a {@code Message} attribute whose value
+ * is a string beginning with {@code "OK: "}. Notice that the
+ * wildcard characters are SQL's ones. In the query language,
+ * {@code %} means "any sequence of characters" and {@code _}
+ * means "any single character". In the rest of the JMX API, these
+ * correspond to {@code *} and {@code %} respectively.
+ *
+ *
- {@code instanceof 'javax.management.NotificationBroadcaster'}
+ *
- Selects MBeans that are instances of
+ * {@link javax.management.NotificationBroadcaster}, as reported by
+ * {@link javax.management.MBeanServer#isInstanceOf MBeanServer.isInstanceOf}.
+ *
+ *
- {@code like 'mydomain:*'}
+ *
- Selects MBeans whose {@link ObjectName}s have the domain {@code mydomain}.
+ *
+ *
+ *
+ * The last two examples do not correspond to valid SQL syntax, but all
+ * the others do.
+ *
+ * The remainder of this description is a formal specification of the
+ * query language.
+ *
+ *
+ *
+ *
+ * Keywords such as and, like, and between are not
+ * case sensitive. You can write between, BETWEEN, or
+ * BeTwEeN with the same effect.
+ *
+ * On the other hand, attribute names are case sensitive. The
+ * attribute {@code Name} is not the same as the attribute {@code name}.
+ *
+ * To access an attribute whose name, ignoring case, is the same as one of
+ * the keywords {@code not}, {@code instanceof}, {@code like}, {@code true},
+ * or {@code false}, you can use double quotes, for example {@code "not"}.
+ * Double quotes can also be used to include non-identifier characters in
+ * the name of an attribute, for example {@code "attribute-name-with-hyphens"}.
+ * To include the double quote character in the attribute name, write it
+ * twice. {@code "foo""bar""baz"} represents the attribute called
+ * {@code foo"bar"baz}.
+ *
+ *
String constants are written with single quotes like {@code 'this'}. A
+ * single quote within a string constant must be doubled, for example
+ * {@code 'can''t'}.
+ *
+ * Integer constants are written as a sequence of decimal digits,
+ * optionally preceded by a plus or minus sign. An integer constant must be
+ * a valid input to {@link Long#valueOf(String)}.
+ *
+ * Floating-point constants are written using the Java syntax. A
+ * floating-point constant must be a valid input to
+ * {@link Double#valueOf(String)}.
+ *
+ * A boolean constant is either {@code true} or {@code false}, ignoring
+ * case.
+ *
+ * Spaces cannot appear inside identifiers (unless written with double
+ * quotes) or keywords or multi-character tokens such as {@code <=}. Spaces can
+ * appear anywhere else, but are not required except to separate tokens. For
+ * example, the query {@code a < b and 5 = c} could also be written {@code a
+ *
+ *
+ * Grammar
+ *
+ *
+ * - query:
+ *
- andquery [OR query]
+ *
+ *
- andquery:
+ *
- predicate [AND andquery]
+ *
+ *
- predicate:
+ *
- ( query ) |
+ * NOT predicate |
+ * INSTANCEOF stringvalue |
+ * LIKE objectnamepattern |
+ * value predrhs
+ *
+ * - predrhs:
+ *
- compare value |
+ * [NOT] BETWEEN value AND
+ * value |
+ * [NOT] IN ( value
+ * commavalues ) |
+ * [NOT] LIKE stringvalue
+ *
+ * - commavalues:
+ *
- [ , value commavalues ]
+ *
+ *
- compare:
+ *
- = | < | > |
+ * <= | >= | <> | !=
+ *
+ *
- value:
+ *
- factor [plusorminus
+ * value]
+ *
+ *
- plusorminus:
+ *
- + | -
+ *
+ *
- factor:
+ *
- term [timesordivide
+ * factor]
+ *
+ *
- timesordivide:
+ *
- * | /
+ *
+ *
- term:
+ *
- attr | literal |
+ * ( value )
+ *
+ *
- attr:
+ *
- name [# name]
+ *
+ *
- name:
+ *
- identifier [.name]
+ *
+ *
- identifier:
+ *
- Java-identifier | double-quoted-identifier
+ *
+ *
- literal:
+ *
- booleanlit | longlit |
+ * doublelit | stringlit
+ *
+ *
- booleanlit:
+ *
- FALSE | TRUE
+ *
+ *
- stringvalue:
+ *
- stringlit
+ *
+ *
- objectnamepattern:
+ *
- stringlit
+ *
+ *
+ *
+ *
+ * Semantics
+ *
+ *
The meaning of the grammar is described in the table below.
+ * This defines a function q that maps a string to a Java object
+ * such as a {@link QueryExp} or a {@link ValueExp}.
+ *
+ *
+ * | String s | q(s) |
+ *
+ * | query1 OR query2
+ * | {@link Query#or Query.or}(q(query1), q(query2))
+ *
+ * |
| query1 AND query2
+ * | {@link Query#and Query.and}(q(query1), q(query2))
+ *
+ * |
| ( queryOrValue )
+ * | q(queryOrValue)
+ *
+ * |
| NOT query
+ * | {@link Query#not Query.not}(q(query))
+ *
+ * |
| INSTANCEOF stringLiteral
+ * | {@link Query#isInstanceOf Query.isInstanceOf}({@link Query#value(String) Query.value}(q(stringLiteral)))
+ *
+ * |
| LIKE stringLiteral
+ * | {@link ObjectName#ObjectName(String) new ObjectName}(q(stringLiteral))
+ *
+ * |
| value1 = value2
+ * | {@link Query#eq Query.eq}(q(value1), q(value2))
+ *
+ * |
| value1 < value2
+ * | {@link Query#lt Query.lt}(q(value1), q(value2))
+ *
+ * |
| value1 > value2
+ * | {@link Query#gt Query.gt}(q(value1), q(value2))
+ *
+ * |
| value1 <= value2
+ * | {@link Query#leq Query.leq}(q(value1), q(value2))
+ *
+ * |
| value1 >= value2
+ * | {@link Query#geq Query.geq}(q(value1), q(value2))
+ *
+ * |
| value1 <> value2
+ * | {@link Query#not Query.not}({@link Query#eq Query.eq}(q(value1), q(value2)))
+ *
+ * |
| value1 != value2
+ * | {@link Query#not Query.not}({@link Query#eq Query.eq}(q(value1), q(value2)))
+ *
+ * |
| value1 BETWEEN value2 AND value3
+ * | {@link Query#between Query.between}(q(value1),
+ * q(value2), q(value3))
+ *
+ * |
| value1 NOT BETWEEN value2 AND value3
+ * | {@link Query#not Query.not}({@link Query#between Query.between}(q(value1), q(value2), q(value3)))
+ *
+ * |
| value1 IN ( value2, value3 )
+ * | {@link Query#in Query.in}(q(value1),
+ * new ValueExp[] {
+ * q(value2), q(value3)})
+ *
+ * |
| value1 NOT IN ( value2, value3 )
+ * | {@link Query#not Query.not}({@link Query#in Query.in}(q(value1),
+ * new ValueExp[] {
+ * q(value2), q(value3)}))
+ *
+ * |
| value LIKE stringLiteral
+ * | {@link Query#match Query.match}(q(value),
+ * translateWildcards(q(stringLiteral)))
+ *
+ * |
| value NOT LIKE stringLiteral
+ * | {@link Query#not Query.not}({@link Query#match Query.match}(q(value),
+ * translateWildcards(q(stringLiteral))))
+ *
+ * |
| value1 + value2
+ * | {@link Query#plus Query.plus}(q(value1), q(value2))
+ *
+ * |
| value1 - value2
+ * | {@link Query#minus Query.minus}(q(value1), q(value2))
+ *
+ * |
| value1 * value2
+ * | {@link Query#times Query.times}(q(value1), q(value2))
+ *
+ * |
| value1 / value2
+ * | {@link Query#div Query.div}(q(value1), q(value2))
+ *
+ * |
| name
+ * | {@link Query#attr(String) Query.attr}(q(name))
+ *
+ * |
| name1#name2
+ * | {@link Query#attr(String,String) Query.attr}(q(name1),
+ * q(name2))
+ *
+ * |
| FALSE
+ * | {@link Query#value(boolean) Query.value}(false)
+ *
+ * |
| TRUE
+ * | {@link Query#value(boolean) Query.value}(true)
+ *
+ * |
| decimalLiteral
+ * | {@link Query#value(long) Query.value}({@link Long#valueOf(String) Long.valueOf}(decimalLiteral))
+ *
+ * |
| floatingPointLiteral
+ * | {@link Query#value(double) Query.value}({@link Double#valueOf(String) Double.valueOf}(floatingPointLiteral))
+ * |
+ *
+ * Here, translateWildcards is a function
+ * that translates from the SQL notation for wildcards, using {@code %} and
+ * {@code _}, to the JMX API notation, using {@code *} and {@code ?}. If the
+ * LIKE string already contains {@code *} or {@code ?}, these characters
+ * have their literal meanings, and will be quoted in the call to
+ * {@link Query#match Query.match}.
+ *
* @since 1.5
*/
public class Query extends Object {
@@ -277,16 +604,12 @@ package javax.management;
}
/**
- * Returns a new attribute expression.
- *
- * Evaluating this expression for a given
- * objectName includes performing {@link
- * MBeanServer#getAttribute MBeanServer.getAttribute(objectName,
- * name)}.
+ * Returns a new attribute expression. See {@link AttributeValueExp}
+ * for a detailed description of the semantics of the expression.
*
* @param name The name of the attribute.
*
- * @return An attribute expression for the attribute named name.
+ * @return An attribute expression for the attribute named {@code name}.
*/
public static AttributeValueExp attr(String name) {
return new AttributeValueExp(name);
@@ -627,6 +950,63 @@ package javax.management;
return new InstanceOfQueryExp(classNameValue);
}
+ /**
+ * Return a string representation of the given query. The string
+ * returned by this method can be converted back into an equivalent
+ * query using {@link #fromString fromString}.
+ *
+ * (Two queries are equivalent if they produce the same result in
+ * all cases. Equivalent queries are not necessarily identical:
+ * for example the queries {@code Query.lt(Query.attr("A"), Query.attr("B"))}
+ * and {@code Query.not(Query.ge(Query.attr("A"), Query.attr("B")))} are
+ * equivalent but not identical.)
+ *
+ * The string returned by this method is only guaranteed to be converted
+ * back into an equivalent query if {@code query} was constructed, or
+ * could have been constructed, using the methods of this class.
+ * If you make a custom query {@code myQuery} by implementing
+ * {@link QueryExp} yourself then the result of
+ * {@code Query.toString(myQuery)} is unspecified.
+ *
+ * @param query the query to convert. If it is null, the result will
+ * also be null.
+ * @return the string representation of the query, or null if the
+ * query is null.
+ *
+ * @since 1.7
+ */
+ public static String toString(QueryExp query) {
+ if (query == null)
+ return null;
+
+ if (query instanceof ToQueryString)
+ return ((ToQueryString) query).toQueryString();
+
+ return query.toString();
+ }
+
+ /**
+ * Produce a query from the given string. The query returned
+ * by this method can be converted back into a string using
+ * {@link #toString(QueryExp) toString}. The resultant string will
+ * not necessarily be equal to {@code s}.
+ *
+ * @param s the string to convert.
+ *
+ * @return a {@code QueryExp} derived by parsing the string, or
+ * null if the string is null.
+ *
+ * @throws IllegalArgumentException if the string is not a valid
+ * query string.
+ *
+ * @since 1.7
+ */
+ public static QueryExp fromString(String s) {
+ if (s == null)
+ return null;
+ return new QueryParser(s).parseQuery();
+ }
+
/**
* Utility method to escape strings used with
* Query.{initial|any|final}SubString() methods.
diff --git a/jdk/src/share/classes/javax/management/QueryEval.java b/jdk/src/share/classes/javax/management/QueryEval.java
index 05c4e38b4be..02c651c3c4c 100644
--- a/jdk/src/share/classes/javax/management/QueryEval.java
+++ b/jdk/src/share/classes/javax/management/QueryEval.java
@@ -38,7 +38,7 @@ import javax.management.MBeanServer;
*
* @since 1.5
*/
-public abstract class QueryEval implements Serializable {
+public abstract class QueryEval extends ToQueryString implements Serializable {
/* Serial version */
private static final long serialVersionUID = 2675899265640874796L;
diff --git a/jdk/src/share/classes/javax/management/QueryExp.java b/jdk/src/share/classes/javax/management/QueryExp.java
index 6ac9ef6854f..217db104249 100644
--- a/jdk/src/share/classes/javax/management/QueryExp.java
+++ b/jdk/src/share/classes/javax/management/QueryExp.java
@@ -30,9 +30,9 @@ import java.io.Serializable;
/**
- * Represents relational constraints that can be used in database
- * query "where clauses". Instances of QueryExp are returned by the
- * static methods of the {@link Query} class.
+ * Represents relational constraints similar to database query "where
+ * clauses". Instances of QueryExp are returned by the static methods of the
+ * {@link Query} class.
*
* It is possible, but not
* recommended, to create custom queries by implementing this
@@ -40,6 +40,7 @@ import java.io.Serializable;
* QueryEval} class than to implement the interface directly, so that
* the {@link #setMBeanServer} method works correctly.
*
+ * @see MBeanServer#queryNames MBeanServer.queryNames
* @since 1.5
*/
public interface QueryExp extends Serializable {
diff --git a/jdk/src/share/classes/javax/management/QueryParser.java b/jdk/src/share/classes/javax/management/QueryParser.java
new file mode 100644
index 00000000000..5e24e3bfbd3
--- /dev/null
+++ b/jdk/src/share/classes/javax/management/QueryParser.java
@@ -0,0 +1,663 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.management;
+
+import java.util.ArrayList;
+import java.util.Formatter;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ *
Parser for JMX queries represented in an SQL-like language.
+ */
+/*
+ * Note that if a query starts with ( then we don't know whether it is
+ * a predicate or just a value that is parenthesized. So, inefficiently,
+ * we try to parse a predicate and if that doesn't work we try to parse
+ * a value.
+ */
+class QueryParser {
+ // LEXER STARTS HERE
+
+ private static class Token {
+ final String string;
+ Token(String s) {
+ this.string = s;
+ }
+
+ @Override
+ public String toString() {
+ return string;
+ }
+ }
+
+ private static final Token
+ END = new Token(""),
+ LPAR = new Token("("), RPAR = new Token(")"),
+ COMMA = new Token(","), DOT = new Token("."), SHARP = new Token("#"),
+ PLUS = new Token("+"), MINUS = new Token("-"),
+ TIMES = new Token("*"), DIVIDE = new Token("/"),
+ LT = new Token("<"), GT = new Token(">"),
+ LE = new Token("<="), GE = new Token(">="),
+ NE = new Token("<>"), EQ = new Token("="),
+ NOT = new Id("NOT"), INSTANCEOF = new Id("INSTANCEOF"),
+ FALSE = new Id("FALSE"), TRUE = new Id("TRUE"),
+ BETWEEN = new Id("BETWEEN"), AND = new Id("AND"),
+ OR = new Id("OR"), IN = new Id("IN"),
+ LIKE = new Id("LIKE"), CLASS = new Id("CLASS");
+
+ // Keywords that can appear where an identifier can appear.
+ // If an attribute is one of these, then it must be quoted when
+ // converting a query into a string.
+ // We use a TreeSet so we can look up case-insensitively.
+ private static final Set idKeywords =
+ new TreeSet(String.CASE_INSENSITIVE_ORDER);
+ static {
+ for (Token t : new Token[] {NOT, INSTANCEOF, FALSE, TRUE, LIKE, CLASS})
+ idKeywords.add(t.string);
+ };
+
+ public static String quoteId(String id) {
+ if (id.contains("\"") || idKeywords.contains(id))
+ return '"' + id.replace("\"", "\"\"") + '"';
+ else
+ return id;
+ }
+
+ private static class Id extends Token {
+ Id(String id) {
+ super(id);
+ }
+
+ // All other tokens use object identity, which means e.g. that one
+ // occurrence of the string constant 'x' is not the same as another.
+ // For identifiers, we ignore case when testing for equality so that
+ // for a keyword such as AND you can also spell it as "And" or "and".
+ // But we keep the original case of the identifier, so if it's not
+ // a keyword we will distinguish between the attribute Foo and the
+ // attribute FOO.
+ @Override
+ public boolean equals(Object o) {
+ return (o instanceof Id && (((Id) o).toString().equalsIgnoreCase(toString())));
+ }
+ }
+
+ private static class QuotedId extends Token {
+ QuotedId(String id) {
+ super(id);
+ }
+
+ @Override
+ public String toString() {
+ return '"' + string.replace("\"", "\"\"") + '"';
+ }
+ }
+
+ private static class StringLit extends Token {
+ StringLit(String s) {
+ super(s);
+ }
+
+ @Override
+ public String toString() {
+ return '\'' + string.replace("'", "''") + '\'';
+ }
+ }
+
+ private static class LongLit extends Token {
+ long number;
+
+ LongLit(long number) {
+ super(Long.toString(number));
+ this.number = number;
+ }
+ }
+
+ private static class DoubleLit extends Token {
+ double number;
+
+ DoubleLit(double number) {
+ super(Double.toString(number));
+ this.number = number;
+ }
+ }
+
+ private static class Tokenizer {
+ private final String s;
+ private final int len;
+ private int i = 0;
+
+ Tokenizer(String s) {
+ this.s = s;
+ this.len = s.length();
+ }
+
+ private int thisChar() {
+ if (i == len)
+ return -1;
+ return s.codePointAt(i);
+ }
+
+ private void advance() {
+ i += Character.charCount(thisChar());
+ }
+
+ private int thisCharAdvance() {
+ int c = thisChar();
+ advance();
+ return c;
+ }
+
+ Token nextToken() {
+ // In this method, c is the character we're looking at, and
+ // thisChar() is the character after that. Everything must
+ // preserve these invariants. When we return we then have
+ // thisChar() being the start of the following token, so
+ // the next call to nextToken() will begin from there.
+ int c;
+
+ // Skip space
+ do {
+ if (i == len)
+ return null;
+ c = thisCharAdvance();
+ } while (Character.isWhitespace(c));
+
+ // Now c is the first character of the token, and tokenI points
+ // to the character after that.
+ switch (c) {
+ case '(': return LPAR;
+ case ')': return RPAR;
+ case ',': return COMMA;
+ case '.': return DOT;
+ case '#': return SHARP;
+ case '*': return TIMES;
+ case '/': return DIVIDE;
+ case '=': return EQ;
+ case '-': return MINUS;
+ case '+': return PLUS;
+
+ case '>':
+ if (thisChar() == '=') {
+ advance();
+ return GE;
+ } else
+ return GT;
+
+ case '<':
+ c = thisChar();
+ switch (c) {
+ case '=': advance(); return LE;
+ case '>': advance(); return NE;
+ default: return LT;
+ }
+
+ case '!':
+ if (thisCharAdvance() != '=')
+ throw new IllegalArgumentException("'!' must be followed by '='");
+ return NE;
+
+ case '"':
+ case '\'': {
+ int quote = c;
+ StringBuilder sb = new StringBuilder();
+ while (true) {
+ while ((c = thisChar()) != quote) {
+ if (c < 0) {
+ throw new IllegalArgumentException(
+ "Unterminated string constant");
+ }
+ sb.appendCodePoint(thisCharAdvance());
+ }
+ advance();
+ if (thisChar() == quote) {
+ sb.appendCodePoint(quote);
+ advance();
+ } else
+ break;
+ }
+ if (quote == '\'')
+ return new StringLit(sb.toString());
+ else
+ return new QuotedId(sb.toString());
+ }
+ }
+
+ // Is it a numeric constant?
+ if (Character.isDigit(c) || c == '.') {
+ StringBuilder sb = new StringBuilder();
+ int lastc = -1;
+ while (true) {
+ sb.appendCodePoint(c);
+ c = Character.toLowerCase(thisChar());
+ if (c == '+' || c == '-') {
+ if (lastc != 'e')
+ break;
+ } else if (!Character.isDigit(c) && c != '.' && c != 'e')
+ break;
+ lastc = c;
+ advance();
+ }
+ String s = sb.toString();
+ if (s.indexOf('.') >= 0 || s.indexOf('e') >= 0) {
+ double d = parseDoubleCheckOverflow(s);
+ return new DoubleLit(d);
+ } else {
+ // Like the Java language, we allow the numeric constant
+ // x where -x = Long.MIN_VALUE, even though x is not
+ // representable as a long (it is Long.MAX_VALUE + 1).
+ // Code in the parser will reject this value if it is
+ // not the operand of unary minus.
+ long l = -Long.parseLong("-" + s);
+ return new LongLit(l);
+ }
+ }
+
+ // It must be an identifier.
+ if (!Character.isJavaIdentifierStart(c)) {
+ StringBuilder sb = new StringBuilder();
+ Formatter f = new Formatter(sb);
+ f.format("Bad character: %c (%04x)", c, c);
+ throw new IllegalArgumentException(sb.toString());
+ }
+
+ StringBuilder id = new StringBuilder();
+ while (true) { // identifier
+ id.appendCodePoint(c);
+ c = thisChar();
+ if (!Character.isJavaIdentifierPart(c))
+ break;
+ advance();
+ }
+
+ return new Id(id.toString());
+ }
+ }
+
+ /* Parse a double as a Java compiler would do it, throwing an exception
+ * if the input does not fit in a double. We assume that the input
+ * string is not "Infinity" and does not have a leading sign.
+ */
+ private static double parseDoubleCheckOverflow(String s) {
+ double d = Double.parseDouble(s);
+ if (Double.isInfinite(d))
+ throw new NumberFormatException("Overflow: " + s);
+ if (d == 0.0) { // Underflow checking is hard! CR 6604864
+ String ss = s;
+ int e = s.indexOf('e'); // we already forced E to lowercase
+ if (e > 0)
+ ss = s.substring(0, e);
+ ss = ss.replace("0", "").replace(".", "");
+ if (!ss.isEmpty())
+ throw new NumberFormatException("Underflow: " + s);
+ }
+ return d;
+ }
+
+ // PARSER STARTS HERE
+
+ private final List tokens;
+ private int tokenI;
+ // The current token is always tokens[tokenI].
+
+ QueryParser(String s) {
+ // Construct the complete list of tokens immediately and append
+ // a sentinel (END).
+ tokens = new ArrayList();
+ Tokenizer tokenizer = new Tokenizer(s);
+ Token t;
+ while ((t = tokenizer.nextToken()) != null)
+ tokens.add(t);
+ tokens.add(END);
+ }
+
+ private Token current() {
+ return tokens.get(tokenI);
+ }
+
+ // If the current token is t, then skip it and return true.
+ // Otherwise, return false.
+ private boolean skip(Token t) {
+ if (t.equals(current())) {
+ tokenI++;
+ return true;
+ }
+ return false;
+ }
+
+ // If the current token is one of the ones in 'tokens', then skip it
+ // and return its index in 'tokens'. Otherwise, return -1.
+ private int skipOne(Token... tokens) {
+ for (int i = 0; i < tokens.length; i++) {
+ if (skip(tokens[i]))
+ return i;
+ }
+ return -1;
+ }
+
+ // If the current token is t, then skip it and return.
+ // Otherwise throw an exception.
+ private void expect(Token t) {
+ if (!skip(t))
+ throw new IllegalArgumentException("Expected " + t + ", found " + current());
+ }
+
+ private void next() {
+ tokenI++;
+ }
+
+ QueryExp parseQuery() {
+ QueryExp qe = query();
+ if (current() != END)
+ throw new IllegalArgumentException("Junk at end of query: " + current());
+ return qe;
+ }
+
+ // The remainder of this class is a classical recursive-descent parser.
+ // We only need to violate the recursive-descent scheme in one place,
+ // where parentheses make the grammar not LL(1).
+
+ private QueryExp query() {
+ QueryExp lhs = andquery();
+ while (skip(OR))
+ lhs = Query.or(lhs, andquery());
+ return lhs;
+ }
+
+ private QueryExp andquery() {
+ QueryExp lhs = predicate();
+ while (skip(AND))
+ lhs = Query.and(lhs, predicate());
+ return lhs;
+ }
+
+ private QueryExp predicate() {
+ // Grammar hack. If we see a paren, it might be (query) or
+ // it might be (value). We try to parse (query), and if that
+ // fails, we parse (value). For example, if the string is
+ // "(2+3)*4 < 5" then we will try to parse the query
+ // "2+3)*4 < 5", which will fail at the ), so we'll back up to
+ // the paren and let value() handle it.
+ if (skip(LPAR)) {
+ int parenIndex = tokenI - 1;
+ try {
+ QueryExp qe = query();
+ expect(RPAR);
+ return qe;
+ } catch (IllegalArgumentException e) {
+ // OK: try parsing a value
+ }
+ tokenI = parenIndex;
+ }
+
+ if (skip(NOT))
+ return Query.not(predicate());
+
+ if (skip(INSTANCEOF))
+ return Query.isInstanceOf(stringvalue());
+
+ if (skip(LIKE)) {
+ StringValueExp sve = stringvalue();
+ String s = sve.getValue();
+ try {
+ return new ObjectName(s);
+ } catch (MalformedObjectNameException e) {
+ throw new IllegalArgumentException(
+ "Bad ObjectName pattern after LIKE: '" + s + "'", e);
+ }
+ }
+
+ ValueExp lhs = value();
+
+ return predrhs(lhs);
+ }
+
+ // The order of elements in the following arrays is important. The code
+ // in predrhs depends on integer indexes. Change with caution.
+ private static final Token[] relations = {
+ EQ, LT, GT, LE, GE, NE,
+ // 0, 1, 2, 3, 4, 5,
+ };
+ private static final Token[] betweenLikeIn = {
+ BETWEEN, LIKE, IN
+ // 0, 1, 2,
+ };
+
+ private QueryExp predrhs(ValueExp lhs) {
+ Token start = current(); // for errors
+
+ // Look for < > = etc
+ int i = skipOne(relations);
+ if (i >= 0) {
+ ValueExp rhs = value();
+ switch (i) {
+ case 0: return Query.eq(lhs, rhs);
+ case 1: return Query.lt(lhs, rhs);
+ case 2: return Query.gt(lhs, rhs);
+ case 3: return Query.leq(lhs, rhs);
+ case 4: return Query.geq(lhs, rhs);
+ case 5: return Query.not(Query.eq(lhs, rhs));
+ // There is no Query.ne so <> is shorthand for the above.
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ // Must be BETWEEN LIKE or IN, optionally preceded by NOT
+ boolean not = skip(NOT);
+ i = skipOne(betweenLikeIn);
+ if (i < 0)
+ throw new IllegalArgumentException("Expected relation at " + start);
+
+ QueryExp q;
+ switch (i) {
+ case 0: { // BETWEEN
+ ValueExp lower = value();
+ expect(AND);
+ ValueExp upper = value();
+ q = Query.between(lhs, lower, upper);
+ break;
+ }
+
+ case 1: { // LIKE
+ if (!(lhs instanceof AttributeValueExp)) {
+ throw new IllegalArgumentException(
+ "Left-hand side of LIKE must be an attribute");
+ }
+ AttributeValueExp alhs = (AttributeValueExp) lhs;
+ StringValueExp sve = stringvalue();
+ String s = sve.getValue();
+ q = Query.match(alhs, patternValueExp(s));
+ break;
+ }
+
+ case 2: { // IN
+ expect(LPAR);
+ List values = new ArrayList();
+ values.add(value());
+ while (skip(COMMA))
+ values.add(value());
+ expect(RPAR);
+ q = Query.in(lhs, values.toArray(new ValueExp[values.size()]));
+ break;
+ }
+
+ default:
+ throw new AssertionError();
+ }
+
+ if (not)
+ q = Query.not(q);
+
+ return q;
+ }
+
+ private ValueExp value() {
+ ValueExp lhs = factor();
+ int i;
+ while ((i = skipOne(PLUS, MINUS)) >= 0) {
+ ValueExp rhs = factor();
+ if (i == 0)
+ lhs = Query.plus(lhs, rhs);
+ else
+ lhs = Query.minus(lhs, rhs);
+ }
+ return lhs;
+ }
+
+ private ValueExp factor() {
+ ValueExp lhs = term();
+ int i;
+ while ((i = skipOne(TIMES, DIVIDE)) >= 0) {
+ ValueExp rhs = term();
+ if (i == 0)
+ lhs = Query.times(lhs, rhs);
+ else
+ lhs = Query.div(lhs, rhs);
+ }
+ return lhs;
+ }
+
+ private ValueExp term() {
+ boolean signed = false;
+ int sign = +1;
+ if (skip(PLUS))
+ signed = true;
+ else if (skip(MINUS)) {
+ signed = true; sign = -1;
+ }
+
+ Token t = current();
+ next();
+
+ if (t instanceof DoubleLit)
+ return Query.value(sign * ((DoubleLit) t).number);
+ if (t instanceof LongLit) {
+ long n = ((LongLit) t).number;
+ if (n == Long.MIN_VALUE && sign != -1)
+ throw new IllegalArgumentException("Illegal positive integer: " + n);
+ return Query.value(sign * n);
+ }
+ if (signed)
+ throw new IllegalArgumentException("Expected number after + or -");
+
+ if (t == LPAR) {
+ ValueExp v = value();
+ expect(RPAR);
+ return v;
+ }
+ if (t.equals(FALSE) || t.equals(TRUE)) {
+ return Query.value(t.equals(TRUE));
+ }
+ if (t.equals(CLASS))
+ return Query.classattr();
+
+ if (t instanceof StringLit)
+ return Query.value(t.string); // Not toString(), which would requote '
+
+ // At this point, all that remains is something that will call Query.attr
+
+ if (!(t instanceof Id) && !(t instanceof QuotedId))
+ throw new IllegalArgumentException("Unexpected token " + t);
+
+ String name1 = name(t);
+
+ if (skip(SHARP)) {
+ Token t2 = current();
+ next();
+ String name2 = name(t2);
+ return Query.attr(name1, name2);
+ }
+ return Query.attr(name1);
+ }
+
+ // Initially, t is the first token of a supposed name and current()
+ // is the second.
+ private String name(Token t) {
+ StringBuilder sb = new StringBuilder();
+ while (true) {
+ if (!(t instanceof Id) && !(t instanceof QuotedId))
+ throw new IllegalArgumentException("Unexpected token " + t);
+ sb.append(t.string);
+ if (current() != DOT)
+ break;
+ sb.append('.');
+ next();
+ t = current();
+ next();
+ }
+ return sb.toString();
+ }
+
+ private StringValueExp stringvalue() {
+ // Currently the only way to get a StringValueExp when constructing
+ // a QueryExp is via Query.value(String), so we only recognize
+ // string literals here. But if we expand queries in the future
+ // that might no longer be true.
+ Token t = current();
+ next();
+ if (!(t instanceof StringLit))
+ throw new IllegalArgumentException("Expected string: " + t);
+ return Query.value(t.string);
+ }
+
+ // Convert the SQL pattern syntax, using % and _, to the Query.match
+ // syntax, using * and ?. The tricky part is recognizing \% and
+ // \_ as literal values, and also not replacing them inside [].
+ // But Query.match does not recognize \ inside [], which makes our
+ // job a tad easier.
+ private StringValueExp patternValueExp(String s) {
+ int c;
+ for (int i = 0; i < s.length(); i += Character.charCount(c)) {
+ c = s.codePointAt(i);
+ switch (c) {
+ case '\\':
+ i++; // i += Character.charCount(c), but we know it's 1!
+ if (i >= s.length())
+ throw new IllegalArgumentException("\\ at end of pattern");
+ break;
+ case '[':
+ i = s.indexOf(']', i);
+ if (i < 0)
+ throw new IllegalArgumentException("[ without ]");
+ break;
+ case '%':
+ s = s.substring(0, i) + "*" + s.substring(i + 1);
+ break;
+ case '_':
+ s = s.substring(0, i) + "?" + s.substring(i + 1);
+ break;
+ case '*':
+ case '?':
+ s = s.substring(0, i) + '\\' + (char) c + s.substring(i + 1);
+ i++;
+ break;
+ }
+ }
+ return Query.value(s);
+ }
+}
diff --git a/jdk/src/share/classes/javax/management/StringValueExp.java b/jdk/src/share/classes/javax/management/StringValueExp.java
index 5e5202349f5..40a9b2364d8 100644
--- a/jdk/src/share/classes/javax/management/StringValueExp.java
+++ b/jdk/src/share/classes/javax/management/StringValueExp.java
@@ -73,7 +73,7 @@ public class StringValueExp implements ValueExp {
* Returns the string representing the object.
*/
public String toString() {
- return "'" + val + "'";
+ return "'" + val.replace("'", "''") + "'";
}
diff --git a/jdk/src/share/classes/javax/management/ToQueryString.java b/jdk/src/share/classes/javax/management/ToQueryString.java
new file mode 100644
index 00000000000..be73bc5f377
--- /dev/null
+++ b/jdk/src/share/classes/javax/management/ToQueryString.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.management;
+
+/* QueryExp classes can extend this to get non-default treatment for
+ * Query.toString(q). We're reluctant to change the public toString()
+ * methods of the classes because people might be parsing them, even
+ * though that's rather fragile. But Query.toString(q) has no such
+ * constraint so it can use the new toQueryString() method defined here.
+ */
+class ToQueryString {
+ String toQueryString() {
+ return toString();
+ }
+}
diff --git a/jdk/src/share/classes/javax/management/monitor/Monitor.java b/jdk/src/share/classes/javax/management/monitor/Monitor.java
index 528e8c7fd1a..5df59a7a20e 100644
--- a/jdk/src/share/classes/javax/management/monitor/Monitor.java
+++ b/jdk/src/share/classes/javax/management/monitor/Monitor.java
@@ -27,13 +27,8 @@ package javax.management.monitor;
import static com.sun.jmx.defaults.JmxProperties.MONITOR_LOGGER;
import com.sun.jmx.mbeanserver.GetPropertyAction;
-import com.sun.jmx.remote.util.EnvHelp;
-import java.beans.BeanInfo;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
+import com.sun.jmx.mbeanserver.Introspector;
import java.io.IOException;
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -64,7 +59,6 @@ import javax.management.NotificationBroadcasterSupport;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import static javax.management.monitor.MonitorNotification.*;
-import javax.management.openmbean.CompositeData;
/**
* Defines the part common to all monitor MBeans.
@@ -876,44 +870,13 @@ public abstract class Monitor
if (isComplexTypeAttribute) {
Object v = value;
for (String attr : remainingAttributes)
- v = introspect(object, attr, v);
+ v = Introspector.elementFromComplex(v, attr);
return (Comparable>) v;
} else {
return (Comparable>) value;
}
}
- Object introspect(ObjectName object,
- String attribute,
- Object value)
- throws AttributeNotFoundException {
- try {
- if (value.getClass().isArray() && attribute.equals("length")) {
- return Array.getLength(value);
- } else if (value instanceof CompositeData) {
- return ((CompositeData) value).get(attribute);
- } else {
- // Java Beans introspection
- //
- BeanInfo bi = Introspector.getBeanInfo(value.getClass());
- PropertyDescriptor[] pds = bi.getPropertyDescriptors();
- for (PropertyDescriptor pd : pds)
- if (pd.getName().equals(attribute))
- return pd.getReadMethod().invoke(value);
- throw new AttributeNotFoundException(
- "Could not find the getter method for the property " +
- attribute + " using the Java Beans introspector");
- }
- } catch (InvocationTargetException e) {
- throw new IllegalArgumentException(e);
- } catch (AttributeNotFoundException e) {
- throw e;
- } catch (Exception e) {
- throw EnvHelp.initCause(
- new AttributeNotFoundException(e.getMessage()), e);
- }
- }
-
boolean isComparableTypeValid(ObjectName object,
String attribute,
Comparable> value) {
diff --git a/jdk/test/javax/management/query/QueryDottedAttrTest.java b/jdk/test/javax/management/query/QueryDottedAttrTest.java
new file mode 100644
index 00000000000..956496db9b6
--- /dev/null
+++ b/jdk/test/javax/management/query/QueryDottedAttrTest.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test QueryDottedAttrTest
+ * @bug 6602310
+ * @summary Test that Query.attr can understand a.b etc.
+ * @author Eamonn McManus
+ */
+
+import java.beans.ConstructorProperties;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Collections;
+import java.util.Set;
+import javax.management.AttributeNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.management.Query;
+import javax.management.QueryExp;
+import javax.management.ReflectionException;
+import javax.management.StandardMBean;
+
+public class QueryDottedAttrTest {
+ public static class Complex {
+ private final double re, im;
+
+ @ConstructorProperties({"real", "imaginary"})
+ public Complex(double re, double im) {
+ this.re = re;
+ this.im = im;
+ }
+
+ public double getRe() {
+ return re;
+ }
+
+ public double getIm() {
+ return im;
+ }
+ }
+
+ public static interface Intf {
+ Complex getComplex();
+ int[] getIntArray();
+ String[] getStringArray();
+ }
+
+ public static class Impl implements Intf {
+ public Complex getComplex() {
+ return new Complex(1.0, 1.0);
+ }
+
+ public int[] getIntArray() {
+ return new int[] {1, 2, 3};
+ }
+
+ public String[] getStringArray() {
+ return new String[] {"one", "two", "three"};
+ }
+ }
+
+ public static interface TestMBean extends Intf {}
+
+ public static class Test extends Impl implements TestMBean {}
+
+ public static interface TestMXBean extends Intf {}
+
+ public static class TestMX extends Impl implements TestMXBean {}
+
+ public static class AttrWithDot extends StandardMBean {
+ public AttrWithDot(Object impl, Class intf) {
+ super(intf.cast(impl), intf, (intf == TestMXBean.class));
+ }
+
+ public Object getAttribute(String attribute)
+ throws AttributeNotFoundException, MBeanException, ReflectionException {
+ if (attribute.equals("Complex.re"))
+ return 2.0;
+ else
+ return super.getAttribute(attribute);
+ }
+ }
+
+ private static final boolean[] booleans = {false, true};
+
+ private static final QueryExp[] alwaysTrueQueries = {
+ Query.eq(Query.attr("IntArray.length"), Query.value(3)),
+ Query.eq(Query.attr("StringArray.length"), Query.value(3)),
+ Query.eq(Query.attr("Complex.im"), Query.value(1.0)),
+ };
+
+ private static final QueryExp[] alwaysFalseQueries = {
+ Query.eq(Query.attr("IntArray.length"), Query.value("3")),
+ Query.eq(Query.attr("IntArray.length"), Query.value(2)),
+ Query.eq(Query.attr("Complex.im"), Query.value(-1.0)),
+ Query.eq(Query.attr("Complex.xxx"), Query.value(0)),
+ };
+
+ private static final QueryExp[] attrWithDotTrueQueries = {
+ Query.eq(Query.attr("Complex.re"), Query.value(2.0)),
+ };
+
+ private static final QueryExp[] attrWithDotFalseQueries = {
+ Query.eq(Query.attr("Complex.re"), Query.value(1.0)),
+ };
+
+ private static String failure;
+
+ public static void main(String[] args) throws Exception {
+ ObjectName name = new ObjectName("a:b=c");
+ for (boolean attrWithDot : booleans) {
+ for (boolean mx : booleans) {
+ String what =
+ (mx ? "MXBean" : "Standard MBean") +
+ (attrWithDot ? " having attribute with dot in its name" : "");
+ System.out.println("Testing " + what);
+ Class> intf = mx ? TestMXBean.class : TestMBean.class;
+ Object impl = mx ? new TestMX() : new Test();
+ if (attrWithDot)
+ impl = new AttrWithDot(impl, intf);
+ MBeanServer mbs = MBeanServerFactory.newMBeanServer();
+ mbs.registerMBean(impl, name);
+ boolean ismx = "true".equals(
+ mbs.getMBeanInfo(name).getDescriptor().getFieldValue("mxbean"));
+ if (mx != ismx)
+ fail("MBean should " + (mx ? "" : "not ") + "be MXBean");
+ test(mbs, name, alwaysTrueQueries, true);
+ test(mbs, name, alwaysFalseQueries, false);
+ test(mbs, name, attrWithDotTrueQueries, attrWithDot);
+ test(mbs, name, attrWithDotFalseQueries, !attrWithDot);
+ }
+ }
+ if (failure != null)
+ throw new Exception("TEST FAILED: " + failure);
+ }
+
+ private static void test(
+ MBeanServer mbs, ObjectName name, QueryExp[] queries, boolean expect)
+ throws Exception {
+ for (QueryExp query : queries) {
+ // Serialize and deserialize the query to ensure that its
+ // serialization is correct
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream oout = new ObjectOutputStream(bout);
+ oout.writeObject(query);
+ oout.close();
+ ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
+ ObjectInputStream oin = new ObjectInputStream(bin);
+ query = (QueryExp) oin.readObject();
+ Set names = mbs.queryNames(null, query);
+ if (names.isEmpty()) {
+ if (expect)
+ fail("Query is false but should be true: " + query);
+ } else if (names.equals(Collections.singleton(name))) {
+ if (!expect)
+ fail("Query is true but should be false: " + query);
+ } else {
+ fail("Query returned unexpected set: " + names);
+ }
+ }
+ }
+
+ private static void fail(String msg) {
+ failure = msg;
+ System.out.println("..." + msg);
+ }
+}
diff --git a/jdk/test/javax/management/query/QueryExpStringTest.java b/jdk/test/javax/management/query/QueryExpStringTest.java
index 729a8e7ec95..be6a515b8fb 100644
--- a/jdk/test/javax/management/query/QueryExpStringTest.java
+++ b/jdk/test/javax/management/query/QueryExpStringTest.java
@@ -31,6 +31,10 @@
* @run main QueryExpStringTest
*/
+// This test is mostly obsolete, since we now have Query.fromString.
+// The test includes its own parser, from which Query.fromString was derived.
+// The parsers are not identical and the one here is no longer maintained.
+
import java.util.*;
import javax.management.*;
@@ -39,6 +43,11 @@ public class QueryExpStringTest {
private static final ValueExp
attr = Query.attr("attr"),
qattr = Query.attr("className", "attr"),
+ aa = Query.attr("A"),
+ bb = Query.attr("B"),
+ cc = Query.attr("C"),
+ dd = Query.attr("D"),
+ zero = Query.value(0),
classattr = Query.classattr(),
simpleString = Query.value("simpleString"),
complexString = Query.value("a'b\\'\""),
@@ -66,10 +75,14 @@ public class QueryExpStringTest {
(StringValueExp) simpleString),
initialStar = Query.initialSubString((AttributeValueExp) attr,
Query.value("*")),
+ initialPercent = Query.initialSubString((AttributeValueExp) attr,
+ Query.value("%")),
any = Query.anySubString((AttributeValueExp) attr,
(StringValueExp) simpleString),
anyStar = Query.anySubString((AttributeValueExp) attr,
Query.value("*")),
+ anyPercent = Query.anySubString((AttributeValueExp) attr,
+ Query.value("%")),
ffinal = Query.finalSubString((AttributeValueExp) attr,
(StringValueExp) simpleString),
finalMagic = Query.finalSubString((AttributeValueExp) attr,
@@ -77,16 +90,20 @@ public class QueryExpStringTest {
in = Query.in(intValue, new ValueExp[] {intValue, floatValue}),
and = Query.and(gt, lt),
or = Query.or(gt, lt),
- not = Query.not(gt);
+ not = Query.not(gt),
+ aPlusB_PlusC = Query.gt(Query.plus(Query.plus(aa, bb), cc), zero),
+ aPlus_BPlusC = Query.gt(Query.plus(aa, Query.plus(bb, cc)), zero);
// Commented-out tests below require change to implementation
private static final Object tests[] = {
attr, "attr",
- qattr, "className.attr",
+// qattr, "className.attr",
+// Preceding form now appears as className#attr, an incompatible change
+// which we don't mind much because nobody uses the two-arg Query.attr.
classattr, "Class",
simpleString, "'simpleString'",
-// complexString, "'a\\'b\\\\\\'\"'",
+ complexString, "'a''b\\\''\"'",
intValue, "12345678",
integerValue, "12345678",
longValue, "12345678",
@@ -104,16 +121,20 @@ public class QueryExpStringTest {
eq, "(12345678) = (2.5)",
between, "(12345678) between (2.5) and (2.5)",
match, "attr like 'simpleString'",
-// initial, "attr like 'simpleString*'",
-// initialStar, "attr like '\\\\**'",
-// any, "attr like '*simpleString*'",
-// anyStar, "attr like '*\\\\**'",
-// ffinal, "attr like '*simpleString'",
-// finalMagic, "attr like '*\\\\?\\\\*\\\\[\\\\\\\\'",
+ initial, "attr like 'simpleString%'",
+ initialStar, "attr like '\\*%'",
+ initialPercent, "attr like '\\%%'",
+ any, "attr like '%simpleString%'",
+ anyStar, "attr like '%\\*%'",
+ anyPercent, "attr like '%\\%%'",
+ ffinal, "attr like '%simpleString'",
+ finalMagic, "attr like '%\\?\\*\\[\\\\'",
in, "12345678 in (12345678, 2.5)",
and, "((12345678) > (2.5)) and ((12345678) < (2.5))",
or, "((12345678) > (2.5)) or ((12345678) < (2.5))",
not, "not ((12345678) > (2.5))",
+ aPlusB_PlusC, "(A + B + C) > (0)",
+// aPlus_BPlusC, "(A + (B + C)) > (0)",
};
public static void main(String[] args) throws Exception {
@@ -185,7 +206,9 @@ public class QueryExpStringTest {
throw new Exception("Expected types `attr like string': " +
exp + " like " + pat);
}
- return Query.match((AttributeValueExp) exp, (StringValueExp) pat);
+ StringValueExp spat = (StringValueExp) pat;
+ spat = Query.value(translateMatch(spat.getValue()));
+ return Query.match((AttributeValueExp) exp, spat);
}
if (skip(ss, " in (")) {
@@ -203,6 +226,28 @@ public class QueryExpStringTest {
throw new Exception("Expected in or like after expression");
}
+ private static String translateMatch(String s) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < s.length(); i++) { // logic not correct for wide chars
+ char c = s.charAt(i);
+ switch (c) {
+ case '\\':
+ sb.append(c).append(s.charAt(++i)); break;
+ case '%':
+ sb.append('*'); break;
+ case '_':
+ sb.append('?'); break;
+ case '*':
+ sb.append("\\*"); break;
+ case '?':
+ sb.append("\\?"); break;
+ default:
+ sb.append(c); break;
+ }
+ }
+ return sb.toString();
+ }
+
private static QueryExp parseQueryAfterParen(String[] ss)
throws Exception {
/* This is very ugly. We might have "(q1) and (q2)" here, or
@@ -229,7 +274,7 @@ public class QueryExpStringTest {
ss[0] = start;
ValueExp lhs = parseExp(ss);
if (!skip(ss, ") "))
- throw new Exception("Expected `) ' after subexpression");
+ throw new Exception("Expected `) ' after subexpression: " + ss[0]);
String op = scanWord(ss);
if (!skip(ss, " ("))
throw new Exception("Expected ` (' after `" + op + "'");
@@ -258,15 +303,16 @@ public class QueryExpStringTest {
}
private static ValueExp parseExp(String[] ss) throws Exception {
- final ValueExp prim = parsePrimary(ss);
+ ValueExp lhs = parsePrimary(ss);
+ while (true) {
/* Look ahead to see if we have an arithmetic operator. */
String back = ss[0];
if (!skip(ss, " "))
- return prim;
+ return lhs;
if (ss[0].equals("") || "+-*/".indexOf(ss[0].charAt(0)) < 0) {
ss[0] = back;
- return prim;
+ return lhs;
}
final String op = scanWord(ss);
@@ -276,15 +322,16 @@ public class QueryExpStringTest {
throw new Exception("Unknown arithmetic operator: " + op);
if (!skip(ss, " "))
throw new Exception("Expected space after arithmetic operator");
- ValueExp rhs = parseExp(ss);
+ ValueExp rhs = parsePrimary(ss);
switch (op.charAt(0)) {
- case '+': return Query.plus(prim, rhs);
- case '-': return Query.minus(prim, rhs);
- case '*': return Query.times(prim, rhs);
- case '/': return Query.div(prim, rhs);
+ case '+': lhs = Query.plus(lhs, rhs); break;
+ case '-': lhs = Query.minus(lhs, rhs); break;
+ case '*': lhs = Query.times(lhs, rhs); break;
+ case '/': lhs = Query.div(lhs, rhs); break;
default: throw new Exception("Can't happen: " + op.charAt(0));
}
}
+ }
private static ValueExp parsePrimary(String[] ss) throws Exception {
String s = ss[0];
@@ -324,14 +371,19 @@ public class QueryExpStringTest {
private static String scanWord(String[] ss) throws Exception {
String s = ss[0];
int space = s.indexOf(' ');
- if (space < 0) {
+ int rpar = s.indexOf(')');
+ if (space < 0 && rpar < 0) {
ss[0] = "";
return s;
- } else {
- String word = s.substring(0, space);
- ss[0] = s.substring(space);
- return word;
}
+ int stop;
+ if (space >= 0 && rpar >= 0) // string has both space and ), stop at first
+ stop = Math.min(space, rpar);
+ else // string has only one, stop at it
+ stop = Math.max(space, rpar);
+ String word = s.substring(0, stop);
+ ss[0] = s.substring(stop);
+ return word;
}
private static boolean matchWord(String[] ss, String word)
@@ -381,13 +433,11 @@ public class QueryExpStringTest {
for (i = 0; i < len; i++) {
char c = s.charAt(i);
if (c == '\'') {
- ss[0] = s.substring(i + 1);
+ ++i;
+ if (i >= len || s.charAt(i) != '\'') {
+ ss[0] = s.substring(i);
return Query.value(buf.toString());
}
- if (c == '\\') {
- if (++i == len)
- throw new Exception("\\ at end of string");
- c = s.charAt(i);
}
buf.append(c);
}
diff --git a/jdk/test/javax/management/query/QueryParseTest.java b/jdk/test/javax/management/query/QueryParseTest.java
new file mode 100644
index 00000000000..a6004b5c150
--- /dev/null
+++ b/jdk/test/javax/management/query/QueryParseTest.java
@@ -0,0 +1,778 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test QueryParseTest
+ * @bug 6602310 6604768
+ * @summary Test Query.fromString and Query.toString.
+ * @author Eamonn McManus
+ */
+
+import java.util.Collections;
+import java.util.Set;
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerDelegate;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.management.Query;
+import javax.management.QueryExp;
+
+public class QueryParseTest {
+ // In this table, each string constant corresponds to a test case.
+ // The objects following the string up to the next string are MBeans.
+ // Each MBean must implement ExpectedValue to return true or false
+ // according as it should return that value for the query parsed
+ // from the given string. The test will parse the string into a
+ // a query and verify that the MBeans return the expected value
+ // for that query. Then it will convert the query back into a string
+ // and into a second query, and check that the MBeans return the
+ // expected value for that query too. The reason we need to do all
+ // this is that the spec talks about "equivalent queries", and gives
+ // the implementation wide scope to rearrange queries. So we cannot
+ // just compare string values.
+ //
+ // We could also write an implementation-dependent test that knew what
+ // the strings look like, and that would have to be changed if the
+ // implementation changed. But the approach here is cleaner.
+ //
+ // To simplify the creation of MBeans, most use the expectTrue or
+ // expectFalse methods. The parameters of these methods end up in
+ // attributes called "A", "B", "C", etc.
+ private static final Object[] queryTests = {
+ // RELATIONS
+
+ "A < B",
+ expectTrue(1, 2), expectTrue(1.0, 2.0), expectTrue("one", "two"),
+ expectTrue(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY),
+ expectFalse(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY),
+ expectFalse(1, 1), expectFalse(1.0, 1.0), expectFalse("one", "one"),
+ expectFalse(2, 1), expectFalse(2.0, 1.0), expectFalse("two", "one"),
+ expectFalse(Double.NaN, Double.NaN),
+
+ "One = two",
+ expectTrueOneTwo(1, 1), expectTrueOneTwo(1.0, 1.0),
+ expectFalseOneTwo(1, 2), expectFalseOneTwo(2, 1),
+
+ "A <= B",
+ expectTrue(1, 1), expectTrue(1, 2), expectTrue("one", "one"),
+ expectTrue("one", "two"),
+ expectFalse(2, 1), expectFalse("two", "one"),
+ expectFalse(Double.NaN, Double.NaN),
+
+ "A >= B",
+ expectTrue(1, 1), expectTrue(2, 1), expectTrue("two", "one"),
+ expectFalse(1, 2), expectFalse("one", "two"),
+
+ "A > B",
+ expectTrue(2, 1), expectTrue("two", "one"),
+ expectFalse(2, 2), expectFalse(1, 2), expectFalse(1.0, 2.0),
+ expectFalse("one", "two"),
+
+ "A <> B",
+ expectTrue(1, 2), expectTrue("foo", "bar"),
+ expectFalse(1, 1), expectFalse("foo", "foo"),
+
+ "A != B",
+ expectTrue(1, 2), expectTrue("foo", "bar"),
+ expectFalse(1, 1), expectFalse("foo", "foo"),
+
+ // PARENTHESES
+
+ "(((A))) = (B)",
+ expectTrue(1, 1), expectFalse(1, 2),
+
+ "(A = B)",
+ expectTrue(1, 1), expectFalse(1, 2),
+
+ "(((A = (B))))",
+ expectTrue(1, 1), expectFalse(1, 2),
+
+ // INTEGER LITERALS
+
+ "A = 1234567890123456789",
+ expectTrue(1234567890123456789L), expectFalse(123456789L),
+
+ "A = +1234567890123456789",
+ expectTrue(1234567890123456789L), expectFalse(123456789L),
+
+ "A = -1234567890123456789",
+ expectTrue(-1234567890123456789L), expectFalse(-123456789L),
+
+
+ "A = + 1234567890123456789",
+ expectTrue(1234567890123456789L), expectFalse(123456789L),
+
+ "A = - 1234567890123456789",
+ expectTrue(-1234567890123456789L), expectFalse(-123456789L),
+
+ "A = " + Long.MAX_VALUE,
+ expectTrue(Long.MAX_VALUE), expectFalse(Long.MIN_VALUE),
+
+ "A = " + Long.MIN_VALUE,
+ expectTrue(Long.MIN_VALUE), expectFalse(Long.MAX_VALUE),
+
+ // DOUBLE LITERALS
+
+ "A = 0.0",
+ expectTrue(0.0), expectFalse(1.0),
+
+ "A = 0.0e23",
+ expectTrue(0.0), expectFalse(1.0),
+
+ "A = 1.2e3",
+ expectTrue(1.2e3), expectFalse(1.2),
+
+ "A = +1.2",
+ expectTrue(1.2), expectFalse(-1.2),
+
+ "A = 1.2e+3",
+ expectTrue(1.2e3), expectFalse(1.2),
+
+ "A = 1.2e-3",
+ expectTrue(1.2e-3), expectFalse(1.2),
+
+ "A = 1.2E3",
+ expectTrue(1.2e3), expectFalse(1.2),
+
+ "A = -1.2e3",
+ expectTrue(-1.2e3), expectFalse(1.2),
+
+ "A = " + Double.MAX_VALUE,
+ expectTrue(Double.MAX_VALUE), expectFalse(Double.MIN_VALUE),
+
+ "A = " + -Double.MAX_VALUE,
+ expectTrue(-Double.MAX_VALUE), expectFalse(-Double.MIN_VALUE),
+
+ "A = " + Double.MIN_VALUE,
+ expectTrue(Double.MIN_VALUE), expectFalse(Double.MAX_VALUE),
+
+ "A = " + -Double.MIN_VALUE,
+ expectTrue(-Double.MIN_VALUE), expectFalse(-Double.MAX_VALUE),
+
+ Query.toString( // A = Infinity -> A = (1.0/0.0)
+ Query.eq(Query.attr("A"), Query.value(Double.POSITIVE_INFINITY))),
+ expectTrue(Double.POSITIVE_INFINITY),
+ expectFalse(0.0), expectFalse(Double.NEGATIVE_INFINITY),
+
+ Query.toString( // A = -Infinity -> A = (-1.0/0.0)
+ Query.eq(Query.attr("A"), Query.value(Double.NEGATIVE_INFINITY))),
+ expectTrue(Double.NEGATIVE_INFINITY),
+ expectFalse(0.0), expectFalse(Double.POSITIVE_INFINITY),
+
+ Query.toString( // A < NaN -> A < (0.0/0.0)
+ Query.lt(Query.attr("A"), Query.value(Double.NaN))),
+ expectFalse(0.0), expectFalse(Double.NEGATIVE_INFINITY),
+ expectFalse(Double.POSITIVE_INFINITY), expectFalse(Double.NaN),
+
+ Query.toString( // A >= NaN -> A < (0.0/0.0)
+ Query.geq(Query.attr("A"), Query.value(Double.NaN))),
+ expectFalse(0.0), expectFalse(Double.NEGATIVE_INFINITY),
+ expectFalse(Double.POSITIVE_INFINITY), expectFalse(Double.NaN),
+
+ // STRING LITERALS
+
+ "A = 'blim'",
+ expectTrue("blim"), expectFalse("blam"),
+
+ "A = 'can''t'",
+ expectTrue("can't"), expectFalse("cant"), expectFalse("can''t"),
+
+ "A = '''blim'''",
+ expectTrue("'blim'"), expectFalse("'blam'"),
+
+ "A = ''",
+ expectTrue(""), expectFalse((Object) null),
+
+ // BOOLEAN LITERALS
+
+ "A = true",
+ expectTrue(true), expectFalse(false), expectFalse((Object) null),
+
+ "A = TRUE",
+ expectTrue(true), expectFalse(false),
+
+ "A = TrUe",
+ expectTrue(true), expectFalse(false),
+
+ "A = false",
+ expectTrue(false), expectFalse(true),
+
+ "A = fAlSe",
+ expectTrue(false), expectFalse(true),
+
+ "A = \"true\"", // An attribute called "true"
+ expectFalse(true), expectFalse(false), expectFalse("\"true\""),
+ newTester(new String[] {"A", "true"}, new Object[] {2.2, 2.2}, true),
+ newTester(new String[] {"A", "true"}, new Object[] {2.2, 2.3}, false),
+
+ "A = \"False\"",
+ expectFalse(true), expectFalse(false), expectFalse("\"False\""),
+ newTester(new String[] {"A", "False"}, new Object[] {2.2, 2.2}, true),
+ newTester(new String[] {"A", "False"}, new Object[] {2.2, 2.3}, false),
+
+ // ARITHMETIC
+
+ "A + B = 10",
+ expectTrue(4, 6), expectFalse(3, 8),
+
+ "A + B = 'blim'",
+ expectTrue("bl", "im"), expectFalse("bl", "am"),
+
+ "A - B = 10",
+ expectTrue(16, 6), expectFalse(16, 3),
+
+ "A * B = 10",
+ expectTrue(2, 5), expectFalse(3, 3),
+
+ "A / B = 10",
+ expectTrue(70, 7), expectTrue(70.0, 7), expectFalse(70.01, 7),
+
+ "A + B + C = 10",
+ expectTrue(2, 3, 5), expectFalse(2, 4, 8),
+
+ "A+B+C=10",
+ expectTrue(2, 3, 5), expectFalse(2, 4, 8),
+
+ "A + B + C + D = 10",
+ expectTrue(1, 2, 3, 4), expectFalse(2, 3, 4, 5),
+
+ "A + (B + C) = 10",
+ expectTrue(2, 3, 5), expectFalse(2, 4, 8),
+
+ // It is not correct to rearrange A + (B + C) as A + B + C
+ // (which means (A + B) + C), because of overflow.
+ // In particular Query.toString must not do this.
+ "A + (B + C) = " + Double.MAX_VALUE, // ensure no false associativity
+ expectTrue(Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE),
+ expectFalse(-Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE),
+
+ "A * (B * C) < " + Double.MAX_VALUE, // same test for multiplication
+ expectTrue(Double.MAX_VALUE, Double.MAX_VALUE, Double.MIN_VALUE),
+ expectFalse(Double.MIN_VALUE, Double.MAX_VALUE, Double.MAX_VALUE),
+
+ "A * B + C = 10",
+ expectTrue(3, 3, 1), expectTrue(2, 4, 2), expectFalse(1, 2, 3),
+
+ "A*B+C=10",
+ expectTrue(3, 3, 1), expectTrue(2, 4, 2), expectFalse(1, 2, 3),
+
+ "(A * B) + C = 10",
+ expectTrue(3, 3, 1), expectTrue(2, 4, 2), expectFalse(1, 2, 3),
+
+ "A + B * C = 10",
+ expectTrue(1, 3, 3), expectTrue(2, 2, 4), expectFalse(1, 2, 3),
+
+ "A - B * C = 10",
+ expectTrue(16, 2, 3), expectFalse(15, 2, 2),
+
+ "A + B / C = 10",
+ expectTrue(5, 15, 3), expectFalse(5, 16, 4),
+
+ "A - B / C = 10",
+ expectTrue(16, 12, 2), expectFalse(15, 10, 3),
+
+ "A * (B + C) = 10",
+ expectTrue(2, 2, 3), expectFalse(1, 2, 3),
+
+ "A / (B + C) = 10",
+ expectTrue(70, 4, 3), expectFalse(70, 3, 5),
+
+ "A * (B - C) = 10",
+ expectTrue(2, 8, 3), expectFalse(2, 3, 8),
+
+ "A / (B - C) = 10",
+ expectTrue(70, 11, 4), expectFalse(70, 4, 11),
+
+ "A / B / C = 10",
+ expectTrue(140, 2, 7), expectFalse(100, 5, 5),
+
+ "A / (B / C) = 10",
+ expectTrue(70, 14, 2), expectFalse(70, 10, 7),
+
+ // LOGIC
+
+ "A = B or C = D",
+ expectTrue(1, 1, 2, 3), expectTrue(1, 2, 3, 3), expectTrue(1, 1, 2, 2),
+ expectFalse(1, 2, 3, 4), expectFalse("!", "!!", "?", "??"),
+
+ "A = B and C = D",
+ expectTrue(1, 1, 2, 2),
+ expectFalse(1, 1, 2, 3), expectFalse(1, 2, 3, 3),
+
+ "A = 1 and B = 2 and C = 3",
+ expectTrue(1, 2, 3), expectFalse(1, 2, 4),
+
+ "A = 1 or B = 2 or C = 3",
+ expectTrue(1, 2, 3), expectTrue(1, 0, 0), expectTrue(0, 0, 3),
+ expectFalse(2, 3, 4),
+
+ // grouped as (a and b) or (c and d)
+ "A = 1 AND B = 2 OR C = 3 AND D = 4",
+ expectTrue(1, 2, 3, 4), expectTrue(1, 2, 1, 2), expectTrue(3, 4, 3, 4),
+ expectFalse(3, 4, 1, 2), expectFalse(1, 1, 1, 1),
+
+ "(A = 1 AND B = 2) OR (C = 3 AND D = 4)",
+ expectTrue(1, 2, 3, 4), expectTrue(1, 2, 1, 2), expectTrue(3, 4, 3, 4),
+ expectFalse(3, 4, 1, 2), expectFalse(1, 1, 1, 1),
+
+ "(A = 1 or B = 2) AND (C = 3 or C = 4)",
+ expectTrue(1, 1, 3, 3), expectTrue(2, 2, 4, 4), expectTrue(1, 2, 3, 4),
+ expectFalse(1, 2, 1, 2), expectFalse(3, 4, 3, 4),
+
+ // LIKE
+
+ "A like 'b%m'",
+ expectTrue("blim"), expectTrue("bm"),
+ expectFalse(""), expectFalse("blimmo"), expectFalse("mmm"),
+
+ "A not like 'b%m'",
+ expectFalse("blim"), expectFalse("bm"),
+ expectTrue(""), expectTrue("blimmo"), expectTrue("mmm"),
+
+ "A like 'b_m'",
+ expectTrue("bim"), expectFalse("blim"),
+
+ "A like '%can''t%'",
+ expectTrue("can't"),
+ expectTrue("I'm sorry Dave, I'm afraid I can't do that"),
+ expectFalse("cant"), expectFalse("can''t"),
+
+ "A like '\\%%\\%'",
+ expectTrue("%blim%"), expectTrue("%%"),
+ expectFalse("blim"), expectFalse("%asdf"), expectFalse("asdf%"),
+
+ "A LIKE '*%?_'",
+ expectTrue("*blim?!"), expectTrue("*?_"),
+ expectFalse("blim"), expectFalse("blim?"),
+ expectFalse("?*"), expectFalse("??"), expectFalse(""), expectFalse("?"),
+
+ Query.toString(
+ Query.initialSubString(Query.attr("A"), Query.value("*?%_"))),
+ expectTrue("*?%_tiddly"), expectTrue("*?%_"),
+ expectFalse("?%_tiddly"), expectFalse("*!%_"), expectFalse("*??_"),
+ expectFalse("*?%!"), expectFalse("*?%!tiddly"),
+
+ Query.toString(
+ Query.finalSubString(Query.attr("A"), Query.value("*?%_"))),
+ expectTrue("tiddly*?%_"), expectTrue("*?%_"),
+ expectFalse("tiddly?%_"), expectFalse("*!%_"), expectFalse("*??_"),
+ expectFalse("*?%!"), expectFalse("tiddly*?%!"),
+
+ // BETWEEN
+
+ "A between B and C",
+ expectTrue(1, 1, 2), expectTrue(2, 1, 2), expectTrue(2, 1, 3),
+ expectFalse(3, 1, 2), expectFalse(0, 1, 2), expectFalse(2, 3, 1),
+ expectTrue(1.0, 0.0, 2.0), expectFalse(2.0, 0.0, 1.0),
+ expectTrue(0.0, 0.0, 0.0), expectTrue(1.0, 0.0, 1.0),
+ expectTrue(1.0, 0.0, Double.POSITIVE_INFINITY),
+ expectFalse(1.0, Double.NEGATIVE_INFINITY, 0.0),
+ expectFalse(false, false, true), expectFalse(true, false, true),
+ expectTrue("jim", "fred", "sheila"), expectFalse("fred", "jim", "sheila"),
+
+ "A between B and C and 1+2=3",
+ expectTrue(2, 1, 3), expectFalse(2, 3, 1),
+
+ "A not between B and C",
+ expectTrue(1, 2, 3), expectFalse(2, 1, 3),
+
+ // IN
+
+ "A in (1, 2, 3)",
+ expectTrue(1), expectTrue(2), expectTrue(3),
+ expectFalse(0), expectFalse(4),
+
+ "A in (1)",
+ expectTrue(1), expectFalse(0),
+
+ "A in (1.2, 3.4)",
+ expectTrue(1.2), expectTrue(3.4), expectFalse(0.0),
+
+ "A in ('foo', 'bar')",
+ expectTrue("foo"), expectTrue("bar"), expectFalse("baz"),
+
+ "A in ('foo', 'bar') and 'bl'+'im'='blim'",
+ expectTrue("foo"), expectTrue("bar"), expectFalse("baz"),
+
+ "A in (B, C, D)", // requires fix for CR 6604768
+ expectTrue(1, 1, 2, 3), expectFalse(1, 2, 3, 4),
+
+ "A not in (B, C, D)",
+ expectTrue(1, 2, 3, 4), expectFalse(1, 1, 2, 3),
+
+ // QUOTING
+
+ "\"LIKE\" = 1 and \"NOT\" = 2 and \"INSTANCEOF\" = 3 and " +
+ "\"TRUE\" = 4 and \"FALSE\" = 5",
+ newTester(
+ new String[] {"LIKE", "NOT", "INSTANCEOF", "TRUE", "FALSE"},
+ new Object[] {1, 2, 3, 4, 5},
+ true),
+ newTester(
+ new String[] {"LIKE", "NOT", "INSTANCEOF", "TRUE", "FALSE"},
+ new Object[] {5, 4, 3, 2, 1},
+ false),
+
+ "\"\"\"woo\"\"\" = 5",
+ newTester(new String[] {"\"woo\""}, new Object[] {5}, true),
+ newTester(new String[] {"\"woo\""}, new Object[] {4}, false),
+ expectFalse(),
+
+ // INSTANCEOF
+
+ "instanceof '" + Tester.class.getName() + "'",
+ expectTrue(),
+
+ "instanceof '" + String.class.getName() + "'",
+ expectFalse(),
+
+ // LIKE OBJECTNAME
+
+ // The test MBean is registered as a:b=c
+ "like 'a:b=c'", expectTrue(),
+ "like 'a:*'", expectTrue(),
+ "like '*:b=c'", expectTrue(),
+ "like 'a:b=*'", expectTrue(),
+ "like 'a:b=?'", expectTrue(),
+ "like 'd:b=c'", expectFalse(),
+ "like 'a:b=??*'", expectFalse(),
+ "like 'a:b=\"can''t\"'", expectFalse(),
+
+ // QUALIFIED ATTRIBUTE
+
+ Tester.class.getName() + "#A = 5",
+ expectTrue(5), expectFalse(4),
+
+ Tester.class.getName() + " # A = 5",
+ expectTrue(5), expectFalse(4),
+
+ Tester.class.getSuperclass().getName() + "#A = 5",
+ expectFalse(5),
+
+ DynamicMBean.class.getName() + "#A = 5",
+ expectFalse(5),
+
+ Tester.class.getName() + "#A = 5",
+ new Tester(new String[] {"A"}, new Object[] {5}, false) {},
+ // note the little {} at the end which means this is a subclass
+ // and therefore QualifiedAttributeValue should return false.
+
+ MBeanServerDelegate.class.getName() + "#SpecificationName LIKE '%'",
+ new Wrapped(new MBeanServerDelegate(), true),
+ new Tester(new String[] {"SpecificationName"}, new Object[] {"JMX"}, false),
+
+ // DOTTED ATTRIBUTE
+
+ "A.canonicalName = '" +
+ MBeanServerDelegate.DELEGATE_NAME.getCanonicalName() + "'",
+ expectTrue(MBeanServerDelegate.DELEGATE_NAME),
+ expectFalse(ObjectName.WILDCARD),
+
+ "A.class.name = 'java.lang.String'",
+ expectTrue("blim"), expectFalse(95), expectFalse((Object) null),
+
+ "A.canonicalName like 'JMImpl%:%'",
+ expectTrue(MBeanServerDelegate.DELEGATE_NAME),
+ expectFalse(ObjectName.WILDCARD),
+
+ "A.true = 'blim'",
+ new Tester(new String[] {"A.true"}, new Object[] {"blim"}, true),
+ new Tester(new String[] {"A.true"}, new Object[] {"blam"}, false),
+
+ "\"A.true\" = 'blim'",
+ new Tester(new String[] {"A.true"}, new Object[] {"blim"}, true),
+ new Tester(new String[] {"A.true"}, new Object[] {"blam"}, false),
+
+ MBeanServerDelegate.class.getName() +
+ "#SpecificationName.class.name = 'java.lang.String'",
+ new Wrapped(new MBeanServerDelegate(), true),
+ new Tester(new String[] {"SpecificationName"}, new Object[] {"JMX"}, false),
+
+ MBeanServerDelegate.class.getName() +
+ " # SpecificationName.class.name = 'java.lang.String'",
+ new Wrapped(new MBeanServerDelegate(), true),
+ new Tester(new String[] {"SpecificationName"}, new Object[] {"JMX"}, false),
+
+ // CLASS
+
+ "class = '" + Tester.class.getName() + "'",
+ expectTrue(),
+ new Wrapped(new MBeanServerDelegate(), false),
+
+ "Class = '" + Tester.class.getName() + "'",
+ expectTrue(),
+ new Wrapped(new MBeanServerDelegate(), false),
+ };
+
+ private static final String[] incorrectQueries = {
+ "", " ", "25", "()", "(a = b", "a = b)", "a.3 = 5",
+ "a = " + Long.MAX_VALUE + "0",
+ "a = " + Double.MAX_VALUE + "0",
+ "a = " + Double.MIN_VALUE + "0",
+ "a = 12a5", "a = 12e5e5", "a = 12.23.34",
+ "a = 'can't'", "a = 'unterminated", "a = 'asdf''",
+ "a = \"oops", "a = \"oops\"\"",
+ "a like 5", "true or false",
+ "a ! b", "? = 3", "a = @", "a##b",
+ "a between b , c", "a between and c",
+ "a in b, c", "a in 23", "a in (2, 3", "a in (2, 3x)",
+ "a like \"foo\"", "a like b", "a like 23",
+ "like \"foo\"", "like b", "like 23", "like 'a:b'",
+ "5 like 'a'", "'a' like '%'",
+ "a not= b", "a not = b", "a not b", "a not b c",
+ "a = +b", "a = +'b'", "a = +true", "a = -b", "a = -'b'",
+ "a#5 = b", "a#'b' = c",
+ "a instanceof b", "a instanceof 17", "a instanceof",
+ "a like 'oops\\'", "a like '[oops'",
+
+ // Check that -Long.MIN_VALUE is an illegal constant. This is one more
+ // than Long.MAX_VALUE and, like the Java language, we only allow it
+ // if it is the operand of unary minus.
+ "a = " + Long.toString(Long.MIN_VALUE).substring(1),
+ };
+
+ public static void main(String[] args) throws Exception {
+ int nexti;
+ String failed = null;
+
+ System.out.println("TESTING CORRECT QUERY STRINGS");
+ for (int i = 0; i < queryTests.length; i = nexti) {
+ for (nexti = i + 1; nexti < queryTests.length; nexti++) {
+ if (queryTests[nexti] instanceof String)
+ break;
+ }
+ if (!(queryTests[i] instanceof String))
+ throw new Exception("Test bug: should be string: " + queryTests[i]);
+
+ String qs = (String) queryTests[i];
+ System.out.println("Test: " + qs);
+
+ QueryExp qe = Query.fromString(qs);
+ String qes = Query.toString(qe);
+ System.out.println("...parses to: " + qes);
+ final QueryExp[] queries;
+ if (qes.equals(qs))
+ queries = new QueryExp[] {qe};
+ else {
+ QueryExp qe2 = Query.fromString(qes);
+ String qes2 = Query.toString(qe2);
+ System.out.println("...which parses to: " + qes2);
+ if (qes.equals(qes2))
+ queries = new QueryExp[] {qe};
+ else
+ queries = new QueryExp[] {qe, qe2};
+ }
+
+ for (int j = i + 1; j < nexti; j++) {
+ Object mbean;
+ if (queryTests[j] instanceof Wrapped)
+ mbean = ((Wrapped) queryTests[j]).mbean();
+ else
+ mbean = queryTests[j];
+ boolean expect = ((ExpectedValue) queryTests[j]).expectedValue();
+ for (QueryExp qet : queries) {
+ boolean actual = runQuery(qet, mbean);
+ boolean ok = (expect == actual);
+ System.out.println(
+ "..." + mbean + " -> " + actual +
+ (ok ? " (OK)" : " ####INCORRECT####"));
+ if (!ok)
+ failed = qs;
+ }
+ }
+ }
+
+ System.out.println();
+ System.out.println("TESTING INCORRECT QUERY STRINGS");
+ for (String s : incorrectQueries) {
+ try {
+ QueryExp qe = Query.fromString(s);
+ System.out.println("###DID NOT GET ERROR:### \"" + s + "\"");
+ failed = s;
+ } catch (IllegalArgumentException e) {
+ String es = (e.getClass() == IllegalArgumentException.class) ?
+ e.getMessage() : e.toString();
+ System.out.println("OK: exception for \"" + s + "\": " + es);
+ }
+ }
+
+ if (failed == null)
+ System.out.println("TEST PASSED");
+ else
+ throw new Exception("TEST FAILED: Last failure: " + failed);
+ }
+
+ private static boolean runQuery(QueryExp qe, Object mbean)
+ throws Exception {
+ MBeanServer mbs = MBeanServerFactory.newMBeanServer();
+ ObjectName name = new ObjectName("a:b=c");
+ mbs.registerMBean(mbean, name);
+ Set names = mbs.queryNames(new ObjectName("a:*"), qe);
+ if (names.isEmpty())
+ return false;
+ if (names.equals(Collections.singleton(name)))
+ return true;
+ throw new Exception("Unexpected query result set: " + names);
+ }
+
+ private static interface ExpectedValue {
+ public boolean expectedValue();
+ }
+
+ private static class Wrapped implements ExpectedValue {
+ private final Object mbean;
+ private final boolean expect;
+
+ Wrapped(Object mbean, boolean expect) {
+ this.mbean = mbean;
+ this.expect = expect;
+ }
+
+ Object mbean() {
+ return mbean;
+ }
+
+ public boolean expectedValue() {
+ return expect;
+ }
+ }
+
+ private static class Tester implements DynamicMBean, ExpectedValue {
+ private final AttributeList attributes;
+ private final boolean expectedValue;
+
+ Tester(AttributeList attributes, boolean expectedValue) {
+ this.attributes = attributes;
+ this.expectedValue = expectedValue;
+ }
+
+ Tester(String[] names, Object[] values, boolean expectedValue) {
+ this(makeAttributeList(names, values), expectedValue);
+ }
+
+ private static AttributeList makeAttributeList(
+ String[] names, Object[] values) {
+ if (names.length != values.length)
+ throw new Error("Test bug: names and values different length");
+ AttributeList list = new AttributeList();
+ for (int i = 0; i < names.length; i++)
+ list.add(new Attribute(names[i], values[i]));
+ return list;
+ }
+
+ public Object getAttribute(String attribute)
+ throws AttributeNotFoundException {
+ for (Attribute a : attributes.asList()) {
+ if (a.getName().equals(attribute))
+ return a.getValue();
+ }
+ throw new AttributeNotFoundException(attribute);
+ }
+
+ public void setAttribute(Attribute attribute) {
+ throw new UnsupportedOperationException();
+ }
+
+ public AttributeList getAttributes(String[] attributes) {
+ AttributeList list = new AttributeList();
+ for (String attribute : attributes) {
+ try {
+ list.add(new Attribute(attribute, getAttribute(attribute)));
+ } catch (AttributeNotFoundException e) {
+ // OK: ignore, per semantics of getAttributes
+ }
+ }
+ return list;
+ }
+
+ public AttributeList setAttributes(AttributeList attributes) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object invoke(String actionName, Object[] params, String[] signature) {
+ throw new UnsupportedOperationException();
+ }
+
+ public MBeanInfo getMBeanInfo() {
+ MBeanAttributeInfo mbais[] = new MBeanAttributeInfo[attributes.size()];
+ for (int i = 0; i < mbais.length; i++) {
+ Attribute attr = attributes.asList().get(i);
+ String name = attr.getName();
+ Object value = attr.getValue();
+ String type =
+ ((value == null) ? new Object() : value).getClass().getName();
+ mbais[i] = new MBeanAttributeInfo(
+ name, type, name, true, false, false);
+ }
+ return new MBeanInfo(
+ getClass().getName(), "descr", mbais, null, null, null);
+ }
+
+ public boolean expectedValue() {
+ return expectedValue;
+ }
+
+ @Override
+ public String toString() {
+ return attributes.toString();
+ }
+ }
+
+ // Method rather than field, to avoid circular init dependencies
+ private static String[] abcd() {
+ return new String[] {"A", "B", "C", "D"};
+ }
+
+ private static String[] onetwo() {
+ return new String[] {"One", "two"};
+ }
+
+ private static Object expectTrue(Object... attrs) {
+ return newTester(abcd(), attrs, true);
+ }
+
+ private static Object expectFalse(Object... attrs) {
+ return newTester(abcd(), attrs, false);
+ }
+
+ private static Object expectTrueOneTwo(Object... attrs) {
+ return newTester(onetwo(), attrs, true);
+ }
+
+ private static Object expectFalseOneTwo(Object... attrs) {
+ return newTester(onetwo(), attrs, false);
+ }
+
+ private static Object newTester(String[] names, Object[] attrs, boolean expect) {
+ AttributeList list = new AttributeList();
+ for (int i = 0; i < attrs.length; i++)
+ list.add(new Attribute(names[i], attrs[i]));
+ return new Tester(list, expect);
+ }
+}
From c79ec66f1a02102662783fa610b3f769574147fd Mon Sep 17 00:00:00 2001
From: Daniel Fuchs
Date: Mon, 3 Mar 2008 12:29:42 +0100
Subject: [PATCH 014/126] 6651382: The Java JVM SNMP provider reports incorrect
stats when asked for multiple OIDs
The JvmMemPoolEntryImpl must use the row index when caching data.
Reviewed-by: jfdenise
---
.../snmp/jvminstr/JvmMemPoolEntryImpl.java | 32 ++++++++++---------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemPoolEntryImpl.java b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemPoolEntryImpl.java
index 156813969f9..0863148f916 100644
--- a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemPoolEntryImpl.java
+++ b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemPoolEntryImpl.java
@@ -26,7 +26,6 @@ package sun.management.snmp.jvminstr;
// java imports
//
-import java.io.Serializable;
import java.util.Map;
// jmx imports
@@ -36,9 +35,7 @@ import com.sun.jmx.snmp.SnmpDefinitions;
// jdmk imports
//
-import com.sun.jmx.snmp.agent.SnmpMib;
-import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;
import java.lang.management.MemoryType;
import java.lang.management.MemoryPoolMXBean;
@@ -73,7 +70,9 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean {
"jvmMemPoolEntry.getCollectionUsage";
final static MemoryUsage ZEROS = new MemoryUsage(0,0,0,0);
-
+ final String entryMemoryTag;
+ final String entryPeakMemoryTag;
+ final String entryCollectMemoryTag;
MemoryUsage getMemoryUsage() {
try {
@@ -81,17 +80,17 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean {
if (m != null) {
final MemoryUsage cached = (MemoryUsage)
- m.get(memoryTag);
+ m.get(entryMemoryTag);
if (cached != null) {
- log.debug("getMemoryUsage",
- "jvmMemPoolEntry.getUsage found in cache.");
+ log.debug("getMemoryUsage",entryMemoryTag+
+ " found in cache.");
return cached;
}
MemoryUsage u = pool.getUsage();
if (u == null) u = ZEROS;
- m.put(memoryTag,u);
+ m.put(entryMemoryTag,u);
return u;
}
// Should never come here.
@@ -113,18 +112,18 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean {
if (m != null) {
final MemoryUsage cached = (MemoryUsage)
- m.get(peakMemoryTag);
+ m.get(entryPeakMemoryTag);
if (cached != null) {
if (log.isDebugOn())
log.debug("getPeakMemoryUsage",
- peakMemoryTag + " found in cache.");
+ entryPeakMemoryTag + " found in cache.");
return cached;
}
MemoryUsage u = pool.getPeakUsage();
if (u == null) u = ZEROS;
- m.put(peakMemoryTag,u);
+ m.put(entryPeakMemoryTag,u);
return u;
}
// Should never come here.
@@ -146,18 +145,18 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean {
if (m != null) {
final MemoryUsage cached = (MemoryUsage)
- m.get(collectMemoryTag);
+ m.get(entryCollectMemoryTag);
if (cached != null) {
if (log.isDebugOn())
log.debug("getCollectMemoryUsage",
- collectMemoryTag + " found in cache.");
+ entryCollectMemoryTag + " found in cache.");
return cached;
}
MemoryUsage u = pool.getCollectionUsage();
if (u == null) u = ZEROS;
- m.put(collectMemoryTag,u);
+ m.put(entryCollectMemoryTag,u);
return u;
}
// Should never come here.
@@ -179,9 +178,12 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean {
/**
* Constructor for the "JvmMemPoolEntry" group.
*/
- public JvmMemPoolEntryImpl(MemoryPoolMXBean mp, int index) {
+ public JvmMemPoolEntryImpl(MemoryPoolMXBean mp, final int index) {
this.pool=mp;
this.jvmMemPoolIndex = index;
+ this.entryMemoryTag = memoryTag + "." + index;
+ this.entryPeakMemoryTag = peakMemoryTag + "." + index;
+ this.entryCollectMemoryTag = collectMemoryTag + "." + index;
}
/**
From 8736cd2d59fd43897d5ced19df13bd6dac97923e Mon Sep 17 00:00:00 2001
From: Eamonn McManus
Date: Mon, 3 Mar 2008 15:28:40 +0100
Subject: [PATCH 015/126] 6607114: Make JMXServiceURL reconstructible in
MXBeans
Add @ConstructorProperties tag to JMXServiceURL
Reviewed-by: dfuchs
---
jdk/src/share/classes/javax/management/remote/JMXServiceURL.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/jdk/src/share/classes/javax/management/remote/JMXServiceURL.java b/jdk/src/share/classes/javax/management/remote/JMXServiceURL.java
index 5d5c799774e..774f21441a6 100644
--- a/jdk/src/share/classes/javax/management/remote/JMXServiceURL.java
+++ b/jdk/src/share/classes/javax/management/remote/JMXServiceURL.java
@@ -274,6 +274,7 @@ public class JMXServiceURL implements Serializable {
* is not possible to find the local host name, or if
* port is negative.
*/
+ @ConstructorProperties({"protocol", "host", "port", "URLPath"})
public JMXServiceURL(String protocol, String host, int port,
String urlPath)
throws MalformedURLException {
From 5cd758db4c9631984e20ef2fd32c27643476bad8 Mon Sep 17 00:00:00 2001
From: Eamonn McManus
Date: Mon, 3 Mar 2008 15:44:50 +0100
Subject: [PATCH 016/126] 6670375: Missing unit test for 6607114 (Make
JMXServiceURL reconstructible)
Current setup doesn't allow two pushes with same CR number
Reviewed-by: dfuchs
---
.../management/remote/JMXServiceURL.java | 1 +
.../management/mxbean/JMXServiceURLTest.java | 103 ++++++++++++++++++
2 files changed, 104 insertions(+)
create mode 100644 jdk/test/javax/management/mxbean/JMXServiceURLTest.java
diff --git a/jdk/src/share/classes/javax/management/remote/JMXServiceURL.java b/jdk/src/share/classes/javax/management/remote/JMXServiceURL.java
index 774f21441a6..3211c902b47 100644
--- a/jdk/src/share/classes/javax/management/remote/JMXServiceURL.java
+++ b/jdk/src/share/classes/javax/management/remote/JMXServiceURL.java
@@ -30,6 +30,7 @@ package javax.management.remote;
import com.sun.jmx.remote.util.ClassLogger;
import com.sun.jmx.remote.util.EnvHelp;
+import java.beans.ConstructorProperties;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.MalformedURLException;
diff --git a/jdk/test/javax/management/mxbean/JMXServiceURLTest.java b/jdk/test/javax/management/mxbean/JMXServiceURLTest.java
new file mode 100644
index 00000000000..dc796037c35
--- /dev/null
+++ b/jdk/test/javax/management/mxbean/JMXServiceURLTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test JMXServiceURLTest
+ * @bug 6607114 6670375
+ * @summary Test that JMXServiceURL works correctly in MXBeans
+ * @author Eamonn McManus
+ */
+
+import java.lang.management.ManagementFactory;
+import javax.management.JMX;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+import javax.management.remote.JMXServiceURL;
+
+public class JMXServiceURLTest {
+ public static interface UrlMXBean {
+ public JMXServiceURL getUrl();
+ public void setUrl(JMXServiceURL url);
+ }
+
+ public static class UrlImpl implements UrlMXBean {
+ volatile JMXServiceURL url;
+
+ public JMXServiceURL getUrl() {
+ return url;
+ }
+
+ public void setUrl(JMXServiceURL url) {
+ this.url = url;
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ ObjectName name = new ObjectName("a:b=c");
+ UrlImpl urlImpl = new UrlImpl();
+ mbs.registerMBean(urlImpl, name);
+
+ JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://host:8000/noddy");
+ UrlMXBean proxy = JMX.newMXBeanProxy(mbs, name, UrlMXBean.class);
+ proxy.setUrl(url);
+ assertEquals(url, urlImpl.url);
+ JMXServiceURL url2 = proxy.getUrl();
+ assertEquals(url, url2);
+
+ CompositeData cd = (CompositeData) mbs.getAttribute(name, "Url");
+ CompositeType ct = cd.getCompositeType();
+ // Make sure it looks like what we expect. This will have to be
+ // changed if ever we add new properties to CompositeType. In that
+ // case this test should also check interoperability between the
+ // current version and the new version.
+ assertEquals(4, ct.keySet().size());
+ Object[][] expectedItems = {
+ {"protocol", SimpleType.STRING, "rmi"},
+ {"host", SimpleType.STRING, "host"},
+ {"port", SimpleType.INTEGER, 8000},
+ {"URLPath", SimpleType.STRING, "/noddy"},
+ };
+ for (Object[] expectedItem : expectedItems) {
+ String itemName = (String) expectedItem[0];
+ OpenType expectedType = (OpenType) expectedItem[1];
+ Object expectedValue = expectedItem[2];
+ OpenType actualType = ct.getType(itemName);
+ assertEquals(expectedType, actualType);
+ Object actualValue = cd.get(itemName);
+ assertEquals(expectedValue, actualValue);
+ }
+ }
+
+ private static void assertEquals(Object expect, Object actual)
+ throws Exception {
+ if (expect.equals(actual))
+ System.out.println("Equal: " + expect);
+ else
+ throw new Exception("Expected " + expect + ", got " + actual);
+ }
+}
From 6797bd9fb23a0be3f574378fc6829e815a913849 Mon Sep 17 00:00:00 2001
From: Chris Hegarty
Date: Tue, 4 Mar 2008 17:09:09 +0000
Subject: [PATCH 017/126] 6638560: APPCRASH in
"SPNEGO_HTTP_AUTH/PROXY_FALLBACK" test case with 64 bit JDK on Win2008 x64,
VinVista x64
Remove incorrect free from native code
Reviewed-by: jccollet
---
.../sun/net/www/protocol/http/NTLMAuthSequence.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c b/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c
index 29c0a2b3b70..4d4e56ee807 100644
--- a/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c
+++ b/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c
@@ -52,7 +52,7 @@ static INITIALIZE_SECURITY_CONTEXT_FN pInitializeSecurityContext;
static COMPLETE_AUTH_TOKEN_FN pCompleteAuthToken;
static DELETE_SECURITY_CONTEXT_FN pDeleteSecurityContext;
-static void endSequence (PCredHandle credHand, PCtxtHandle ctxHandle, SecBufferDesc OutBuffDesc);
+static void endSequence (PCredHandle credHand, PCtxtHandle ctxHandle);
static jfieldID ntlm_ctxHandleID;
static jfieldID ntlm_crdHandleID;
@@ -247,7 +247,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_get
}
if (ss < 0) {
- endSequence (pCred, pCtx, OutBuffDesc);
+ endSequence (pCred, pCtx);
return 0;
}
@@ -255,7 +255,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_get
ss = pCompleteAuthToken( pCtx, &OutBuffDesc );
if (ss < 0) {
- endSequence (pCred, pCtx, OutBuffDesc);
+ endSequence (pCred, pCtx);
return 0;
}
}
@@ -265,25 +265,23 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_get
(*env)->SetByteArrayRegion(env, ret, 0, OutSecBuff.cbBuffer,
OutSecBuff.pvBuffer);
if (lastToken != 0) // 2nd stage
- endSequence (pCred, pCtx, OutBuffDesc);
+ endSequence (pCred, pCtx);
result = ret;
}
if ((ss != SEC_I_CONTINUE_NEEDED) && (ss == SEC_I_COMPLETE_AND_CONTINUE)) {
- endSequence (pCred, pCtx, OutBuffDesc);
+ endSequence (pCred, pCtx);
}
return result;
}
-static void endSequence (PCredHandle credHand, PCtxtHandle ctxHandle, SecBufferDesc OutBuffDesc) {
+static void endSequence (PCredHandle credHand, PCtxtHandle ctxHandle) {
if (credHand != 0) {
pFreeCredentialsHandle (credHand);
free (credHand);
}
- pFreeContextBuffer (&OutBuffDesc);
-
if (ctxHandle != 0) {
pDeleteSecurityContext(ctxHandle);
free (ctxHandle);
From e467c731a73a22b867cf4b5066b25712a04aa888 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Tue, 4 Mar 2008 09:47:43 -0800
Subject: [PATCH 018/126] 6654456: OpenJDK build problem with freetype
makefiles
Ifdef test on OPENJDK before it gets set based on source tree contents
Reviewed-by: xdono
---
jdk/make/common/shared/Platform.gmk | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/jdk/make/common/shared/Platform.gmk b/jdk/make/common/shared/Platform.gmk
index f9f229a8548..915454a940c 100644
--- a/jdk/make/common/shared/Platform.gmk
+++ b/jdk/make/common/shared/Platform.gmk
@@ -93,10 +93,8 @@ SYSTEM_UNAME := $(shell uname)
# Normal boot jdk is previous release, but a hard requirement is a 1.5 boot
REQUIRED_BOOT_VER = 1.5
-#This is specific to OpenJDK build
-ifdef OPENJDK
- REQUIRED_FREETYPE_VERSION=2.3.0
-endif
+# If we are using freetype, this is the required version
+REQUIRED_FREETYPE_VERSION=2.3.0
#
# Prune out all known SCM (Source Code Management) directories
From 05b8e8fbfdca459acffbf2b94c927db5651fafa7 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Tue, 4 Mar 2008 09:49:22 -0800
Subject: [PATCH 019/126] 6637583: Build failure on latest Solaris, source
missing include of resource.h?
The include of sys/resource.h must be explicit
Reviewed-by: xdono
---
jdk/src/solaris/hpi/native_threads/src/sys_api_td.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/jdk/src/solaris/hpi/native_threads/src/sys_api_td.c b/jdk/src/solaris/hpi/native_threads/src/sys_api_td.c
index 37b098aae43..c61324a4d0f 100644
--- a/jdk/src/solaris/hpi/native_threads/src/sys_api_td.c
+++ b/jdk/src/solaris/hpi/native_threads/src/sys_api_td.c
@@ -63,15 +63,8 @@
#define CLOSEIO
#endif /* NO_INTERRUPTIBLE_IO */
-/*
- * Linux does not define rlim_t (solaris
- * does). THIS IS PROBABLY NOT THE RIGHT THING TO DO, so
- * somebody please fix this.
- */
-#ifdef __linux__
-typedef int rlim_t ;
-#endif
-
+/* Get typedef for rlim_t */
+#include
#ifdef CLOSEIO
From 962e1ab78eaf27a94f0ad1c68abb558a4ae158b6 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Tue, 4 Mar 2008 09:50:30 -0800
Subject: [PATCH 020/126] 6638571: Fix freetype sanity check to work on solaris
64bit
Missing -xarch options to build for 64bit
Reviewed-by: xdono
---
jdk/make/tools/freetypecheck/Makefile | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/jdk/make/tools/freetypecheck/Makefile b/jdk/make/tools/freetypecheck/Makefile
index c2a3e644ba7..7bcfe6300c1 100644
--- a/jdk/make/tools/freetypecheck/Makefile
+++ b/jdk/make/tools/freetypecheck/Makefile
@@ -38,7 +38,14 @@ FT_TEST_PATH = $(TEMPDIR)/$(FT_TEST)
all: $(FT_TEST_PATH)
-FT_OPTIONS = -I$(FT_HEADERS) -I$(FT_HEADERS)/freetype2
+# Start with CFLAGS (which gets us the required -xarch setting on solaris)
+ifeq ($(PLATFORM), windows)
+ FT_OPTIONS =
+else
+ FT_OPTIONS = $(CFLAGS)
+endif
+
+FT_OPTIONS += -I$(FT_HEADERS) -I$(FT_HEADERS)/freetype2
FT_OPTIONS += $(XARCH)
#add runtime library search path
From c13218442ae82fdf73b658e2b3889fdeae134736 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Tue, 4 Mar 2008 09:51:25 -0800
Subject: [PATCH 021/126] 6638060: Build failed with GNU make 3.81 (part of
latest Solaris 'gmake')
Changes to the way GNU make 3.81 deals with the env variable SHELL
Reviewed-by: xdono
---
jdk/make/java/nio/Makefile | 10 +++++-----
jdk/make/java/nio/genCharsetProvider.sh | 2 +-
jdk/make/java/nio/genExceptions.sh | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/jdk/make/java/nio/Makefile b/jdk/make/java/nio/Makefile
index 98a838831a2..0a9070f8257 100644
--- a/jdk/make/java/nio/Makefile
+++ b/jdk/make/java/nio/Makefile
@@ -191,7 +191,7 @@ sources: $(SPP) $(FILES_genout)
GEN_BUFFER_SH = genBuffer.sh
-GEN_BUFFER_CMD = SPP="$(SPP_CMD)" NAWK=$(NAWK) SED=$(SED) \
+GEN_BUFFER_CMD = SPP="$(SPP_CMD)" NAWK=$(NAWK) SED=$(SED) SH=$(SH) \
$(SH) $(GEN_BUFFER_SH)
# Public abstract buffer classes
@@ -582,7 +582,7 @@ $(BUF_GEN)/ByteBufferAsDoubleBuffer%L.java: $(BUF_SRC)/ByteBufferAs-X-Buffer.jav
GEN_CODER_SH = genCoder.sh
-GEN_CODER_CMD = SPP="$(SPP_CMD)" SED=$(SED) NAWK=$(NAWK) $(SH) $(GEN_CODER_SH)
+GEN_CODER_CMD = SPP="$(SPP_CMD)" SED=$(SED) NAWK=$(NAWK) SH=$(SH) $(SH) $(GEN_CODER_SH)
$(CS_GEN)/CharsetDecoder.java: $(CS_SRC)/Charset-X-Coder.java $(GEN_CODER_SH)
$(prep-target)
@@ -602,7 +602,7 @@ $(CS_GEN)/CharsetEncoder.java: $(CS_SRC)/Charset-X-Coder.java $(GEN_CODER_SH)
GEN_EX_SH = genExceptions.sh
-GEN_EX_CMD = NAWK=$(NAWK) $(SHELL) $(GEN_EX_SH)
+GEN_EX_CMD = NAWK=$(NAWK) SH=$(SH) $(SH) $(GEN_EX_SH)
$(CH_GEN)/%Exception.java: genExceptions.sh $(CH_SRC)/exceptions
$(prep-target)
@@ -635,8 +635,8 @@ $(SCS_GEN)/StandardCharsets.java: genCharsetProvider.sh \
$(HASHER_JARFILE) $(SCS_SRC)/standard-charsets
$(prep-target)
@$(RM) $@.temp
- NAWK=$(NAWK) TEMPDIR=$(TEMPDIR) \
+ NAWK=$(NAWK) TEMPDIR=$(TEMPDIR) SH=$(SH) \
HASHER="$(BOOT_JAVA_CMD) -jar $(HASHER_JARFILE)" \
- $(SHELL) -e genCharsetProvider.sh $(SCS_SRC)/standard-charsets $(SCS_GEN)
+ $(SH) -e genCharsetProvider.sh $(SCS_SRC)/standard-charsets $(SCS_GEN)
.PHONY: sources
diff --git a/jdk/make/java/nio/genCharsetProvider.sh b/jdk/make/java/nio/genCharsetProvider.sh
index 1c344dacabd..574722fb4a9 100644
--- a/jdk/make/java/nio/genCharsetProvider.sh
+++ b/jdk/make/java/nio/genCharsetProvider.sh
@@ -48,7 +48,7 @@ echo '-->' $OUT
# Header
#
-$SHELL addNotices.sh "$COPYRIGHT_YEARS" > $OUT
+$SH ./addNotices.sh "$COPYRIGHT_YEARS" > $OUT
cat <<__END__ >>$OUT
diff --git a/jdk/make/java/nio/genExceptions.sh b/jdk/make/java/nio/genExceptions.sh
index 0e2020c2c1f..2de5e9cd784 100644
--- a/jdk/make/java/nio/genExceptions.sh
+++ b/jdk/make/java/nio/genExceptions.sh
@@ -41,7 +41,7 @@ gen() {
echo '-->' $DST/$ID.java
out=$DST/${ID}.java
- $SHELL addNotices.sh "$COPYRIGHT_YEARS" > $out
+ $SH ./addNotices.sh "$COPYRIGHT_YEARS" > $out
cat >>$out <<__END__
From 4b49c996b425daeee0dfc07f2b677bc394b4ede7 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Tue, 4 Mar 2008 09:52:54 -0800
Subject: [PATCH 022/126] 6668781: Openjdk windows cygwin build failure: no
rule to make linker_md.obj target
Use of GNU make vpath breaks on windows with C:/ style fullpaths
Reviewed-by: xdono
---
jdk/make/common/Defs-linux.gmk | 4 ++--
jdk/make/common/Defs-solaris.gmk | 4 ++--
jdk/make/common/Defs-windows.gmk | 6 +++---
jdk/make/common/Defs.gmk | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/jdk/make/common/Defs-linux.gmk b/jdk/make/common/Defs-linux.gmk
index 51d638f96ab..674b6f6a0e6 100644
--- a/jdk/make/common/Defs-linux.gmk
+++ b/jdk/make/common/Defs-linux.gmk
@@ -50,13 +50,13 @@ CC_DEPEND = -MM
CC_DEPEND_FILTER = $(SED) -e 's!$*\.$(OBJECT_SUFFIX)!$(dir $@)& $(dir $@)$*.$(DEPEND_SUFFIX)!g'
ifndef PLATFORM_SRC
- PLATFORM_SRC = $(JDK_TOPDIR)/src/solaris
+ PLATFORM_SRC = $(BUILDDIR)/../src/solaris
endif # PLATFORM_SRC
# Platform specific closed sources
ifndef OPENJDK
ifndef CLOSED_PLATFORM_SRC
- CLOSED_PLATFORM_SRC = $(JDK_TOPDIR)/src/closed/solaris
+ CLOSED_PLATFORM_SRC = $(BUILDDIR)/../src/closed/solaris
endif
endif
diff --git a/jdk/make/common/Defs-solaris.gmk b/jdk/make/common/Defs-solaris.gmk
index 800c0b75ddb..052c0c88fc8 100644
--- a/jdk/make/common/Defs-solaris.gmk
+++ b/jdk/make/common/Defs-solaris.gmk
@@ -45,13 +45,13 @@
include $(JDK_MAKE_SHARED_DIR)/Defs.gmk
ifndef PLATFORM_SRC
-PLATFORM_SRC = $(JDK_TOPDIR)/src/solaris
+PLATFORM_SRC = $(BUILDDIR)/../src/solaris
endif # PLATFORM_SRC
# Platform specific closed sources
ifndef OPENJDK
ifndef CLOSED_PLATFORM_SRC
- CLOSED_PLATFORM_SRC = $(JDK_TOPDIR)/src/closed/solaris
+ CLOSED_PLATFORM_SRC = $(BUILDDIR)/../src/closed/solaris
endif
endif
diff --git a/jdk/make/common/Defs-windows.gmk b/jdk/make/common/Defs-windows.gmk
index 6f53eb72f3b..e9bdea85278 100644
--- a/jdk/make/common/Defs-windows.gmk
+++ b/jdk/make/common/Defs-windows.gmk
@@ -51,13 +51,13 @@ ifndef LIB_LOCATION
endif # LIB_LOCATION
ifndef PLATFORM_SRC
- PLATFORM_SRC = $(JDK_TOPDIR)/src/windows
+ PLATFORM_SRC = $(BUILDDIR)/../src/windows
endif # PLATFORM_SRC
# Platform specific closed sources
ifndef OPENJDK
ifndef CLOSED_PLATFORM_SRC
- CLOSED_PLATFORM_SRC = $(JDK_TOPDIR)/src/closed/windows
+ CLOSED_PLATFORM_SRC = $(BUILDDIR)/../src/closed/windows
endif
endif
@@ -367,7 +367,7 @@ else
endif
# Settings for the VERSIONINFO tap on windows.
-VERSIONINFO_RESOURCE = $(JDK_TOPDIR)/src/windows/resource/version.rc
+VERSIONINFO_RESOURCE = $(BUILDDIR)/../src/windows/resource/version.rc
ifneq ($(JDK_BUILD_NUMBER),)
COOKED_BUILD_NUMBER = $(shell $(ECHO) $(JDK_BUILD_NUMBER) | $(SED) -e 's/^b//' -e 's/^0//')
diff --git a/jdk/make/common/Defs.gmk b/jdk/make/common/Defs.gmk
index 9dd781b2f7e..6048744384e 100644
--- a/jdk/make/common/Defs.gmk
+++ b/jdk/make/common/Defs.gmk
@@ -59,13 +59,13 @@ include $(JDK_TOPDIR)/make/common/CancelImplicits.gmk
# there yet.
#
ifndef SHARE_SRC
- SHARE_SRC = $(JDK_TOPDIR)/src/share
+ SHARE_SRC = $(BUILDDIR)/../src/share
endif
# Files that cannot be included in the OpenJDK distribution are
# collected under a parent directory which contains just those files.
ifndef CLOSED_SRC
- CLOSED_SRC = $(JDK_TOPDIR)/src/closed
+ CLOSED_SRC = $(BUILDDIR)/../src/closed
endif
# If we have no closed directory, force it to an openjdk build
From 12028b6de1242f5e8f0c58c51099fd178559fd47 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Tue, 4 Mar 2008 10:58:04 -0800
Subject: [PATCH 023/126] 6652588: Fix broken JPRT makefile target, no bundle
saved
Jprt make rules missing the bundle up of the output
Reviewed-by: xdono
---
jaxp/make/Makefile | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/jaxp/make/Makefile b/jaxp/make/Makefile
index 9e72148a928..6de97e7e673 100644
--- a/jaxp/make/Makefile
+++ b/jaxp/make/Makefile
@@ -90,7 +90,6 @@ ifdef ALT_OUTPUTDIR
else
OUTPUTDIR = ..
endif
-ABS_OUTPUTDIR = $(call FullPath,$(OUTPUTDIR))
ifdef ALT_LANGTOOLS_DIST
ANT_OPTIONS += -Dbootstrap.dir=$(ALT_LANGTOOLS_DIST)/bootstrap
@@ -127,7 +126,11 @@ $(ANT_TARGETS):
$(ANT_JAVA_HOME) $(ANT) $(ANT_OPTIONS) $@
# Targets for Sun's internal JPRT build system
+JPRT_ARCHIVE_BUNDLE=$(OUTPUTDIR)/jprt.zip
jprt_build_product jprt_build_debug jprt_build_fastdebug: all
+ $(RM) $(JPRT_ARCHIVE_BUNDLE)
+ ( cd $(OUTPUTDIR)/dist && \
+ zip -q -r $(JPRT_ARCHIVE_BUNDLE) . )
# Declare these phony (not filenames)
.PHONY: $(ANT_TARGETS) all clobber \
From fc9ffa52c48ef8cf8549262cf92bf348f2389dde Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Tue, 4 Mar 2008 10:58:50 -0800
Subject: [PATCH 024/126] 6652588: Fix broken JPRT makefile target, no bundle
saved
Jprt make rules were missing the bundle logic
Reviewed-by: xdono
---
jaxws/make/Makefile | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/jaxws/make/Makefile b/jaxws/make/Makefile
index 3dab62bec74..3dc17bfa39f 100644
--- a/jaxws/make/Makefile
+++ b/jaxws/make/Makefile
@@ -69,7 +69,7 @@ else
endif
endif
-# Note: j2se/make/common/Defs.gmk uses LANGUAGE_VERSION (-source NN)
+# Note: jdk/make/common/Defs.gmk uses LANGUAGE_VERSION (-source NN)
# and the somewhat misnamed CLASS_VERSION (-target NN)
ifdef TARGET_CLASS_VERSION
ANT_OPTIONS += -Djavac.target=$(TARGET_CLASS_VERSION)
@@ -90,7 +90,6 @@ ifdef ALT_OUTPUTDIR
else
OUTPUTDIR = ..
endif
-ABS_OUTPUTDIR = $(call FullPath,$(OUTPUTDIR))
ifdef ALT_LANGTOOLS_DIST
ANT_OPTIONS += -Dbootstrap.dir=$(ALT_LANGTOOLS_DIST)/bootstrap
@@ -127,7 +126,11 @@ $(ANT_TARGETS):
$(ANT_JAVA_HOME) $(ANT) $(ANT_OPTIONS) $@
# Targets for Sun's internal JPRT build system
+JPRT_ARCHIVE_BUNDLE=$(OUTPUTDIR)/jprt.zip
jprt_build_product jprt_build_debug jprt_build_fastdebug: all
+ $(RM) $(JPRT_ARCHIVE_BUNDLE)
+ ( cd $(OUTPUTDIR)/dist && \
+ zip -q -r $(JPRT_ARCHIVE_BUNDLE) . )
# Declare these phony (not filenames)
.PHONY: $(ANT_TARGETS) all clobber \
From 0f960354ea2506d0c7daa4e90d1523d43c89c5ec Mon Sep 17 00:00:00 2001
From: Weijun Wang
Date: Wed, 5 Mar 2008 09:52:50 +0800
Subject: [PATCH 025/126] 6641312: Fix krb5 codes indentation problems
Reviewed-by: xuelei, valeriep, wetmore
---
.../classes/sun/security/krb5/KrbTgsReq.java | 194 ++--
.../sun/security/krb5/internal/APRep.java | 133 ++-
.../sun/security/krb5/internal/APReq.java | 160 +--
.../sun/security/krb5/internal/ASRep.java | 44 +-
.../sun/security/krb5/internal/ASReq.java | 23 +-
.../security/krb5/internal/Authenticator.java | 251 ++--
.../krb5/internal/AuthorizationData.java | 176 ++-
.../krb5/internal/AuthorizationDataEntry.java | 144 +--
.../security/krb5/internal/EncAPRepPart.java | 180 +--
.../security/krb5/internal/EncASRepPart.java | 94 +-
.../security/krb5/internal/EncKDCRepPart.java | 273 +++--
.../krb5/internal/EncKrbCredPart.java | 267 ++---
.../krb5/internal/EncKrbPrivPart.java | 197 ++--
.../security/krb5/internal/EncTGSRepPart.java | 91 +-
.../security/krb5/internal/EncTicketPart.java | 247 ++--
.../sun/security/krb5/internal/KDCRep.java | 294 ++---
.../sun/security/krb5/internal/KDCReq.java | 267 ++---
.../sun/security/krb5/internal/KRBCred.java | 214 ++--
.../security/krb5/internal/KrbCredInfo.java | 22 +-
.../krb5/internal/ccache/Credentials.java | 293 ++---
.../native/sun/security/krb5/NativeCreds.c | 1018 ++++++++---------
21 files changed, 2337 insertions(+), 2245 deletions(-)
diff --git a/jdk/src/share/classes/sun/security/krb5/KrbTgsReq.java b/jdk/src/share/classes/sun/security/krb5/KrbTgsReq.java
index 328e255e0d6..0cc54e17c45 100644
--- a/jdk/src/share/classes/sun/security/krb5/KrbTgsReq.java
+++ b/jdk/src/share/classes/sun/security/krb5/KrbTgsReq.java
@@ -75,107 +75,107 @@ public class KrbTgsReq extends KrbKdcReq {
null); // EncryptionKey subSessionKey
}
- // Called by Credentials, KrbCred
- KrbTgsReq(
- KDCOptions options,
- Credentials asCreds,
- PrincipalName sname,
- KerberosTime from,
- KerberosTime till,
- KerberosTime rtime,
- int[] eTypes,
- HostAddresses addresses,
- AuthorizationData authorizationData,
- Ticket[] additionalTickets,
- EncryptionKey subKey) throws KrbException, IOException {
+ // Called by Credentials, KrbCred
+ KrbTgsReq(
+ KDCOptions options,
+ Credentials asCreds,
+ PrincipalName sname,
+ KerberosTime from,
+ KerberosTime till,
+ KerberosTime rtime,
+ int[] eTypes,
+ HostAddresses addresses,
+ AuthorizationData authorizationData,
+ Ticket[] additionalTickets,
+ EncryptionKey subKey) throws KrbException, IOException {
- princName = asCreds.client;
- servName = sname;
- ctime = new KerberosTime(KerberosTime.NOW);
-
-
- // check if they are valid arguments. The optional fields
- // should be consistent with settings in KDCOptions.
- if (options.get(KDCOptions.FORWARDABLE) &&
- (!(asCreds.flags.get(Krb5.TKT_OPTS_FORWARDABLE)))) {
- throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
- }
- if (options.get(KDCOptions.FORWARDED)) {
- if (!(asCreds.flags.get(KDCOptions.FORWARDABLE)))
- throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
- }
- if (options.get(KDCOptions.PROXIABLE) &&
- (!(asCreds.flags.get(Krb5.TKT_OPTS_PROXIABLE)))) {
- throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
- }
- if (options.get(KDCOptions.PROXY)) {
- if (!(asCreds.flags.get(KDCOptions.PROXIABLE)))
- throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
- }
- if (options.get(KDCOptions.ALLOW_POSTDATE) &&
- (!(asCreds.flags.get(Krb5.TKT_OPTS_MAY_POSTDATE)))) {
- throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
- }
- if (options.get(KDCOptions.RENEWABLE) &&
- (!(asCreds.flags.get(Krb5.TKT_OPTS_RENEWABLE)))) {
- throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
- }
-
- if (options.get(KDCOptions.POSTDATED)) {
- if (!(asCreds.flags.get(KDCOptions.POSTDATED)))
- throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
- } else {
- if (from != null) from = null;
- }
- if (options.get(KDCOptions.RENEWABLE)) {
- if (!(asCreds.flags.get(KDCOptions.RENEWABLE)))
- throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
- } else {
- if (rtime != null) rtime = null;
- }
- if (options.get(KDCOptions.ENC_TKT_IN_SKEY)) {
- if (additionalTickets == null)
- throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
- // in TGS_REQ there could be more than one additional
- // tickets, but in file-based credential cache,
- // there is only one additional ticket field.
- secondTicket = additionalTickets[0];
- } else {
- if (additionalTickets != null)
- additionalTickets = null;
- }
-
- tgsReqMessg = createRequest(
- options,
- asCreds.ticket,
- asCreds.key,
- ctime,
- princName,
- princName.getRealm(),
- servName,
- from,
- till,
- rtime,
- eTypes,
- addresses,
- authorizationData,
- additionalTickets,
- subKey);
- obuf = tgsReqMessg.asn1Encode();
-
- // XXX We need to revisit this to see if can't move it
- // up such that FORWARDED flag set in the options
- // is included in the marshaled request.
- /*
- * If this is based on a forwarded ticket, record that in the
- * options, because the returned TgsRep will contain the
- * FORWARDED flag set.
- */
- if (asCreds.flags.get(KDCOptions.FORWARDED))
- options.set(KDCOptions.FORWARDED, true);
+ princName = asCreds.client;
+ servName = sname;
+ ctime = new KerberosTime(KerberosTime.NOW);
+ // check if they are valid arguments. The optional fields
+ // should be consistent with settings in KDCOptions.
+ if (options.get(KDCOptions.FORWARDABLE) &&
+ (!(asCreds.flags.get(Krb5.TKT_OPTS_FORWARDABLE)))) {
+ throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
}
+ if (options.get(KDCOptions.FORWARDED)) {
+ if (!(asCreds.flags.get(KDCOptions.FORWARDABLE)))
+ throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
+ }
+ if (options.get(KDCOptions.PROXIABLE) &&
+ (!(asCreds.flags.get(Krb5.TKT_OPTS_PROXIABLE)))) {
+ throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
+ }
+ if (options.get(KDCOptions.PROXY)) {
+ if (!(asCreds.flags.get(KDCOptions.PROXIABLE)))
+ throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
+ }
+ if (options.get(KDCOptions.ALLOW_POSTDATE) &&
+ (!(asCreds.flags.get(Krb5.TKT_OPTS_MAY_POSTDATE)))) {
+ throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
+ }
+ if (options.get(KDCOptions.RENEWABLE) &&
+ (!(asCreds.flags.get(Krb5.TKT_OPTS_RENEWABLE)))) {
+ throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
+ }
+
+ if (options.get(KDCOptions.POSTDATED)) {
+ if (!(asCreds.flags.get(KDCOptions.POSTDATED)))
+ throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
+ } else {
+ if (from != null) from = null;
+ }
+ if (options.get(KDCOptions.RENEWABLE)) {
+ if (!(asCreds.flags.get(KDCOptions.RENEWABLE)))
+ throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
+ } else {
+ if (rtime != null) rtime = null;
+ }
+ if (options.get(KDCOptions.ENC_TKT_IN_SKEY)) {
+ if (additionalTickets == null)
+ throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
+ // in TGS_REQ there could be more than one additional
+ // tickets, but in file-based credential cache,
+ // there is only one additional ticket field.
+ secondTicket = additionalTickets[0];
+ } else {
+ if (additionalTickets != null)
+ additionalTickets = null;
+ }
+
+ tgsReqMessg = createRequest(
+ options,
+ asCreds.ticket,
+ asCreds.key,
+ ctime,
+ princName,
+ princName.getRealm(),
+ servName,
+ from,
+ till,
+ rtime,
+ eTypes,
+ addresses,
+ authorizationData,
+ additionalTickets,
+ subKey);
+ obuf = tgsReqMessg.asn1Encode();
+
+ // XXX We need to revisit this to see if can't move it
+ // up such that FORWARDED flag set in the options
+ // is included in the marshaled request.
+ /*
+ * If this is based on a forwarded ticket, record that in the
+ * options, because the returned TgsRep will contain the
+ * FORWARDED flag set.
+ */
+ if (asCreds.flags.get(KDCOptions.FORWARDED))
+ options.set(KDCOptions.FORWARDED, true);
+
+
+ }
/**
* Sends a TGS request to the realm of the target.
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/APRep.java b/jdk/src/share/classes/sun/security/krb5/internal/APRep.java
index 17aeb89797c..53c3b58eaac 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/APRep.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/APRep.java
@@ -54,81 +54,88 @@ import java.math.BigInteger;
* http://www.ietf.org/rfc/rfc4120.txt.
*/
public class APRep {
- public int pvno;
- public int msgType;
- public EncryptedData encPart;
- public APRep(EncryptedData new_encPart) {
- pvno = Krb5.PVNO;
- msgType = Krb5.KRB_AP_REP;
- encPart = new_encPart;
- }
+ public int pvno;
+ public int msgType;
+ public EncryptedData encPart;
- public APRep(byte[] data) throws Asn1Exception,
- KrbApErrException, IOException {
- init(new DerValue(data));
- }
+ public APRep(EncryptedData new_encPart) {
+ pvno = Krb5.PVNO;
+ msgType = Krb5.KRB_AP_REP;
+ encPart = new_encPart;
+ }
+
+ public APRep(byte[] data) throws Asn1Exception,
+ KrbApErrException, IOException {
+ init(new DerValue(data));
+ }
public APRep(DerValue encoding) throws Asn1Exception,
- KrbApErrException, IOException {
- init(encoding);
- }
+ KrbApErrException, IOException {
+ init(encoding);
+ }
- /**
- * Initializes an APRep object.
- * @param encoding a single DER-encoded value.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- * @exception KrbApErrException if the value read from the DER-encoded data
- * stream does not match the pre-defined value.
- */
+ /**
+ * Initializes an APRep object.
+ * @param encoding a single DER-encoded value.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ * @exception KrbApErrException if the value read from the DER-encoded data
+ * stream does not match the pre-defined value.
+ */
private void init(DerValue encoding) throws Asn1Exception,
- KrbApErrException, IOException {
+ KrbApErrException, IOException {
- if (((encoding.getTag() & (byte)(0x1F)) != Krb5.KRB_AP_REP)
- || (encoding.isApplication() != true)
- || (encoding.isConstructed() != true))
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- DerValue der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence)
+ if (((encoding.getTag() & (byte) (0x1F)) != Krb5.KRB_AP_REP)
+ || (encoding.isApplication() != true)
+ || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- DerValue subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) != (byte)0x00)
+ }
+ DerValue der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ DerValue subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x00) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
pvno = subDer.getData().getBigInteger().intValue();
- if (pvno != Krb5.PVNO)
- throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) != (byte)0x01)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- msgType = subDer.getData().getBigInteger().intValue();
- if (msgType != Krb5.KRB_AP_REP)
- throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
- encPart = EncryptedData.parse(der.getData(), (byte)0x02, false);
- if (der.getData().available() > 0)
+ if (pvno != Krb5.PVNO) {
+ throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x01) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
+ msgType = subDer.getData().getBigInteger().intValue();
+ if (msgType != Krb5.KRB_AP_REP) {
+ throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
+ }
+ encPart = EncryptedData.parse(der.getData(), (byte) 0x02, false);
+ if (der.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
- /**
- * Encodes an APRep object.
- * @return byte array of encoded APRep object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- public byte[] asn1Encode() throws Asn1Exception, IOException {
+ /**
+ * Encodes an APRep object.
+ * @return byte array of encoded APRep object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
DerOutputStream bytes = new DerOutputStream();
- DerOutputStream temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(pvno));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
- temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(msgType));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), encPart.asn1Encode());
- temp = new DerOutputStream();
- temp.write(DerValue.tag_Sequence, bytes);
- DerOutputStream aprep = new DerOutputStream();
- aprep.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x0F), temp);
- return aprep.toByteArray();
- }
-
+ DerOutputStream temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(pvno));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
+ temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(msgType));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), encPart.asn1Encode());
+ temp = new DerOutputStream();
+ temp.write(DerValue.tag_Sequence, bytes);
+ DerOutputStream aprep = new DerOutputStream();
+ aprep.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x0F), temp);
+ return aprep.toByteArray();
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/APReq.java b/jdk/src/share/classes/sun/security/krb5/internal/APReq.java
index 328f833df62..3a1dc7c2222 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/APReq.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/APReq.java
@@ -54,94 +54,98 @@ import java.math.BigInteger;
*
* http://www.ietf.org/rfc/rfc4120.txt.
*/
-
public class APReq {
- public int pvno;
- public int msgType;
- public APOptions apOptions;
- public Ticket ticket;
- public EncryptedData authenticator;
- public APReq(
- APOptions new_apOptions,
- Ticket new_ticket,
- EncryptedData new_authenticator
- ) {
- pvno = Krb5.PVNO;
- msgType = Krb5.KRB_AP_REQ;
- apOptions = new_apOptions;
- ticket = new_ticket;
- authenticator = new_authenticator;
- }
+ public int pvno;
+ public int msgType;
+ public APOptions apOptions;
+ public Ticket ticket;
+ public EncryptedData authenticator;
- public APReq(byte[] data) throws Asn1Exception,IOException, KrbApErrException, RealmException {
+ public APReq(
+ APOptions new_apOptions,
+ Ticket new_ticket,
+ EncryptedData new_authenticator) {
+ pvno = Krb5.PVNO;
+ msgType = Krb5.KRB_AP_REQ;
+ apOptions = new_apOptions;
+ ticket = new_ticket;
+ authenticator = new_authenticator;
+ }
+
+ public APReq(byte[] data) throws Asn1Exception, IOException, KrbApErrException, RealmException {
init(new DerValue(data));
- }
+ }
public APReq(DerValue encoding) throws Asn1Exception, IOException, KrbApErrException, RealmException {
- init(encoding);
- }
+ init(encoding);
+ }
- /**
- * Initializes an APReq object.
- * @param encoding a single DER-encoded value.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- * @exception KrbApErrException if the value read from the DER-encoded data stream does not match the pre-defined value.
- * @exception RealmException if an error occurs while parsing a Realm object.
- */
- private void init(DerValue encoding) throws Asn1Exception,
- IOException, KrbApErrException, RealmException {
- DerValue der, subDer;
- if (((encoding.getTag() & (byte)0x1F) != Krb5.KRB_AP_REQ)
- || (encoding.isApplication() != true)
- || (encoding.isConstructed() != true))
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) != (byte)0x00)
+ /**
+ * Initializes an APReq object.
+ * @param encoding a single DER-encoded value.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ * @exception KrbApErrException if the value read from the DER-encoded data stream does not match the pre-defined value.
+ * @exception RealmException if an error occurs while parsing a Realm object.
+ */
+ private void init(DerValue encoding) throws Asn1Exception,
+ IOException, KrbApErrException, RealmException {
+ DerValue der, subDer;
+ if (((encoding.getTag() & (byte) 0x1F) != Krb5.KRB_AP_REQ)
+ || (encoding.isApplication() != true)
+ || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x00) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
pvno = subDer.getData().getBigInteger().intValue();
- if (pvno != Krb5.PVNO)
- throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) != (byte)0x01)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- msgType = subDer.getData().getBigInteger().intValue();
- if (msgType != Krb5.KRB_AP_REQ)
- throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
- apOptions = APOptions.parse(der.getData(), (byte)0x02, false);
- ticket = Ticket.parse(der.getData(), (byte)0x03, false);
- authenticator = EncryptedData.parse(der.getData(), (byte)0x04, false);
- if (der.getData().available() > 0)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ if (pvno != Krb5.PVNO) {
+ throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
}
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x01) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ msgType = subDer.getData().getBigInteger().intValue();
+ if (msgType != Krb5.KRB_AP_REQ) {
+ throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
+ }
+ apOptions = APOptions.parse(der.getData(), (byte) 0x02, false);
+ ticket = Ticket.parse(der.getData(), (byte) 0x03, false);
+ authenticator = EncryptedData.parse(der.getData(), (byte) 0x04, false);
+ if (der.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
- /**
- * Encodes an APReq object.
- * @return byte array of encoded APReq object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- public byte[] asn1Encode() throws Asn1Exception, IOException {
+ /**
+ * Encodes an APReq object.
+ * @return byte array of encoded APReq object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
DerOutputStream bytes = new DerOutputStream();
- DerOutputStream temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(pvno));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
- temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(msgType));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), apOptions.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), ticket.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), authenticator.asn1Encode());
- temp = new DerOutputStream();
- temp.write(DerValue.tag_Sequence, bytes);
- DerOutputStream apreq = new DerOutputStream();
- apreq.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x0E), temp);
- return apreq.toByteArray();
-
- }
-
+ DerOutputStream temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(pvno));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
+ temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(msgType));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), apOptions.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), ticket.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x04), authenticator.asn1Encode());
+ temp = new DerOutputStream();
+ temp.write(DerValue.tag_Sequence, bytes);
+ DerOutputStream apreq = new DerOutputStream();
+ apreq.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x0E), temp);
+ return apreq.toByteArray();
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/ASRep.java b/jdk/src/share/classes/sun/security/krb5/internal/ASRep.java
index df0ebac6550..a59811d97f9 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/ASRep.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/ASRep.java
@@ -40,30 +40,28 @@ import java.io.IOException;
public class ASRep extends KDCRep {
- public ASRep(
- PAData[] new_pAData,
- Realm new_crealm,
- PrincipalName new_cname,
- Ticket new_ticket,
- EncryptedData new_encPart
- ) throws IOException {
- super(new_pAData, new_crealm, new_cname, new_ticket,
- new_encPart, Krb5.KRB_AS_REP);
- }
+ public ASRep(
+ PAData[] new_pAData,
+ Realm new_crealm,
+ PrincipalName new_cname,
+ Ticket new_ticket,
+ EncryptedData new_encPart) throws IOException {
+ super(new_pAData, new_crealm, new_cname, new_ticket,
+ new_encPart, Krb5.KRB_AS_REP);
+ }
- public ASRep(byte[] data) throws Asn1Exception,
- RealmException, KrbApErrException, IOException {
- init(new DerValue(data));
- }
+ public ASRep(byte[] data) throws Asn1Exception,
+ RealmException, KrbApErrException, IOException {
+ init(new DerValue(data));
+ }
- public ASRep(DerValue encoding) throws Asn1Exception,
- RealmException, KrbApErrException, IOException {
- init(encoding);
- }
-
- private void init(DerValue encoding) throws Asn1Exception,
- RealmException, KrbApErrException, IOException {
- init(encoding, Krb5.KRB_AS_REP);
- }
+ public ASRep(DerValue encoding) throws Asn1Exception,
+ RealmException, KrbApErrException, IOException {
+ init(encoding);
+ }
+ private void init(DerValue encoding) throws Asn1Exception,
+ RealmException, KrbApErrException, IOException {
+ init(encoding, Krb5.KRB_AS_REP);
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/ASReq.java b/jdk/src/share/classes/sun/security/krb5/internal/ASReq.java
index 743316c6c0c..b5907398bf7 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/ASReq.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/ASReq.java
@@ -36,20 +36,19 @@ import java.io.IOException;
public class ASReq extends KDCReq {
- public ASReq(PAData[] new_pAData, KDCReqBody new_reqBody) throws IOException {
- super(new_pAData, new_reqBody, Krb5.KRB_AS_REQ);
- }
+ public ASReq(PAData[] new_pAData, KDCReqBody new_reqBody) throws IOException {
+ super(new_pAData, new_reqBody, Krb5.KRB_AS_REQ);
+ }
- public ASReq(byte[] data) throws Asn1Exception, KrbException, IOException {
- init(new DerValue(data));
- }
+ public ASReq(byte[] data) throws Asn1Exception, KrbException, IOException {
+ init(new DerValue(data));
+ }
public ASReq(DerValue encoding) throws Asn1Exception, KrbException, IOException {
- init(encoding);
- }
-
- private void init(DerValue encoding) throws Asn1Exception, IOException, KrbException {
- super.init(encoding, Krb5.KRB_AS_REQ);
- }
+ init(encoding);
+ }
+ private void init(DerValue encoding) throws Asn1Exception, IOException, KrbException {
+ super.init(encoding, Krb5.KRB_AS_REQ);
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/Authenticator.java b/jdk/src/share/classes/sun/security/krb5/internal/Authenticator.java
index 57b6156c0e5..49cf1709ee2 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/Authenticator.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/Authenticator.java
@@ -34,6 +34,7 @@ import sun.security.util.*;
import java.util.Vector;
import java.io.IOException;
import java.math.BigInteger;
+
/**
* Implements the ASN.1 Authenticator type.
*
@@ -58,6 +59,7 @@ import java.math.BigInteger;
* http://www.ietf.org/rfc/rfc4120.txt.
*/
public class Authenticator {
+
public int authenticator_vno;
public Realm crealm;
public PrincipalName cname;
@@ -68,137 +70,145 @@ public class Authenticator {
Integer seqNumber; //optional
public AuthorizationData authorizationData; //optional
- public Authenticator (
- Realm new_crealm,
- PrincipalName new_cname,
- Checksum new_cksum,
- int new_cusec,
- KerberosTime new_ctime,
- EncryptionKey new_subKey,
- Integer new_seqNumber,
- AuthorizationData new_authorizationData
- ) {
- authenticator_vno = Krb5.AUTHNETICATOR_VNO;
- crealm = new_crealm;
- cname = new_cname;
- cksum = new_cksum;
- cusec = new_cusec;
- ctime = new_ctime;
- subKey = new_subKey;
- seqNumber = new_seqNumber;
- authorizationData = new_authorizationData;
- }
+ public Authenticator(
+ Realm new_crealm,
+ PrincipalName new_cname,
+ Checksum new_cksum,
+ int new_cusec,
+ KerberosTime new_ctime,
+ EncryptionKey new_subKey,
+ Integer new_seqNumber,
+ AuthorizationData new_authorizationData) {
+ authenticator_vno = Krb5.AUTHNETICATOR_VNO;
+ crealm = new_crealm;
+ cname = new_cname;
+ cksum = new_cksum;
+ cusec = new_cusec;
+ ctime = new_ctime;
+ subKey = new_subKey;
+ seqNumber = new_seqNumber;
+ authorizationData = new_authorizationData;
+ }
- public Authenticator(byte[] data)
- throws Asn1Exception, IOException, KrbApErrException, RealmException {
- init(new DerValue(data));
- }
+ public Authenticator(byte[] data)
+ throws Asn1Exception, IOException, KrbApErrException, RealmException {
+ init(new DerValue(data));
+ }
- public Authenticator(DerValue encoding)
- throws Asn1Exception,IOException, KrbApErrException, RealmException {
- init(encoding);
- }
+ public Authenticator(DerValue encoding)
+ throws Asn1Exception, IOException, KrbApErrException, RealmException {
+ init(encoding);
+ }
- /**
- * Initializes an Authenticator object.
- * @param encoding a single DER-encoded value.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- * @exception KrbApErrException if the value read from the DER-encoded data
- * stream does not match the pre-defined value.
- * @exception RealmException if an error occurs while parsing a Realm object.
- */
- private void init(DerValue encoding)
- throws Asn1Exception, IOException, KrbApErrException, RealmException {
- DerValue der, subDer;
- //may not be the correct error code for a tag
- //mismatch on an encrypted structure
- if (((encoding.getTag() & (byte)0x1F) != (byte)0x02)
- || (encoding.isApplication() != true)
- || (encoding.isConstructed() != true))
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence)
+ /**
+ * Initializes an Authenticator object.
+ * @param encoding a single DER-encoded value.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ * @exception KrbApErrException if the value read from the DER-encoded data
+ * stream does not match the pre-defined value.
+ * @exception RealmException if an error occurs while parsing a Realm object.
+ */
+ private void init(DerValue encoding)
+ throws Asn1Exception, IOException, KrbApErrException, RealmException {
+ DerValue der, subDer;
+ //may not be the correct error code for a tag
+ //mismatch on an encrypted structure
+ if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x02)
+ || (encoding.isApplication() != true)
+ || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) != (byte)0x00)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x00) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
authenticator_vno = subDer.getData().getBigInteger().intValue();
- if (authenticator_vno != 5)
+ if (authenticator_vno != 5) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
- crealm = Realm.parse(der.getData(), (byte)0x01, false);
- cname = PrincipalName.parse(der.getData(), (byte)0x02, false);
- cksum = Checksum.parse(der.getData(), (byte)0x03, true);
+ }
+ crealm = Realm.parse(der.getData(), (byte) 0x01, false);
+ cname = PrincipalName.parse(der.getData(), (byte) 0x02, false);
+ cksum = Checksum.parse(der.getData(), (byte) 0x03, true);
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & (byte) 0x1F) == 0x04) {
+ cusec = subDer.getData().getBigInteger().intValue();
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ ctime = KerberosTime.parse(der.getData(), (byte) 0x05, false);
+ if (der.getData().available() > 0) {
+ subKey = EncryptionKey.parse(der.getData(), (byte) 0x06, true);
+ } else {
+ subKey = null;
+ seqNumber = null;
+ authorizationData = null;
+ }
+ if (der.getData().available() > 0) {
+ if ((der.getData().peekByte() & 0x1F) == 0x07) {
subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) == 0x04) {
- cusec = subDer.getData().getBigInteger().intValue();
+ if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x07) {
+ seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
}
- else throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- ctime = KerberosTime.parse(der.getData(), (byte)0x05, false);
- if (der.getData().available() > 0) {
- subKey = EncryptionKey.parse(der.getData(), (byte)0x06, true);
- }
- else {
- subKey = null;
- seqNumber = null;
- authorizationData = null;
- }
- if (der.getData().available() > 0) {
- if ((der.getData().peekByte() & 0x1F) == 0x07) {
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) == (byte)0x07)
- seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
- }
- }
- else {
- seqNumber = null;
- authorizationData = null;
- }
- if (der.getData().available() > 0) {
- authorizationData = AuthorizationData.parse(der.getData(), (byte)0x08, true);
- }
- else authorizationData = null;
- if (der.getData().available() > 0)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ } else {
+ seqNumber = null;
+ authorizationData = null;
}
+ if (der.getData().available() > 0) {
+ authorizationData = AuthorizationData.parse(der.getData(), (byte) 0x08, true);
+ } else {
+ authorizationData = null;
+ }
+ if (der.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
- /**
- * Encodes an Authenticator object.
- * @return byte array of encoded Authenticator object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- public byte[] asn1Encode() throws Asn1Exception, IOException {
- Vector v = new Vector ();
- DerOutputStream temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(authenticator_vno));
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp.toByteArray()));
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), crealm.asn1Encode()));
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), cname.asn1Encode()));
- if (cksum != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), cksum.asn1Encode()));
- temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(cusec));
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), temp.toByteArray()));
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), ctime.asn1Encode()));
- if (subKey != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), subKey.asn1Encode()));
- if (seqNumber != null) {
- temp = new DerOutputStream();
- // encode as an unsigned integer (UInt32)
- temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), temp.toByteArray()));
- }
- if (authorizationData != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), authorizationData.asn1Encode()));
- DerValue der[] = new DerValue[v.size()];
- v.copyInto(der);
- temp = new DerOutputStream();
- temp.putSequence(der);
- DerOutputStream out = new DerOutputStream();
- out.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x02), temp);
- return out.toByteArray();
+ /**
+ * Encodes an Authenticator object.
+ * @return byte array of encoded Authenticator object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
+ Vector v = new Vector();
+ DerOutputStream temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(authenticator_vno));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp.toByteArray()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), crealm.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), cname.asn1Encode()));
+ if (cksum != null) {
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), cksum.asn1Encode()));
}
+ temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(cusec));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x04), temp.toByteArray()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x05), ctime.asn1Encode()));
+ if (subKey != null) {
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x06), subKey.asn1Encode()));
+ }
+ if (seqNumber != null) {
+ temp = new DerOutputStream();
+ // encode as an unsigned integer (UInt32)
+ temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x07), temp.toByteArray()));
+ }
+ if (authorizationData != null) {
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x08), authorizationData.asn1Encode()));
+ }
+ DerValue der[] = new DerValue[v.size()];
+ v.copyInto(der);
+ temp = new DerOutputStream();
+ temp.putSequence(der);
+ DerOutputStream out = new DerOutputStream();
+ out.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x02), temp);
+ return out.toByteArray();
+ }
public final Checksum getChecksum() {
return cksum;
@@ -211,5 +221,4 @@ public class Authenticator {
public final EncryptionKey getSubKey() {
return subKey;
}
-
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/AuthorizationData.java b/jdk/src/share/classes/sun/security/krb5/internal/AuthorizationData.java
index d6f04d748b5..269edec71a1 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/AuthorizationData.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/AuthorizationData.java
@@ -53,82 +53,81 @@ import sun.security.krb5.internal.ccache.CCacheOutputStream;
* }
*/
public class AuthorizationData implements Cloneable {
- private AuthorizationDataEntry[] entry = null;
- private AuthorizationData() {
- }
+ private AuthorizationDataEntry[] entry = null;
- public AuthorizationData(
- AuthorizationDataEntry[] new_entries
- ) throws IOException {
- if (new_entries != null) {
- entry = new AuthorizationDataEntry[new_entries.length];
- for (int i = 0; i < new_entries.length; i++) {
- if (new_entries[i] == null) {
- throw new IOException("Cannot create an AuthorizationData");
- } else {
- entry[i] = (AuthorizationDataEntry)new_entries[i].clone();
- }
- }
- }
- }
+ private AuthorizationData() {
+ }
- public AuthorizationData(
- AuthorizationDataEntry new_entry
- ) {
- entry = new AuthorizationDataEntry[1];
- entry[0] = new_entry;
+ public AuthorizationData(AuthorizationDataEntry[] new_entries)
+ throws IOException {
+ if (new_entries != null) {
+ entry = new AuthorizationDataEntry[new_entries.length];
+ for (int i = 0; i < new_entries.length; i++) {
+ if (new_entries[i] == null) {
+ throw new IOException("Cannot create an AuthorizationData");
+ } else {
+ entry[i] = (AuthorizationDataEntry) new_entries[i].clone();
+ }
+ }
}
+ }
- public Object clone() {
- AuthorizationData new_authorizationData =
- new AuthorizationData();
- if (entry != null) {
- new_authorizationData.entry =
- new AuthorizationDataEntry[entry.length];
- for (int i = 0; i < entry.length; i++)
- new_authorizationData.entry[i] =
- (AuthorizationDataEntry)entry[i].clone();
- }
- return new_authorizationData;
- }
+ public AuthorizationData(AuthorizationDataEntry new_entry) {
+ entry = new AuthorizationDataEntry[1];
+ entry[0] = new_entry;
+ }
- /**
- * Constructs a new AuthorizationData, instance.
- * @param der a single DER-encoded value.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- public AuthorizationData(DerValue der) throws Asn1Exception, IOException {
- Vector v =
- new Vector ();
- if (der.getTag() != DerValue.tag_Sequence) {
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- while (der.getData().available() > 0) {
- v.addElement(new AuthorizationDataEntry(der.getData().getDerValue()));
- }
- if (v.size() > 0) {
- entry = new AuthorizationDataEntry[v.size()];
- v.copyInto(entry);
- }
+ public Object clone() {
+ AuthorizationData new_authorizationData =
+ new AuthorizationData();
+ if (entry != null) {
+ new_authorizationData.entry =
+ new AuthorizationDataEntry[entry.length];
+ for (int i = 0; i < entry.length; i++) {
+ new_authorizationData.entry[i] =
+ (AuthorizationDataEntry) entry[i].clone();
+ }
}
+ return new_authorizationData;
+ }
- /**
- * Encodes an AuthorizationData object.
- * @return byte array of encoded AuthorizationData object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- public byte[] asn1Encode() throws Asn1Exception, IOException {
- DerOutputStream bytes = new DerOutputStream();
- DerValue der[] = new DerValue[entry.length];
- for (int i = 0; i < entry.length; i++) {
- der[i] = new DerValue(entry[i].asn1Encode());
- }
- bytes.putSequence(der);
- return bytes.toByteArray();
+ /**
+ * Constructs a new AuthorizationData, instance.
+ * @param der a single DER-encoded value.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public AuthorizationData(DerValue der) throws Asn1Exception, IOException {
+ Vector v =
+ new Vector();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
+ while (der.getData().available() > 0) {
+ v.addElement(new AuthorizationDataEntry(der.getData().getDerValue()));
+ }
+ if (v.size() > 0) {
+ entry = new AuthorizationDataEntry[v.size()];
+ v.copyInto(entry);
+ }
+ }
+
+ /**
+ * Encodes an AuthorizationData object.
+ * @return byte array of encoded AuthorizationData object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
+ DerOutputStream bytes = new DerOutputStream();
+ DerValue der[] = new DerValue[entry.length];
+ for (int i = 0; i < entry.length; i++) {
+ der[i] = new DerValue(entry[i].asn1Encode());
+ }
+ bytes.putSequence(der);
+ return bytes.toByteArray();
+ }
/**
* Parse (unmarshal) an AuthorizationData object from a DER input stream.
@@ -143,31 +142,30 @@ public class AuthorizationData implements Cloneable {
* @return an instance of AuthorizationData.
*
*/
- public static AuthorizationData parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException{
- if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) {
- return null;
- }
- DerValue der = data.getDerValue();
- if (explicitTag != (der.getTag() & (byte)0x1F)) {
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- else {
- DerValue subDer = der.getData().getDerValue();
- return new AuthorizationData(subDer);
- }
+ public static AuthorizationData parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException {
+ if ((optional) && (((byte) data.peekByte() & (byte) 0x1F) != explicitTag)) {
+ return null;
}
+ DerValue der = data.getDerValue();
+ if (explicitTag != (der.getTag() & (byte) 0x1F)) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ } else {
+ DerValue subDer = der.getData().getDerValue();
+ return new AuthorizationData(subDer);
+ }
+ }
- /**
- * Writes AuthorizationData data fields to a output stream.
- *
- * @param cos a CCacheOutputStream to be written to.
- * @exception IOException if an I/O exception occurs.
- */
- public void writeAuth(CCacheOutputStream cos) throws IOException {
- for (int i = 0; i < entry.length; i++) {
- entry[i].writeEntry(cos);
- }
+ /**
+ * Writes AuthorizationData data fields to a output stream.
+ *
+ * @param cos a CCacheOutputStream to be written to.
+ * @exception IOException if an I/O exception occurs.
+ */
+ public void writeAuth(CCacheOutputStream cos) throws IOException {
+ for (int i = 0; i < entry.length; i++) {
+ entry[i].writeEntry(cos);
}
+ }
public String toString() {
String retVal = "AuthorizationData:\n";
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/AuthorizationDataEntry.java b/jdk/src/share/classes/sun/security/krb5/internal/AuthorizationDataEntry.java
index 3ad64576175..e159c85fc00 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/AuthorizationDataEntry.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/AuthorizationDataEntry.java
@@ -35,90 +35,90 @@ import sun.security.krb5.Asn1Exception;
import sun.security.krb5.internal.ccache.CCacheOutputStream;
public class AuthorizationDataEntry implements Cloneable {
- public int adType;
- public byte[] adData;
- private AuthorizationDataEntry() {
+ public int adType;
+ public byte[] adData;
+
+ private AuthorizationDataEntry() {
+ }
+
+ public AuthorizationDataEntry(
+ int new_adType,
+ byte[] new_adData) {
+ adType = new_adType;
+ adData = new_adData;
+ }
+
+ public Object clone() {
+ AuthorizationDataEntry new_authorizationDataEntry =
+ new AuthorizationDataEntry();
+ new_authorizationDataEntry.adType = adType;
+ if (adData != null) {
+ new_authorizationDataEntry.adData = new byte[adData.length];
+ System.arraycopy(adData, 0,
+ new_authorizationDataEntry.adData, 0, adData.length);
}
+ return new_authorizationDataEntry;
+ }
- public AuthorizationDataEntry(
- int new_adType,
- byte[] new_adData
- ) {
- adType = new_adType;
- adData = new_adData;
- }
-
- public Object clone() {
- AuthorizationDataEntry new_authorizationDataEntry =
- new AuthorizationDataEntry();
- new_authorizationDataEntry.adType = adType;
- if (adData != null) {
- new_authorizationDataEntry.adData = new byte[adData.length];
- System.arraycopy(adData, 0,
- new_authorizationDataEntry.adData, 0, adData.length);
- }
- return new_authorizationDataEntry;
- }
-
- /**
- * Constructs an instance of AuthorizationDataEntry.
- * @param encoding a single DER-encoded value.
- */
- public AuthorizationDataEntry(DerValue encoding) throws Asn1Exception, IOException {
- DerValue der;
+ /**
+ * Constructs an instance of AuthorizationDataEntry.
+ * @param encoding a single DER-encoded value.
+ */
+ public AuthorizationDataEntry(DerValue encoding) throws Asn1Exception, IOException {
+ DerValue der;
if (encoding.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- der = encoding.getData().getDerValue();
- if ((der.getTag() & (byte)0x1F) == (byte)0x00) {
- adType = der.getData().getBigInteger().intValue();
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
der = encoding.getData().getDerValue();
- if ((der.getTag() & (byte)0x1F) == (byte)0x01) {
- adData = der.getData().getOctetString();
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- if (encoding.getData().available() > 0)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ if ((der.getTag() & (byte) 0x1F) == (byte) 0x00) {
+ adType = der.getData().getBigInteger().intValue();
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
+ der = encoding.getData().getDerValue();
+ if ((der.getTag() & (byte) 0x1F) == (byte) 0x01) {
+ adData = der.getData().getOctetString();
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ if (encoding.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
- /**
- * Encodes an AuthorizationDataEntry object.
- * @return byte array of encoded AuthorizationDataEntry object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- public byte[] asn1Encode() throws Asn1Exception, IOException {
+ /**
+ * Encodes an AuthorizationDataEntry object.
+ * @return byte array of encoded AuthorizationDataEntry object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
DerOutputStream bytes = new DerOutputStream();
- DerOutputStream temp = new DerOutputStream();
- temp.putInteger(adType);
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
- temp = new DerOutputStream();
- temp.putOctetString(adData);
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
- temp = new DerOutputStream();
- temp.write(DerValue.tag_Sequence, bytes);
- return temp.toByteArray();
- }
+ DerOutputStream temp = new DerOutputStream();
+ temp.putInteger(adType);
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
+ temp = new DerOutputStream();
+ temp.putOctetString(adData);
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
+ temp = new DerOutputStream();
+ temp.write(DerValue.tag_Sequence, bytes);
+ return temp.toByteArray();
+ }
- /**
- * Writes the entry's data fields in FCC format to an output stream.
- *
- * @param cos a CCacheOutputStream.
- * @exception IOException if an I/O exception occurs.
- */
- public void writeEntry(CCacheOutputStream cos) throws IOException {
- cos.write16(adType);
- cos.write32(adData.length);
- cos.write(adData, 0, adData.length);
- }
+ /**
+ * Writes the entry's data fields in FCC format to an output stream.
+ *
+ * @param cos a CCacheOutputStream.
+ * @exception IOException if an I/O exception occurs.
+ */
+ public void writeEntry(CCacheOutputStream cos) throws IOException {
+ cos.write16(adType);
+ cos.write32(adData.length);
+ cos.write(adData, 0, adData.length);
+ }
public String toString() {
return ("adType=" + adType + " adData.length=" + adData.length);
}
-
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/EncAPRepPart.java b/jdk/src/share/classes/sun/security/krb5/internal/EncAPRepPart.java
index 1d3381797e0..b3dcf144159 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/EncAPRepPart.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/EncAPRepPart.java
@@ -55,102 +55,111 @@ import java.math.BigInteger;
* http://www.ietf.org/rfc/rfc4120.txt.
*/
public class EncAPRepPart {
- public KerberosTime ctime;
- public int cusec;
+
+ public KerberosTime ctime;
+ public int cusec;
EncryptionKey subKey; //optional
Integer seqNumber; //optional
- public EncAPRepPart(
- KerberosTime new_ctime,
- int new_cusec,
- EncryptionKey new_subKey,
- Integer new_seqNumber
- ) {
- ctime = new_ctime;
- cusec = new_cusec;
- subKey = new_subKey;
- seqNumber = new_seqNumber;
- }
+ public EncAPRepPart(
+ KerberosTime new_ctime,
+ int new_cusec,
+ EncryptionKey new_subKey,
+ Integer new_seqNumber) {
+ ctime = new_ctime;
+ cusec = new_cusec;
+ subKey = new_subKey;
+ seqNumber = new_seqNumber;
+ }
- public EncAPRepPart(byte[] data)
- throws Asn1Exception, IOException {
- init(new DerValue(data));
- }
+ public EncAPRepPart(byte[] data)
+ throws Asn1Exception, IOException {
+ init(new DerValue(data));
+ }
- public EncAPRepPart(DerValue encoding)
- throws Asn1Exception, IOException {
- init(encoding);
- }
+ public EncAPRepPart(DerValue encoding)
+ throws Asn1Exception, IOException {
+ init(encoding);
+ }
- /**
- * Initializes an EncaPRepPart object.
- * @param encoding a single DER-encoded value.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- private void init(DerValue encoding) throws Asn1Exception, IOException {
- DerValue der, subDer;
- if (((encoding.getTag() & (byte)0x1F) != (byte)0x1B)
- || (encoding.isApplication() != true)
- || (encoding.isConstructed() != true))
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence)
+ /**
+ * Initializes an EncaPRepPart object.
+ * @param encoding a single DER-encoded value.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ private void init(DerValue encoding) throws Asn1Exception, IOException {
+ DerValue der, subDer;
+ if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1B)
+ || (encoding.isApplication() != true)
+ || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- ctime = KerberosTime.parse(der.getData(), (byte)0x00, true);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) == (byte)0x01) {
- cusec = subDer.getData().getBigInteger().intValue();
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- if (der.getData().available() > 0) {
- subKey = EncryptionKey.parse(der.getData(), (byte)0x02, true);
- }
- else {
- subKey = null;
- seqNumber = null;
- }
- if (der.getData().available() > 0) {
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x1F) != 0x03) {
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
- }
- else seqNumber = null;
- if (der.getData().available() > 0)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
+ der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ ctime = KerberosTime.parse(der.getData(), (byte) 0x00, true);
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x01) {
+ cusec = subDer.getData().getBigInteger().intValue();
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ if (der.getData().available() > 0) {
+ subKey = EncryptionKey.parse(der.getData(), (byte) 0x02, true);
+ } else {
+ subKey = null;
+ seqNumber = null;
+ }
+ if (der.getData().available() > 0) {
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & 0x1F) != 0x03) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
+ } else {
+ seqNumber = null;
+ }
+ if (der.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
- /**
- * Encodes an EncAPRepPart object.
- * @return byte array of encoded EncAPRepPart object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- public byte[] asn1Encode() throws Asn1Exception, IOException{
- Vector v = new Vector ();
+ /**
+ * Encodes an EncAPRepPart object.
+ * @return byte array of encoded EncAPRepPart object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
+ Vector v = new Vector();
DerOutputStream temp = new DerOutputStream();
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), ctime.asn1Encode()));
- temp.putInteger(BigInteger.valueOf(cusec));
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp.toByteArray()));
- if (subKey != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), subKey.asn1Encode()));
- if (seqNumber != null) {
- temp = new DerOutputStream();
- // encode as an unsigned integer (UInt32)
- temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp.toByteArray()));
- }
- DerValue der[] = new DerValue[v.size()];
- v.copyInto(der);
- temp = new DerOutputStream();
- temp.putSequence(der);
- DerOutputStream out = new DerOutputStream();
- out.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x1B), temp);
- return out.toByteArray();
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x00), ctime.asn1Encode()));
+ temp.putInteger(BigInteger.valueOf(cusec));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x01), temp.toByteArray()));
+ if (subKey != null) {
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x02), subKey.asn1Encode()));
}
+ if (seqNumber != null) {
+ temp = new DerOutputStream();
+ // encode as an unsigned integer (UInt32)
+ temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x03), temp.toByteArray()));
+ }
+ DerValue der[] = new DerValue[v.size()];
+ v.copyInto(der);
+ temp = new DerOutputStream();
+ temp.putSequence(der);
+ DerOutputStream out = new DerOutputStream();
+ out.write(DerValue.createTag(DerValue.TAG_APPLICATION,
+ true, (byte) 0x1B), temp);
+ return out.toByteArray();
+ }
public final EncryptionKey getSubKey() {
return subKey;
@@ -159,5 +168,4 @@ public class EncAPRepPart {
public final Integer getSeqNumber() {
return seqNumber;
}
-
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/EncASRepPart.java b/jdk/src/share/classes/sun/security/krb5/internal/EncASRepPart.java
index b5526e8014d..b71238fef51 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/EncASRepPart.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/EncASRepPart.java
@@ -36,57 +36,55 @@ import java.io.IOException;
public class EncASRepPart extends EncKDCRepPart {
- public EncASRepPart(
- EncryptionKey new_key,
- LastReq new_lastReq,
- int new_nonce,
- KerberosTime new_keyExpiration,
- TicketFlags new_flags,
- KerberosTime new_authtime,
- KerberosTime new_starttime,
- KerberosTime new_endtime,
- KerberosTime new_renewTill,
- Realm new_srealm,
- PrincipalName new_sname,
- HostAddresses new_caddr
- ) {
- super(
- new_key,
- new_lastReq,
- new_nonce,
- new_keyExpiration,
- new_flags,
- new_authtime,
- new_starttime,
- new_endtime,
- new_renewTill,
- new_srealm,
- new_sname,
- new_caddr,
- Krb5.KRB_ENC_AS_REP_PART
- //may need to use Krb5.KRB_ENC_TGS_REP_PART to mimic
- //behavior of other implementaions, instead of above
+ public EncASRepPart(
+ EncryptionKey new_key,
+ LastReq new_lastReq,
+ int new_nonce,
+ KerberosTime new_keyExpiration,
+ TicketFlags new_flags,
+ KerberosTime new_authtime,
+ KerberosTime new_starttime,
+ KerberosTime new_endtime,
+ KerberosTime new_renewTill,
+ Realm new_srealm,
+ PrincipalName new_sname,
+ HostAddresses new_caddr) {
+ super(
+ new_key,
+ new_lastReq,
+ new_nonce,
+ new_keyExpiration,
+ new_flags,
+ new_authtime,
+ new_starttime,
+ new_endtime,
+ new_renewTill,
+ new_srealm,
+ new_sname,
+ new_caddr,
+ Krb5.KRB_ENC_AS_REP_PART
);
- }
+ //may need to use Krb5.KRB_ENC_TGS_REP_PART to mimic
+ //behavior of other implementaions, instead of above
+ }
- public EncASRepPart(byte[] data) throws Asn1Exception,
- IOException, KrbException {
- init(new DerValue(data));
- }
+ public EncASRepPart(byte[] data) throws Asn1Exception,
+ IOException, KrbException {
+ init(new DerValue(data));
+ }
- public EncASRepPart(DerValue encoding) throws Asn1Exception,
- IOException, KrbException {
- init(encoding);
- }
+ public EncASRepPart(DerValue encoding) throws Asn1Exception,
+ IOException, KrbException {
+ init(encoding);
+ }
- private void init(DerValue encoding) throws Asn1Exception,
- IOException, KrbException {
- init(encoding, Krb5.KRB_ENC_AS_REP_PART);
- }
-
- public byte[] asn1Encode() throws Asn1Exception,
- IOException {
- return asn1Encode(Krb5.KRB_ENC_AS_REP_PART);
- }
+ private void init(DerValue encoding) throws Asn1Exception,
+ IOException, KrbException {
+ init(encoding, Krb5.KRB_ENC_AS_REP_PART);
+ }
+ public byte[] asn1Encode() throws Asn1Exception,
+ IOException {
+ return asn1Encode(Krb5.KRB_ENC_AS_REP_PART);
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/EncKDCRepPart.java b/jdk/src/share/classes/sun/security/krb5/internal/EncKDCRepPart.java
index 35081a0051c..e7723a41c42 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/EncKDCRepPart.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/EncKDCRepPart.java
@@ -36,6 +36,7 @@ import sun.security.util.*;
import java.util.Vector;
import java.io.IOException;
import java.math.BigInteger;
+
/**
* Implements the ASN.1 EncKDCRepPart type.
*
@@ -63,143 +64,163 @@ import java.math.BigInteger;
* http://www.ietf.org/rfc/rfc4120.txt.
*/
public class EncKDCRepPart {
- public EncryptionKey key;
- public LastReq lastReq;
- public int nonce;
- public KerberosTime keyExpiration; //optional
- public TicketFlags flags;
- public KerberosTime authtime;
- public KerberosTime starttime; //optional
- public KerberosTime endtime;
- public KerberosTime renewTill; //optional
- public Realm srealm;
- public PrincipalName sname;
- public HostAddresses caddr; //optional
- public int msgType; //not included in sequence
- public EncKDCRepPart(
- EncryptionKey new_key,
- LastReq new_lastReq,
- int new_nonce,
- KerberosTime new_keyExpiration,
- TicketFlags new_flags,
- KerberosTime new_authtime,
- KerberosTime new_starttime,
- KerberosTime new_endtime,
- KerberosTime new_renewTill,
- Realm new_srealm,
- PrincipalName new_sname,
- HostAddresses new_caddr,
- int new_msgType
- ) {
- key = new_key;
- lastReq = new_lastReq;
- nonce = new_nonce;
- keyExpiration = new_keyExpiration;
- flags = new_flags;
- authtime = new_authtime;
- starttime = new_starttime;
- endtime = new_endtime;
- renewTill = new_renewTill;
- srealm = new_srealm;
- sname = new_sname;
- caddr = new_caddr;
- msgType = new_msgType;
- }
+ public EncryptionKey key;
+ public LastReq lastReq;
+ public int nonce;
+ public KerberosTime keyExpiration; //optional
+ public TicketFlags flags;
+ public KerberosTime authtime;
+ public KerberosTime starttime; //optional
+ public KerberosTime endtime;
+ public KerberosTime renewTill; //optional
+ public Realm srealm;
+ public PrincipalName sname;
+ public HostAddresses caddr; //optional
+ public int msgType; //not included in sequence
- public EncKDCRepPart() {
- }
+ public EncKDCRepPart(
+ EncryptionKey new_key,
+ LastReq new_lastReq,
+ int new_nonce,
+ KerberosTime new_keyExpiration,
+ TicketFlags new_flags,
+ KerberosTime new_authtime,
+ KerberosTime new_starttime,
+ KerberosTime new_endtime,
+ KerberosTime new_renewTill,
+ Realm new_srealm,
+ PrincipalName new_sname,
+ HostAddresses new_caddr,
+ int new_msgType) {
+ key = new_key;
+ lastReq = new_lastReq;
+ nonce = new_nonce;
+ keyExpiration = new_keyExpiration;
+ flags = new_flags;
+ authtime = new_authtime;
+ starttime = new_starttime;
+ endtime = new_endtime;
+ renewTill = new_renewTill;
+ srealm = new_srealm;
+ sname = new_sname;
+ caddr = new_caddr;
+ msgType = new_msgType;
+ }
- public EncKDCRepPart(byte[] data, int rep_type)
- throws Asn1Exception, IOException, RealmException{
- init(new DerValue(data), rep_type);
- }
+ public EncKDCRepPart() {
+ }
- public EncKDCRepPart(DerValue encoding, int rep_type)
- throws Asn1Exception, IOException, RealmException
- {
- init(encoding, rep_type);
- }
+ public EncKDCRepPart(byte[] data, int rep_type)
+ throws Asn1Exception, IOException, RealmException {
+ init(new DerValue(data), rep_type);
+ }
- /**
- * Initializes an EncKDCRepPart object.
- *
- * @param encoding a single DER-encoded value.
- * @param rep_type type of the encrypted reply message.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- * @exception RealmException if an error occurs while decoding an Realm object.
- */
- protected void init(DerValue encoding, int rep_type)
- throws Asn1Exception, IOException, RealmException
- {
- DerValue der, subDer;
- //implementations return the incorrect tag value, so
- //we don't use the above line; instead we use the following
- msgType = (encoding.getTag() & (byte)0x1F);
+ public EncKDCRepPart(DerValue encoding, int rep_type)
+ throws Asn1Exception, IOException, RealmException {
+ init(encoding, rep_type);
+ }
+
+ /**
+ * Initializes an EncKDCRepPart object.
+ *
+ * @param encoding a single DER-encoded value.
+ * @param rep_type type of the encrypted reply message.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ * @exception RealmException if an error occurs while decoding an Realm object.
+ */
+ protected void init(DerValue encoding, int rep_type)
+ throws Asn1Exception, IOException, RealmException {
+ DerValue der, subDer;
+ //implementations return the incorrect tag value, so
+ //we don't use the above line; instead we use the following
+ msgType = (encoding.getTag() & (byte) 0x1F);
if (msgType != Krb5.KRB_ENC_AS_REP_PART &&
- msgType != Krb5.KRB_ENC_TGS_REP_PART)
+ msgType != Krb5.KRB_ENC_TGS_REP_PART) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- key = EncryptionKey.parse(der.getData(), (byte)0x00, false);
- lastReq = LastReq.parse(der.getData(), (byte)0x01, false);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) == (byte)0x02)
- nonce = subDer.getData().getBigInteger().intValue();
- else throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- keyExpiration = KerberosTime.parse(der.getData(), (byte)0x03, true);
- flags = TicketFlags.parse(der.getData(), (byte)0x04, false);
- authtime = KerberosTime.parse(der.getData(), (byte)0x05, false);
- starttime = KerberosTime.parse(der.getData(), (byte)0x06, true);
- endtime = KerberosTime.parse(der.getData(), (byte)0x07, false);
- renewTill = KerberosTime.parse(der.getData(), (byte)0x08, true);
- srealm = Realm.parse(der.getData(), (byte)0x09, false);
- sname = PrincipalName.parse(der.getData(), (byte)0x0A, false);
- if (der.getData().available() > 0)
- caddr = HostAddresses.parse(der.getData(), (byte)0x0B, true);
- if (der.getData().available() > 0)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
+ der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ key = EncryptionKey.parse(der.getData(), (byte) 0x00, false);
+ lastReq = LastReq.parse(der.getData(), (byte) 0x01, false);
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x02) {
+ nonce = subDer.getData().getBigInteger().intValue();
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ keyExpiration = KerberosTime.parse(der.getData(), (byte) 0x03, true);
+ flags = TicketFlags.parse(der.getData(), (byte) 0x04, false);
+ authtime = KerberosTime.parse(der.getData(), (byte) 0x05, false);
+ starttime = KerberosTime.parse(der.getData(), (byte) 0x06, true);
+ endtime = KerberosTime.parse(der.getData(), (byte) 0x07, false);
+ renewTill = KerberosTime.parse(der.getData(), (byte) 0x08, true);
+ srealm = Realm.parse(der.getData(), (byte) 0x09, false);
+ sname = PrincipalName.parse(der.getData(), (byte) 0x0A, false);
+ if (der.getData().available() > 0) {
+ caddr = HostAddresses.parse(der.getData(), (byte) 0x0B, true);
+ }
+ if (der.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
- /**
- * Encodes an EncKDCRepPart object.
- * @param rep_type type of encrypted reply message.
- * @return byte array of encoded EncKDCRepPart object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- public byte[] asn1Encode(int rep_type) throws Asn1Exception,
- IOException {
+ /**
+ * Encodes an EncKDCRepPart object.
+ * @param rep_type type of encrypted reply message.
+ * @return byte array of encoded EncKDCRepPart object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public byte[] asn1Encode(int rep_type) throws Asn1Exception,
+ IOException {
DerOutputStream temp = new DerOutputStream();
DerOutputStream bytes = new DerOutputStream();
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), key.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), lastReq.asn1Encode());
- temp.putInteger(BigInteger.valueOf(nonce));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), temp);
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x00), key.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x01), lastReq.asn1Encode());
+ temp.putInteger(BigInteger.valueOf(nonce));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x02), temp);
- if (keyExpiration != null)
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), keyExpiration.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), flags.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), authtime.asn1Encode());
- if (starttime != null)
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), starttime.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), endtime.asn1Encode());
- if (renewTill != null)
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), renewTill.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), srealm.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), sname.asn1Encode());
- if (caddr != null)
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0B), caddr.asn1Encode());
- //should use the rep_type to build the encoding
- //but other implementations do not; it is ignored and
- //the cached msgType is used instead
- temp = new DerOutputStream();
- temp.write(DerValue.tag_Sequence, bytes);
- bytes = new DerOutputStream();
- bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)msgType), temp);
- return bytes.toByteArray();
+ if (keyExpiration != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x03), keyExpiration.asn1Encode());
}
-
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x04), flags.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x05), authtime.asn1Encode());
+ if (starttime != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x06), starttime.asn1Encode());
+ }
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x07), endtime.asn1Encode());
+ if (renewTill != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x08), renewTill.asn1Encode());
+ }
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x09), srealm.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x0A), sname.asn1Encode());
+ if (caddr != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x0B), caddr.asn1Encode());
+ }
+ //should use the rep_type to build the encoding
+ //but other implementations do not; it is ignored and
+ //the cached msgType is used instead
+ temp = new DerOutputStream();
+ temp.write(DerValue.tag_Sequence, bytes);
+ bytes = new DerOutputStream();
+ bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION,
+ true, (byte) msgType), temp);
+ return bytes.toByteArray();
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/EncKrbCredPart.java b/jdk/src/share/classes/sun/security/krb5/internal/EncKrbCredPart.java
index f37f252bbaa..c5acf6d2b1c 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/EncKrbCredPart.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/EncKrbCredPart.java
@@ -36,6 +36,7 @@ import sun.security.krb5.RealmException;
import java.util.Vector;
import java.io.IOException;
import java.math.BigInteger;
+
/**
* Implements the ASN.1 EncKrbCredPart type.
*
@@ -57,148 +58,158 @@ import java.math.BigInteger;
* http://www.ietf.org/rfc/rfc4120.txt.
*/
public class EncKrbCredPart {
- public KrbCredInfo[] ticketInfo = null;
- public KerberosTime timeStamp; //optional
- private Integer nonce; //optional
- private Integer usec; //optional
- private HostAddress sAddress; //optional
- private HostAddresses rAddress; //optional
+ public KrbCredInfo[] ticketInfo = null;
+ public KerberosTime timeStamp; //optional
+ private Integer nonce; //optional
+ private Integer usec; //optional
+ private HostAddress sAddress; //optional
+ private HostAddresses rAddress; //optional
- public EncKrbCredPart(
- KrbCredInfo[] new_ticketInfo,
- KerberosTime new_timeStamp,
- Integer new_usec,
- Integer new_nonce,
- HostAddress new_sAddress,
- HostAddresses new_rAddress
- ) throws IOException {
- if (new_ticketInfo != null) {
- ticketInfo = new KrbCredInfo[new_ticketInfo.length];
- for (int i = 0; i < new_ticketInfo.length; i++) {
- if (new_ticketInfo[i] == null) {
- throw new IOException("Cannot create a EncKrbCredPart");
- } else {
- ticketInfo[i] = (KrbCredInfo)new_ticketInfo[i].clone();
- }
- }
+ public EncKrbCredPart(
+ KrbCredInfo[] new_ticketInfo,
+ KerberosTime new_timeStamp,
+ Integer new_usec,
+ Integer new_nonce,
+ HostAddress new_sAddress,
+ HostAddresses new_rAddress) throws IOException {
+ if (new_ticketInfo != null) {
+ ticketInfo = new KrbCredInfo[new_ticketInfo.length];
+ for (int i = 0; i < new_ticketInfo.length; i++) {
+ if (new_ticketInfo[i] == null) {
+ throw new IOException("Cannot create a EncKrbCredPart");
+ } else {
+ ticketInfo[i] = (KrbCredInfo) new_ticketInfo[i].clone();
}
- timeStamp = new_timeStamp;
- usec = new_usec;
- nonce = new_nonce;
- sAddress = new_sAddress;
- rAddress = new_rAddress;
+ }
}
+ timeStamp = new_timeStamp;
+ usec = new_usec;
+ nonce = new_nonce;
+ sAddress = new_sAddress;
+ rAddress = new_rAddress;
+ }
- public EncKrbCredPart(byte[] data) throws Asn1Exception,
- IOException, RealmException {
- init(new DerValue(data));
- }
+ public EncKrbCredPart(byte[] data) throws Asn1Exception,
+ IOException, RealmException {
+ init(new DerValue(data));
+ }
- public EncKrbCredPart(DerValue encoding) throws Asn1Exception,
- IOException, RealmException {
- init(encoding);
- }
+ public EncKrbCredPart(DerValue encoding) throws Asn1Exception,
+ IOException, RealmException {
+ init(encoding);
+ }
- /**
- * Initializes an EncKrbCredPart object.
- * @param encoding a single DER-encoded value.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- * @exception RealmException if an error occurs while parsing a Realm object.
- */
- private void init(DerValue encoding) throws Asn1Exception,
- IOException, RealmException {
- DerValue der, subDer;
- //may not be the correct error code for a tag
- //mismatch on an encrypted structure
- nonce = null;
- timeStamp = null;
- usec= null;
+ /**
+ * Initializes an EncKrbCredPart object.
+ * @param encoding a single DER-encoded value.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ * @exception RealmException if an error occurs while parsing a Realm object.
+ */
+ private void init(DerValue encoding) throws Asn1Exception,
+ IOException, RealmException {
+ DerValue der, subDer;
+ //may not be the correct error code for a tag
+ //mismatch on an encrypted structure
+ nonce = null;
+ timeStamp = null;
+ usec = null;
sAddress = null;
rAddress = null;
- if (((encoding.getTag() & (byte)0x1F) != (byte)0x1D)
- || (encoding.isApplication() != true)
- || (encoding.isConstructed() != true))
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence)
+ if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1D)
+ || (encoding.isApplication() != true)
+ || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x00) {
+ DerValue derValues[] = subDer.getData().getSequence(1);
+ ticketInfo = new KrbCredInfo[derValues.length];
+ for (int i = 0; i < derValues.length; i++) {
+ ticketInfo[i] = new KrbCredInfo(derValues[i]);
+ }
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ if (der.getData().available() > 0) {
+ if (((byte) (der.getData().peekByte()) & (byte) 0x1F) == (byte) 0x01) {
subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) == (byte)0x00) {
- DerValue derValues[] = subDer.getData().getSequence(1);
- ticketInfo = new KrbCredInfo[derValues.length];
- for (int i = 0; i < derValues.length; i++) {
- ticketInfo[i] = new KrbCredInfo(derValues[i]);
- }
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- if (der.getData().available() > 0) {
- if (((byte)(der.getData().peekByte()) & (byte)0x1F) == (byte)0x01) {
- subDer = der.getData().getDerValue();
- nonce = new Integer(subDer.getData().getBigInteger().intValue());
- }
- }
- if (der.getData().available() >0) {
- timeStamp = KerberosTime.parse(der.getData(), (byte)0x02, true);
- }
- if (der.getData().available() >0) {
- if (((byte)(der.getData().peekByte()) & (byte)0x1F) == (byte)0x03) {
- subDer = der.getData().getDerValue();
- usec = new Integer(subDer.getData().getBigInteger().intValue());
- }
- }
- if (der.getData().available() >0) {
- sAddress = HostAddress.parse(der.getData(), (byte)0x04, true);
- }
- if (der.getData().available() >0) {
- rAddress = HostAddresses.parse(der.getData(), (byte)0x05, true);
- }
- if (der.getData().available() >0)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ nonce = new Integer(subDer.getData().getBigInteger().intValue());
+ }
}
+ if (der.getData().available() > 0) {
+ timeStamp = KerberosTime.parse(der.getData(), (byte) 0x02, true);
+ }
+ if (der.getData().available() > 0) {
+ if (((byte) (der.getData().peekByte()) & (byte) 0x1F) == (byte) 0x03) {
+ subDer = der.getData().getDerValue();
+ usec = new Integer(subDer.getData().getBigInteger().intValue());
+ }
+ }
+ if (der.getData().available() > 0) {
+ sAddress = HostAddress.parse(der.getData(), (byte) 0x04, true);
+ }
+ if (der.getData().available() > 0) {
+ rAddress = HostAddresses.parse(der.getData(), (byte) 0x05, true);
+ }
+ if (der.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
- /**
- * Encodes an EncKrbCredPart object.
- * @return byte array of encoded EncKrbCredPart object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- *
- */
- public byte[] asn1Encode() throws Asn1Exception, IOException{
+ /**
+ * Encodes an EncKrbCredPart object.
+ * @return byte array of encoded EncKrbCredPart object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ *
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
DerOutputStream bytes = new DerOutputStream();
- DerOutputStream temp = new DerOutputStream();
- DerValue[] tickets = new DerValue[ticketInfo.length];
- for (int i = 0; i < ticketInfo.length; i++)
- tickets[i] = new DerValue(ticketInfo[i].asn1Encode());
- temp.putSequence(tickets);
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
-
- if (nonce != null) {
- temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(nonce.intValue()));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
- }
- if (timeStamp != null) {
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), timeStamp.asn1Encode());
- }
- if (usec != null) {
- temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(usec.intValue()));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp);
- }
- if (sAddress != null) {
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), sAddress.asn1Encode());
- }
- if (rAddress != null) {
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), rAddress.asn1Encode());
- }
- temp = new DerOutputStream();
- temp.write(DerValue.tag_Sequence, bytes);
- bytes = new DerOutputStream();
- bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x1D), temp);
- return bytes.toByteArray();
+ DerOutputStream temp = new DerOutputStream();
+ DerValue[] tickets = new DerValue[ticketInfo.length];
+ for (int i = 0; i < ticketInfo.length; i++) {
+ tickets[i] = new DerValue(ticketInfo[i].asn1Encode());
}
+ temp.putSequence(tickets);
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x00), temp);
+
+ if (nonce != null) {
+ temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(nonce.intValue()));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x01), temp);
+ }
+ if (timeStamp != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x02), timeStamp.asn1Encode());
+ }
+ if (usec != null) {
+ temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(usec.intValue()));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x03), temp);
+ }
+ if (sAddress != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x04), sAddress.asn1Encode());
+ }
+ if (rAddress != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x05), rAddress.asn1Encode());
+ }
+ temp = new DerOutputStream();
+ temp.write(DerValue.tag_Sequence, bytes);
+ bytes = new DerOutputStream();
+ bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION,
+ true, (byte) 0x1D), temp);
+ return bytes.toByteArray();
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/EncKrbPrivPart.java b/jdk/src/share/classes/sun/security/krb5/internal/EncKrbPrivPart.java
index e4ed50b4ba1..292dd58be3b 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/EncKrbPrivPart.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/EncKrbPrivPart.java
@@ -55,114 +55,119 @@ import java.math.BigInteger;
*
* http://www.ietf.org/rfc/rfc4120.txt.
*/
-
public class EncKrbPrivPart {
- public byte[] userData = null;
- public KerberosTime timestamp; //optional
- public Integer usec; //optional
- public Integer seqNumber; //optional
- public HostAddress sAddress; //optional
- public HostAddress rAddress; //optional
- public EncKrbPrivPart(
- byte[] new_userData,
- KerberosTime new_timestamp,
- Integer new_usec,
- Integer new_seqNumber,
- HostAddress new_sAddress,
- HostAddress new_rAddress
- ) {
- if (new_userData != null) {
- userData = new_userData.clone();
- }
- timestamp = new_timestamp;
- usec = new_usec;
- seqNumber = new_seqNumber;
- sAddress = new_sAddress;
- rAddress = new_rAddress;
+ public byte[] userData = null;
+ public KerberosTime timestamp; //optional
+ public Integer usec; //optional
+ public Integer seqNumber; //optional
+ public HostAddress sAddress; //optional
+ public HostAddress rAddress; //optional
+
+ public EncKrbPrivPart(
+ byte[] new_userData,
+ KerberosTime new_timestamp,
+ Integer new_usec,
+ Integer new_seqNumber,
+ HostAddress new_sAddress,
+ HostAddress new_rAddress) {
+ if (new_userData != null) {
+ userData = new_userData.clone();
}
+ timestamp = new_timestamp;
+ usec = new_usec;
+ seqNumber = new_seqNumber;
+ sAddress = new_sAddress;
+ rAddress = new_rAddress;
+ }
- public EncKrbPrivPart(byte[] data) throws Asn1Exception, IOException {
- init(new DerValue(data));
- }
+ public EncKrbPrivPart(byte[] data) throws Asn1Exception, IOException {
+ init(new DerValue(data));
+ }
- public EncKrbPrivPart(DerValue encoding) throws Asn1Exception, IOException {
- init(encoding);
- }
+ public EncKrbPrivPart(DerValue encoding) throws Asn1Exception, IOException {
+ init(encoding);
+ }
- /**
- * Initializes an EncKrbPrivPart object.
- * @param encoding a single DER-encoded value.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- private void init(DerValue encoding) throws Asn1Exception, IOException {
+ /**
+ * Initializes an EncKrbPrivPart object.
+ * @param encoding a single DER-encoded value.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ private void init(DerValue encoding) throws Asn1Exception, IOException {
DerValue der, subDer;
- if (((encoding.getTag() & (byte)0x1F) != (byte)0x1C)
- || (encoding.isApplication() != true)
- || (encoding.isConstructed() != true))
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence)
+ if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1C)
+ || (encoding.isApplication() != true)
+ || (encoding.isConstructed() != true)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & (byte)0x1F) == (byte)0x00) {
- userData = subDer.getData().getOctetString();
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- timestamp = KerberosTime.parse(der.getData(), (byte)0x01, true);
- if ((der.getData().peekByte() & 0x1F) == 0x02) {
- subDer = der.getData().getDerValue();
- usec = new Integer(subDer.getData().getBigInteger().intValue());
- }
- else usec = null;
- if ((der.getData().peekByte() & 0x1F) == 0x03 ) {
- subDer = der.getData().getDerValue();
- seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
- }
- else seqNumber = null;
- sAddress = HostAddress.parse(der.getData(), (byte)0x04, false);
- if (der.getData().available() > 0) {
- rAddress = HostAddress.parse(der.getData(), (byte)0x05, true);
- }
- if (der.getData().available() > 0)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
+ der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x00) {
+ userData = subDer.getData().getOctetString();
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ timestamp = KerberosTime.parse(der.getData(), (byte) 0x01, true);
+ if ((der.getData().peekByte() & 0x1F) == 0x02) {
+ subDer = der.getData().getDerValue();
+ usec = new Integer(subDer.getData().getBigInteger().intValue());
+ } else {
+ usec = null;
+ }
+ if ((der.getData().peekByte() & 0x1F) == 0x03) {
+ subDer = der.getData().getDerValue();
+ seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
+ } else {
+ seqNumber = null;
+ }
+ sAddress = HostAddress.parse(der.getData(), (byte) 0x04, false);
+ if (der.getData().available() > 0) {
+ rAddress = HostAddress.parse(der.getData(), (byte) 0x05, true);
+ }
+ if (der.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
- /**
- * Encodes an EncKrbPrivPart object.
- * @return byte array of encoded EncKrbPrivPart object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- public byte[] asn1Encode() throws Asn1Exception, IOException {
+ /**
+ * Encodes an EncKrbPrivPart object.
+ * @return byte array of encoded EncKrbPrivPart object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
DerOutputStream temp = new DerOutputStream();
DerOutputStream bytes = new DerOutputStream();
- temp.putOctetString(userData);
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
- if (timestamp != null)
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), timestamp.asn1Encode());
- if (usec != null) {
- temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(usec.intValue()));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), temp);
- }
- if (seqNumber != null) {
- temp = new DerOutputStream();
- // encode as an unsigned integer (UInt32)
- temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp);
- }
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), sAddress.asn1Encode());
- if (rAddress != null) {
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), rAddress.asn1Encode());
- }
- temp = new DerOutputStream();
- temp.write(DerValue.tag_Sequence, bytes);
- bytes = new DerOutputStream();
- bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x1C), temp);
- return bytes.toByteArray();
+ temp.putOctetString(userData);
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
+ if (timestamp != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), timestamp.asn1Encode());
}
+ if (usec != null) {
+ temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(usec.intValue()));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), temp);
+ }
+ if (seqNumber != null) {
+ temp = new DerOutputStream();
+ // encode as an unsigned integer (UInt32)
+ temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), temp);
+ }
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x04), sAddress.asn1Encode());
+ if (rAddress != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x05), rAddress.asn1Encode());
+ }
+ temp = new DerOutputStream();
+ temp.write(DerValue.tag_Sequence, bytes);
+ bytes = new DerOutputStream();
+ bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x1C), temp);
+ return bytes.toByteArray();
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/EncTGSRepPart.java b/jdk/src/share/classes/sun/security/krb5/internal/EncTGSRepPart.java
index 95c100a020a..864115e52e9 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/EncTGSRepPart.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/EncTGSRepPart.java
@@ -35,55 +35,52 @@ import java.io.IOException;
public class EncTGSRepPart extends EncKDCRepPart {
- public EncTGSRepPart(
- EncryptionKey new_key,
- LastReq new_lastReq,
- int new_nonce,
- KerberosTime new_keyExpiration,
- TicketFlags new_flags,
- KerberosTime new_authtime,
- KerberosTime new_starttime,
- KerberosTime new_endtime,
- KerberosTime new_renewTill,
- Realm new_srealm,
- PrincipalName new_sname,
- HostAddresses new_caddr
- ) {
- super(
- new_key,
- new_lastReq,
- new_nonce,
- new_keyExpiration,
- new_flags,
- new_authtime,
- new_starttime,
- new_endtime,
- new_renewTill,
- new_srealm,
- new_sname,
- new_caddr,
- Krb5.KRB_ENC_TGS_REP_PART
- );
- }
+ public EncTGSRepPart(
+ EncryptionKey new_key,
+ LastReq new_lastReq,
+ int new_nonce,
+ KerberosTime new_keyExpiration,
+ TicketFlags new_flags,
+ KerberosTime new_authtime,
+ KerberosTime new_starttime,
+ KerberosTime new_endtime,
+ KerberosTime new_renewTill,
+ Realm new_srealm,
+ PrincipalName new_sname,
+ HostAddresses new_caddr) {
+ super(
+ new_key,
+ new_lastReq,
+ new_nonce,
+ new_keyExpiration,
+ new_flags,
+ new_authtime,
+ new_starttime,
+ new_endtime,
+ new_renewTill,
+ new_srealm,
+ new_sname,
+ new_caddr,
+ Krb5.KRB_ENC_TGS_REP_PART);
+ }
- public EncTGSRepPart(byte[] data) throws Asn1Exception,
- IOException, KrbException {
- init(new DerValue(data));
- }
+ public EncTGSRepPart(byte[] data) throws Asn1Exception,
+ IOException, KrbException {
+ init(new DerValue(data));
+ }
- public EncTGSRepPart(DerValue encoding) throws Asn1Exception,
- IOException, KrbException {
- init(encoding);
- }
+ public EncTGSRepPart(DerValue encoding) throws Asn1Exception,
+ IOException, KrbException {
+ init(encoding);
+ }
- private void init(DerValue encoding) throws Asn1Exception,
- IOException, KrbException {
- init(encoding, Krb5.KRB_ENC_TGS_REP_PART);
- }
-
- public byte[] asn1Encode() throws Asn1Exception,
- IOException {
- return asn1Encode(Krb5.KRB_ENC_TGS_REP_PART);
- }
+ private void init(DerValue encoding) throws Asn1Exception,
+ IOException, KrbException {
+ init(encoding, Krb5.KRB_ENC_TGS_REP_PART);
+ }
+ public byte[] asn1Encode() throws Asn1Exception,
+ IOException {
+ return asn1Encode(Krb5.KRB_ENC_TGS_REP_PART);
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/EncTicketPart.java b/jdk/src/share/classes/sun/security/krb5/internal/EncTicketPart.java
index 5f315095825..73eb814445b 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/EncTicketPart.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/EncTicketPart.java
@@ -62,69 +62,68 @@ import java.io.*;
* http://www.ietf.org/rfc/rfc4120.txt.
*/
public class EncTicketPart {
- public TicketFlags flags;
- public EncryptionKey key;
- public Realm crealm;
- public PrincipalName cname;
- public TransitedEncoding transited;
- public KerberosTime authtime;
- public KerberosTime starttime; //optional
- public KerberosTime endtime;
- public KerberosTime renewTill; //optional
- public HostAddresses caddr; //optional
- public AuthorizationData authorizationData; //optional
- public EncTicketPart(
- TicketFlags new_flags,
- EncryptionKey new_key,
- Realm new_crealm,
- PrincipalName new_cname,
- TransitedEncoding new_transited,
- KerberosTime new_authtime,
- KerberosTime new_starttime,
- KerberosTime new_endtime,
- KerberosTime new_renewTill,
- HostAddresses new_caddr,
- AuthorizationData new_authorizationData
- ) {
- flags = new_flags;
- key = new_key;
- crealm = new_crealm;
- cname = new_cname;
- transited = new_transited;
- authtime = new_authtime;
- starttime = new_starttime;
- endtime = new_endtime;
- renewTill = new_renewTill;
- caddr = new_caddr;
- authorizationData = new_authorizationData;
- }
+ public TicketFlags flags;
+ public EncryptionKey key;
+ public Realm crealm;
+ public PrincipalName cname;
+ public TransitedEncoding transited;
+ public KerberosTime authtime;
+ public KerberosTime starttime; //optional
+ public KerberosTime endtime;
+ public KerberosTime renewTill; //optional
+ public HostAddresses caddr; //optional
+ public AuthorizationData authorizationData; //optional
- public EncTicketPart(byte[] data)
- throws Asn1Exception, KrbException, IOException {
- init(new DerValue(data));
- }
+ public EncTicketPart(
+ TicketFlags new_flags,
+ EncryptionKey new_key,
+ Realm new_crealm,
+ PrincipalName new_cname,
+ TransitedEncoding new_transited,
+ KerberosTime new_authtime,
+ KerberosTime new_starttime,
+ KerberosTime new_endtime,
+ KerberosTime new_renewTill,
+ HostAddresses new_caddr,
+ AuthorizationData new_authorizationData) {
+ flags = new_flags;
+ key = new_key;
+ crealm = new_crealm;
+ cname = new_cname;
+ transited = new_transited;
+ authtime = new_authtime;
+ starttime = new_starttime;
+ endtime = new_endtime;
+ renewTill = new_renewTill;
+ caddr = new_caddr;
+ authorizationData = new_authorizationData;
+ }
- public EncTicketPart(DerValue encoding)
- throws Asn1Exception, KrbException, IOException {
- init(encoding);
- }
+ public EncTicketPart(byte[] data)
+ throws Asn1Exception, KrbException, IOException {
+ init(new DerValue(data));
+ }
- /**
- * Initializes an EncTicketPart object.
- * @param encoding a single DER-encoded value.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- * @exception RealmException if an error occurs while parsing a Realm object.
- */
+ public EncTicketPart(DerValue encoding)
+ throws Asn1Exception, KrbException, IOException {
+ init(encoding);
+ }
+ /**
+ * Initializes an EncTicketPart object.
+ * @param encoding a single DER-encoded value.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ * @exception RealmException if an error occurs while parsing a Realm object.
+ */
private static String getHexBytes(byte[] bytes, int len)
- throws IOException {
+ throws IOException {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < len; i++) {
- int b1 = (bytes[i]>>4) & 0x0f;
+ int b1 = (bytes[i] >> 4) & 0x0f;
int b2 = bytes[i] & 0x0f;
sb.append(Integer.toHexString(b1));
@@ -134,73 +133,91 @@ public class EncTicketPart {
return sb.toString();
}
- private void init(DerValue encoding)
- throws Asn1Exception, IOException, RealmException {
- DerValue der, subDer;
+ private void init(DerValue encoding)
+ throws Asn1Exception, IOException, RealmException {
+ DerValue der, subDer;
- renewTill = null;
- caddr = null;
- authorizationData = null;
- if (((encoding.getTag() & (byte)0x1F) != (byte)0x03)
+ renewTill = null;
+ caddr = null;
+ authorizationData = null;
+ if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x03)
|| (encoding.isApplication() != true)
- || (encoding.isConstructed() != true))
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- flags = TicketFlags.parse(der.getData(), (byte)0x00, false);
- key = EncryptionKey.parse(der.getData(), (byte)0x01, false);
- crealm = Realm.parse(der.getData(), (byte)0x02, false);
- cname = PrincipalName.parse(der.getData(), (byte)0x03, false);
- transited = TransitedEncoding.parse(der.getData(), (byte)0x04, false);
- authtime = KerberosTime.parse(der.getData(), (byte)0x05, false);
- starttime = KerberosTime.parse(der.getData(), (byte)0x06, true);
- endtime = KerberosTime.parse(der.getData(), (byte)0x07, false);
- if (der.getData().available() > 0) {
- renewTill = KerberosTime.parse(der.getData(), (byte)0x08, true);
- }
- if (der.getData().available() > 0) {
- caddr = HostAddresses.parse(der.getData(), (byte)0x09, true);
- }
- if (der.getData().available() > 0) {
- authorizationData = AuthorizationData.parse(der.getData(), (byte)0x0A, true);
- }
- if (der.getData().available() > 0)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
-
+ || (encoding.isConstructed() != true)) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ flags = TicketFlags.parse(der.getData(), (byte) 0x00, false);
+ key = EncryptionKey.parse(der.getData(), (byte) 0x01, false);
+ crealm = Realm.parse(der.getData(), (byte) 0x02, false);
+ cname = PrincipalName.parse(der.getData(), (byte) 0x03, false);
+ transited = TransitedEncoding.parse(der.getData(), (byte) 0x04, false);
+ authtime = KerberosTime.parse(der.getData(), (byte) 0x05, false);
+ starttime = KerberosTime.parse(der.getData(), (byte) 0x06, true);
+ endtime = KerberosTime.parse(der.getData(), (byte) 0x07, false);
+ if (der.getData().available() > 0) {
+ renewTill = KerberosTime.parse(der.getData(), (byte) 0x08, true);
+ }
+ if (der.getData().available() > 0) {
+ caddr = HostAddresses.parse(der.getData(), (byte) 0x09, true);
+ }
+ if (der.getData().available() > 0) {
+ authorizationData = AuthorizationData.parse(der.getData(), (byte) 0x0A, true);
+ }
+ if (der.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
- /**
- * Encodes an EncTicketPart object.
- * @return byte array of encoded EncTicketPart object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
+ }
- public byte[] asn1Encode() throws Asn1Exception, IOException {
+ /**
+ * Encodes an EncTicketPart object.
+ * @return byte array of encoded EncTicketPart object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
DerOutputStream bytes = new DerOutputStream();
- DerOutputStream temp = new DerOutputStream();
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), flags.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), key.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), crealm.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), cname.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), transited.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), authtime.asn1Encode());
- if (starttime != null)
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), starttime.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), endtime.asn1Encode());
-
- if (renewTill != null)
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), renewTill.asn1Encode());
-
- if (caddr != null)
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), caddr.asn1Encode());
-
- if (authorizationData != null)
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), authorizationData.asn1Encode());
- temp.write(DerValue.tag_Sequence, bytes);
- bytes = new DerOutputStream();
- bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x03), temp);
- return bytes.toByteArray();
+ DerOutputStream temp = new DerOutputStream();
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x00), flags.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x01), key.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x02), crealm.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x03), cname.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x04), transited.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x05), authtime.asn1Encode());
+ if (starttime != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x06), starttime.asn1Encode());
}
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x07), endtime.asn1Encode());
+
+ if (renewTill != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x08), renewTill.asn1Encode());
+ }
+
+ if (caddr != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x09), caddr.asn1Encode());
+ }
+
+ if (authorizationData != null) {
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x0A), authorizationData.asn1Encode());
+ }
+ temp.write(DerValue.tag_Sequence, bytes);
+ bytes = new DerOutputStream();
+ bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION,
+ true, (byte) 0x03), temp);
+ return bytes.toByteArray();
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/KDCRep.java b/jdk/src/share/classes/sun/security/krb5/internal/KDCRep.java
index ca1d777ed23..f7cc7180082 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/KDCRep.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/KDCRep.java
@@ -35,6 +35,7 @@ import sun.security.util.*;
import java.util.Vector;
import java.io.IOException;
import java.math.BigInteger;
+
/**
* Implements the ASN.1 KDC-REP type.
*
@@ -59,163 +60,168 @@ import java.math.BigInteger;
*
* http://www.ietf.org/rfc/rfc4120.txt.
*/
-
public class KDCRep {
- public Realm crealm;
- public PrincipalName cname;
- public Ticket ticket;
- public EncryptedData encPart;
- public EncKDCRepPart encKDCRepPart; //not part of ASN.1 encoding
- private int pvno;
- private int msgType;
- private PAData[] pAData = null; //optional
- private boolean DEBUG = Krb5.DEBUG;
+ public Realm crealm;
+ public PrincipalName cname;
+ public Ticket ticket;
+ public EncryptedData encPart;
+ public EncKDCRepPart encKDCRepPart; //not part of ASN.1 encoding
+ private int pvno;
+ private int msgType;
+ private PAData[] pAData = null; //optional
+ private boolean DEBUG = Krb5.DEBUG;
- public KDCRep(
- PAData[] new_pAData,
- Realm new_crealm,
- PrincipalName new_cname,
- Ticket new_ticket,
- EncryptedData new_encPart,
- int req_type
- ) throws IOException {
- pvno = Krb5.PVNO;
- msgType = req_type;
- if (new_pAData != null) {
- pAData = new PAData[new_pAData.length];
- for (int i = 0; i < new_pAData.length; i++) {
- if (new_pAData[i] == null) {
- throw new IOException("Cannot create a KDCRep");
- } else {
- pAData[i] = (PAData)new_pAData[i].clone();
- }
- }
+ public KDCRep(
+ PAData[] new_pAData,
+ Realm new_crealm,
+ PrincipalName new_cname,
+ Ticket new_ticket,
+ EncryptedData new_encPart,
+ int req_type) throws IOException {
+ pvno = Krb5.PVNO;
+ msgType = req_type;
+ if (new_pAData != null) {
+ pAData = new PAData[new_pAData.length];
+ for (int i = 0; i < new_pAData.length; i++) {
+ if (new_pAData[i] == null) {
+ throw new IOException("Cannot create a KDCRep");
+ } else {
+ pAData[i] = (PAData) new_pAData[i].clone();
}
- crealm = new_crealm;
- cname = new_cname;
- ticket = new_ticket;
- encPart = new_encPart;
+ }
}
+ crealm = new_crealm;
+ cname = new_cname;
+ ticket = new_ticket;
+ encPart = new_encPart;
+ }
- public KDCRep() {
- }
+ public KDCRep() {
+ }
- public KDCRep(byte[] data, int req_type) throws Asn1Exception, KrbApErrException, RealmException, IOException {
- init(new DerValue(data), req_type);
- }
+ public KDCRep(byte[] data, int req_type) throws Asn1Exception,
+ KrbApErrException, RealmException, IOException {
+ init(new DerValue(data), req_type);
+ }
- public KDCRep(DerValue encoding, int req_type) throws Asn1Exception,
- RealmException, KrbApErrException, IOException {
- init(encoding, req_type);
- }
+ public KDCRep(DerValue encoding, int req_type) throws Asn1Exception,
+ RealmException, KrbApErrException, IOException {
+ init(encoding, req_type);
+ }
/*
// Not used? Don't know what keyusage to use here %%%
-
- public void decrypt(EncryptionKey key) throws Asn1Exception,
- IOException, KrbException, RealmException {
- encKDCRepPart = new EncKDCRepPart(encPart.decrypt(key),
- msgType);
- }
-*/
-
- /**
- * Initializes an KDCRep object.
- *
- * @param encoding a single DER-encoded value.
- * @param req_type reply message type.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- * @exception RealmException if an error occurs while constructing a Realm object from DER-encoded data.
- * @exception KrbApErrException if the value read from the DER-encoded data stream does not match the pre-defined value.
- *
- */
- protected void init(DerValue encoding, int req_type)
+ public void decrypt(EncryptionKey key) throws Asn1Exception,
+ IOException, KrbException, RealmException {
+ encKDCRepPart = new EncKDCRepPart(encPart.decrypt(key), msgType);
+ }
+ */
+ /**
+ * Initializes an KDCRep object.
+ *
+ * @param encoding a single DER-encoded value.
+ * @param req_type reply message type.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ * @exception RealmException if an error occurs while constructing
+ * a Realm object from DER-encoded data.
+ * @exception KrbApErrException if the value read from the DER-encoded
+ * data stream does not match the pre-defined value.
+ *
+ */
+ protected void init(DerValue encoding, int req_type)
throws Asn1Exception, RealmException, IOException,
- KrbApErrException {
- DerValue der, subDer;
- if ((encoding.getTag() & 0x1F) != req_type) {
- if (DEBUG) {
- System.out.println(">>> KDCRep: init() " +
- "encoding tag is " +
- encoding.getTag() +
- " req type is " + req_type);
- }
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence) {
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x1F) == 0x00) {
- pvno = subDer.getData().getBigInteger().intValue();
- if (pvno != Krb5.PVNO)
- throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
- } else {
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x1F) == 0x01) {
- msgType = subDer.getData().getBigInteger().intValue();
- if (msgType != req_type) {
- throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
- }
- } else {
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- if ((der.getData().peekByte() & 0x1F) == 0x02) {
- subDer = der.getData().getDerValue();
- DerValue[] padata = subDer.getData().getSequence(1);
- pAData = new PAData[padata.length];
- for (int i = 0; i < padata.length; i++) {
- pAData[i] = new PAData(padata[i]);
- }
- } else {
- pAData = null;
- }
- crealm = Realm.parse(der.getData(), (byte)0x03, false);
- cname = PrincipalName.parse(der.getData(), (byte)0x04, false);
- ticket = Ticket.parse(der.getData(), (byte)0x05, false);
- encPart = EncryptedData.parse(der.getData(), (byte)0x06, false);
- if (der.getData().available() > 0) {
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ KrbApErrException {
+ DerValue der, subDer;
+ if ((encoding.getTag() & 0x1F) != req_type) {
+ if (DEBUG) {
+ System.out.println(">>> KDCRep: init() " +
+ "encoding tag is " +
+ encoding.getTag() +
+ " req type is " + req_type);
}
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
-
-
- /**
- * Encodes this object to a byte array.
- * @return byte array of encoded APReq object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- *
- */
- public byte[] asn1Encode() throws Asn1Exception, IOException {
-
- DerOutputStream bytes = new DerOutputStream();
- DerOutputStream temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(pvno));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
- temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(msgType));
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
- if (pAData != null && pAData.length > 0) {
- DerOutputStream padata_stream = new DerOutputStream();
- for (int i = 0; i < pAData.length; i++) {
- padata_stream.write(pAData[i].asn1Encode());
- }
- temp = new DerOutputStream();
- temp.write(DerValue.tag_SequenceOf, padata_stream);
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), temp);
- }
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), crealm.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), cname.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), ticket.asn1Encode());
- bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), encPart.asn1Encode());
- temp = new DerOutputStream();
- temp.write(DerValue.tag_Sequence, bytes);
- return temp.toByteArray();
+ der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & 0x1F) == 0x00) {
+ pvno = subDer.getData().getBigInteger().intValue();
+ if (pvno != Krb5.PVNO) {
+ throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
+ }
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & 0x1F) == 0x01) {
+ msgType = subDer.getData().getBigInteger().intValue();
+ if (msgType != req_type) {
+ throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
+ }
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ if ((der.getData().peekByte() & 0x1F) == 0x02) {
+ subDer = der.getData().getDerValue();
+ DerValue[] padata = subDer.getData().getSequence(1);
+ pAData = new PAData[padata.length];
+ for (int i = 0; i < padata.length; i++) {
+ pAData[i] = new PAData(padata[i]);
+ }
+ } else {
+ pAData = null;
+ }
+ crealm = Realm.parse(der.getData(), (byte) 0x03, false);
+ cname = PrincipalName.parse(der.getData(), (byte) 0x04, false);
+ ticket = Ticket.parse(der.getData(), (byte) 0x05, false);
+ encPart = EncryptedData.parse(der.getData(), (byte) 0x06, false);
+ if (der.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
+
+ /**
+ * Encodes this object to a byte array.
+ * @return byte array of encoded APReq object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ *
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
+
+ DerOutputStream bytes = new DerOutputStream();
+ DerOutputStream temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(pvno));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x00), temp);
+ temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(msgType));
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x01), temp);
+ if (pAData != null && pAData.length > 0) {
+ DerOutputStream padata_stream = new DerOutputStream();
+ for (int i = 0; i < pAData.length; i++) {
+ padata_stream.write(pAData[i].asn1Encode());
+ }
+ temp = new DerOutputStream();
+ temp.write(DerValue.tag_SequenceOf, padata_stream);
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x02), temp);
+ }
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x03), crealm.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x04), cname.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x05), ticket.asn1Encode());
+ bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x06), encPart.asn1Encode());
+ temp = new DerOutputStream();
+ temp.write(DerValue.tag_Sequence, bytes);
+ return temp.toByteArray();
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/KDCReq.java b/jdk/src/share/classes/sun/security/krb5/internal/KDCReq.java
index 2f049895695..fee4567c3c6 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/KDCReq.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/KDCReq.java
@@ -56,155 +56,160 @@ import java.math.BigInteger;
*
* http://www.ietf.org/rfc/rfc4120.txt.
*/
-
public class KDCReq {
- public KDCReqBody reqBody;
- private int pvno;
- private int msgType;
- private PAData[] pAData = null; //optional
+ public KDCReqBody reqBody;
+ private int pvno;
+ private int msgType;
+ private PAData[] pAData = null; //optional
- public KDCReq(PAData[] new_pAData, KDCReqBody new_reqBody,
- int req_type) throws IOException {
- pvno = Krb5.PVNO;
- msgType = req_type;
- if (new_pAData != null) {
- pAData = new PAData[new_pAData.length];
- for (int i = 0; i < new_pAData.length; i++) {
- if (new_pAData[i] == null) {
- throw new IOException("Cannot create a KDCRep");
- } else {
- pAData[i] = (PAData)new_pAData[i].clone();
- }
- }
+ public KDCReq(PAData[] new_pAData, KDCReqBody new_reqBody,
+ int req_type) throws IOException {
+ pvno = Krb5.PVNO;
+ msgType = req_type;
+ if (new_pAData != null) {
+ pAData = new PAData[new_pAData.length];
+ for (int i = 0; i < new_pAData.length; i++) {
+ if (new_pAData[i] == null) {
+ throw new IOException("Cannot create a KDCRep");
+ } else {
+ pAData[i] = (PAData) new_pAData[i].clone();
}
- reqBody = new_reqBody;
+ }
}
+ reqBody = new_reqBody;
+ }
- public KDCReq() {
- }
+ public KDCReq() {
+ }
- public KDCReq(byte[] data, int req_type) throws Asn1Exception,
- IOException, KrbException {
+ public KDCReq(byte[] data, int req_type) throws Asn1Exception,
+ IOException, KrbException {
init(new DerValue(data), req_type);
- }
+ }
/**
- * Creates an KDCReq object from a DerValue object and asn1 type.
- *
- * @param der a DER value of an KDCReq object.
- * @param req_type a encoded asn1 type value.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- * @exceptoin KrbErrException
- */
+ * Creates an KDCReq object from a DerValue object and asn1 type.
+ *
+ * @param der a DER value of an KDCReq object.
+ * @param req_type a encoded asn1 type value.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ * @exceptoin KrbErrException
+ */
public KDCReq(DerValue der, int req_type) throws Asn1Exception,
- IOException, KrbException {
- init(der, req_type);
- }
+ IOException, KrbException {
+ init(der, req_type);
+ }
- /**
- * Initializes a KDCReq object from a DerValue. The DER encoding
- * must be in the format specified by the KRB_KDC_REQ ASN.1 notation.
- *
- * @param encoding a DER-encoded KDCReq object.
- * @param req_type an int indicating whether it's KRB_AS_REQ or KRB_TGS_REQ type
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- * @exception KrbException if an error occurs while constructing a Realm object,
- * or a Krb object from DER-encoded data.
- */
+ /**
+ * Initializes a KDCReq object from a DerValue. The DER encoding
+ * must be in the format specified by the KRB_KDC_REQ ASN.1 notation.
+ *
+ * @param encoding a DER-encoded KDCReq object.
+ * @param req_type an int indicating whether it's KRB_AS_REQ or KRB_TGS_REQ type
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ * @exception KrbException if an error occurs while constructing a Realm object,
+ * or a Krb object from DER-encoded data.
+ */
protected void init(DerValue encoding, int req_type) throws Asn1Exception,
- IOException, KrbException {
- DerValue der, subDer;
- BigInteger bint;
- if ((encoding.getTag() & 0x1F) != req_type) {
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence) {
+ IOException, KrbException {
+ DerValue der, subDer;
+ BigInteger bint;
+ if ((encoding.getTag() & 0x1F) != req_type) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x01F) == 0x01) {
- bint = subDer.getData().getBigInteger();
- this.pvno = bint.intValue();
- if (this.pvno != Krb5.PVNO)
- throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x01F) == 0x02) {
- bint = subDer.getData().getBigInteger();
- this.msgType = bint.intValue();
- if (this.msgType != req_type)
- throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x01F) == 0x03) {
- DerValue subsubDer = subDer.getData().getDerValue();
- if (subsubDer.getTag() != DerValue.tag_SequenceOf) {
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- Vector v = new Vector ();
- while (subsubDer.getData().available() > 0) {
- v.addElement(new PAData(subsubDer.getData().getDerValue()));
- }
- if (v.size() > 0) {
- pAData = new PAData[v.size()];
- v.copyInto(pAData);
- }
- }
- else pAData = null;
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x01F) == 0x04) {
- DerValue subsubDer = subDer.getData().getDerValue();
- reqBody = new KDCReqBody(subsubDer, msgType);
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
+ der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & 0x01F) == 0x01) {
+ bint = subDer.getData().getBigInteger();
+ this.pvno = bint.intValue();
+ if (this.pvno != Krb5.PVNO) {
+ throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
+ }
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & 0x01F) == 0x02) {
+ bint = subDer.getData().getBigInteger();
+ this.msgType = bint.intValue();
+ if (this.msgType != req_type) {
+ throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
+ }
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & 0x01F) == 0x03) {
+ DerValue subsubDer = subDer.getData().getDerValue();
+ if (subsubDer.getTag() != DerValue.tag_SequenceOf) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ Vector v = new Vector();
+ while (subsubDer.getData().available() > 0) {
+ v.addElement(new PAData(subsubDer.getData().getDerValue()));
+ }
+ if (v.size() > 0) {
+ pAData = new PAData[v.size()];
+ v.copyInto(pAData);
+ }
+ } else {
+ pAData = null;
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & 0x01F) == 0x04) {
+ DerValue subsubDer = subDer.getData().getDerValue();
+ reqBody = new KDCReqBody(subsubDer, msgType);
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
- /**
- * Encodes this object to a byte array.
- *
- * @return an byte array of encoded data.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- *
- */
+ /**
+ * Encodes this object to a byte array.
+ *
+ * @return an byte array of encoded data.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ *
+ */
public byte[] asn1Encode() throws Asn1Exception, IOException {
- DerOutputStream temp, bytes, out;
- temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(pvno));
- out = new DerOutputStream();
- out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
- temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(msgType));
- out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), temp);
+ DerOutputStream temp, bytes, out;
+ temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(pvno));
+ out = new DerOutputStream();
+ out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x01), temp);
+ temp = new DerOutputStream();
+ temp.putInteger(BigInteger.valueOf(msgType));
+ out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x02), temp);
if (pAData != null && pAData.length > 0) {
- temp = new DerOutputStream();
- for (int i = 0; i < pAData.length; i++) {
- temp.write(pAData[i].asn1Encode());
- }
- bytes = new DerOutputStream();
- bytes.write(DerValue.tag_SequenceOf, temp);
- out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), bytes);
- }
- out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), reqBody.asn1Encode(msgType));
- bytes = new DerOutputStream();
- bytes.write(DerValue.tag_Sequence, out);
- out = new DerOutputStream();
- out.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)msgType), bytes);
- return out.toByteArray();
- }
-
- public byte[] asn1EncodeReqBody() throws Asn1Exception, IOException
- {
- return reqBody.asn1Encode(msgType);
+ temp = new DerOutputStream();
+ for (int i = 0; i < pAData.length; i++) {
+ temp.write(pAData[i].asn1Encode());
+ }
+ bytes = new DerOutputStream();
+ bytes.write(DerValue.tag_SequenceOf, temp);
+ out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x03), bytes);
}
+ out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x04), reqBody.asn1Encode(msgType));
+ bytes = new DerOutputStream();
+ bytes.write(DerValue.tag_Sequence, out);
+ out = new DerOutputStream();
+ out.write(DerValue.createTag(DerValue.TAG_APPLICATION,
+ true, (byte) msgType), bytes);
+ return out.toByteArray();
+ }
+ public byte[] asn1EncodeReqBody() throws Asn1Exception, IOException {
+ return reqBody.asn1Encode(msgType);
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/KRBCred.java b/jdk/src/share/classes/sun/security/krb5/internal/KRBCred.java
index 2c364e834b0..a30ca6d2929 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/KRBCred.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/KRBCred.java
@@ -56,128 +56,134 @@ import java.math.BigInteger;
*
* http://www.ietf.org/rfc/rfc4120.txt.
*/
-
public class KRBCred {
- public Ticket[] tickets = null;
- public EncryptedData encPart;
- private int pvno;
- private int msgType;
+ public Ticket[] tickets = null;
+ public EncryptedData encPart;
+ private int pvno;
+ private int msgType;
- public KRBCred(Ticket[] new_tickets, EncryptedData new_encPart) throws IOException {
- pvno = Krb5.PVNO;
- msgType = Krb5.KRB_CRED;
- if (new_tickets != null) {
- tickets = new Ticket[new_tickets.length];
- for (int i = 0; i < new_tickets.length; i++) {
- if (new_tickets[i] == null) {
- throw new IOException("Cannot create a KRBCred");
- } else {
- tickets[i] = (Ticket)new_tickets[i].clone();
- }
- }
+ public KRBCred(Ticket[] new_tickets, EncryptedData new_encPart) throws IOException {
+ pvno = Krb5.PVNO;
+ msgType = Krb5.KRB_CRED;
+ if (new_tickets != null) {
+ tickets = new Ticket[new_tickets.length];
+ for (int i = 0; i < new_tickets.length; i++) {
+ if (new_tickets[i] == null) {
+ throw new IOException("Cannot create a KRBCred");
+ } else {
+ tickets[i] = (Ticket) new_tickets[i].clone();
}
- encPart = new_encPart;
+ }
}
+ encPart = new_encPart;
+ }
- public KRBCred(byte[] data) throws Asn1Exception,
- RealmException, KrbApErrException, IOException {
- init(new DerValue(data));
+ public KRBCred(byte[] data) throws Asn1Exception,
+ RealmException, KrbApErrException, IOException {
+ init(new DerValue(data));
+ }
+
+ public KRBCred(DerValue encoding) throws Asn1Exception,
+ RealmException, KrbApErrException, IOException {
+ init(encoding);
+ }
+
+ /**
+ * Initializes an KRBCred object.
+ * @param encoding a single DER-encoded value.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ * @exception KrbApErrException if the value read from the DER-encoded data
+ * stream does not match the pre-defined value.
+ * @exception RealmException if an error occurs while parsing a Realm object.
+ */
+ private void init(DerValue encoding) throws Asn1Exception,
+ RealmException, KrbApErrException, IOException {
+ if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x16)
+ || (encoding.isApplication() != true)
+ || (encoding.isConstructed() != true)) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
-
- public KRBCred(DerValue encoding) throws Asn1Exception,
- RealmException, KrbApErrException, IOException {
- init(encoding);
- }
-
- /**
- * Initializes an KRBCred object.
- * @param encoding a single DER-encoded value.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- * @exception KrbApErrException if the value read from the DER-encoded data
- * stream does not match the pre-defined value.
- * @exception RealmException if an error occurs while parsing a Realm object.
- */
- private void init(DerValue encoding) throws Asn1Exception,
- RealmException, KrbApErrException, IOException {
- if (((encoding.getTag() & (byte)0x1F) != (byte)0x16)
- || (encoding.isApplication() != true)
- || (encoding.isConstructed() != true))
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
DerValue der, subDer;
- der = encoding.getData().getDerValue();
- if (der.getTag() != DerValue.tag_Sequence)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x1F) == 0x00) {
- pvno = subDer.getData().getBigInteger().intValue();
- if (pvno != Krb5.PVNO) {
- throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
- }
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x1F) == 0x01) {
- msgType = subDer.getData().getBigInteger().intValue();
- if (msgType != Krb5.KRB_CRED)
- throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x1F) == 0x02) {
- DerValue subsubDer = subDer.getData().getDerValue();
- if (subsubDer.getTag() != DerValue.tag_SequenceOf) {
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- }
- Vector v = new Vector ();
- while (subsubDer.getData().available() > 0) {
- v.addElement(new Ticket(subsubDer.getData().getDerValue()));
- }
- if (v.size() > 0) {
- tickets = new Ticket[v.size()];
- v.copyInto(tickets);
- }
- }
- else
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
- encPart = EncryptedData.parse(der.getData(), (byte)0x03, false);
-
- if (der.getData().available() > 0)
- throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ der = encoding.getData().getDerValue();
+ if (der.getTag() != DerValue.tag_Sequence) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & 0x1F) == 0x00) {
+ pvno = subDer.getData().getBigInteger().intValue();
+ if (pvno != Krb5.PVNO) {
+ throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
+ }
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & 0x1F) == 0x01) {
+ msgType = subDer.getData().getBigInteger().intValue();
+ if (msgType != Krb5.KRB_CRED) {
+ throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
+ }
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ subDer = der.getData().getDerValue();
+ if ((subDer.getTag() & 0x1F) == 0x02) {
+ DerValue subsubDer = subDer.getData().getDerValue();
+ if (subsubDer.getTag() != DerValue.tag_SequenceOf) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ Vector v = new Vector();
+ while (subsubDer.getData().available() > 0) {
+ v.addElement(new Ticket(subsubDer.getData().getDerValue()));
+ }
+ if (v.size() > 0) {
+ tickets = new Ticket[v.size()];
+ v.copyInto(tickets);
+ }
+ } else {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ encPart = EncryptedData.parse(der.getData(), (byte) 0x03, false);
+ if (der.getData().available() > 0) {
+ throw new Asn1Exception(Krb5.ASN1_BAD_ID);
+ }
+ }
- /**
- * Encodes an KRBCred object.
- * @return the data of encoded EncAPRepPart object.
- * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
- * @exception IOException if an I/O error occurs while reading encoded data.
- */
- public byte[] asn1Encode() throws Asn1Exception, IOException {
+ /**
+ * Encodes an KRBCred object.
+ * @return the data of encoded EncAPRepPart object.
+ * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
+ * @exception IOException if an I/O error occurs while reading encoded data.
+ */
+ public byte[] asn1Encode() throws Asn1Exception, IOException {
DerOutputStream temp, bytes, out;
temp = new DerOutputStream();
temp.putInteger(BigInteger.valueOf(pvno));
out = new DerOutputStream();
- out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
- temp = new DerOutputStream();
- temp.putInteger(BigInteger.valueOf(msgType));
- out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
+ out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x00), temp);
temp = new DerOutputStream();
- for (int i = 0; i < tickets.length; i++) {
- temp.write(tickets[i].asn1Encode());
- }
+ temp.putInteger(BigInteger.valueOf(msgType));
+ out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x01), temp);
+ temp = new DerOutputStream();
+ for (int i = 0; i < tickets.length; i++) {
+ temp.write(tickets[i].asn1Encode());
+ }
bytes = new DerOutputStream();
bytes.write(DerValue.tag_SequenceOf, temp);
- out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), bytes);
- out.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), encPart.asn1Encode());
+ out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x02), bytes);
+ out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
+ true, (byte) 0x03), encPart.asn1Encode());
bytes = new DerOutputStream();
bytes.write(DerValue.tag_Sequence, out);
- out = new DerOutputStream();
- out.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x16), bytes);
- return out.toByteArray();
- }
-
+ out = new DerOutputStream();
+ out.write(DerValue.createTag(DerValue.TAG_APPLICATION,
+ true, (byte) 0x16), bytes);
+ return out.toByteArray();
+ }
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/KrbCredInfo.java b/jdk/src/share/classes/sun/security/krb5/internal/KrbCredInfo.java
index 3853ab579cc..08a21b66589 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/KrbCredInfo.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/KrbCredInfo.java
@@ -111,7 +111,7 @@ public class KrbCredInfo {
* @exception RealmException if an error occurs while parsing a Realm object.
*/
public KrbCredInfo(DerValue encoding)
- throws Asn1Exception, IOException, RealmException{
+ throws Asn1Exception, IOException, RealmException{
if (encoding.getTag() != DerValue.tag_Sequence) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
@@ -160,25 +160,25 @@ public class KrbCredInfo {
Vector v = new Vector ();
v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), key.asn1Encode()));
if (prealm != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), prealm.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), prealm.asn1Encode()));
if (pname != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), pname.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), pname.asn1Encode()));
if (flags != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), flags.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), flags.asn1Encode()));
if (authtime != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), authtime.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), authtime.asn1Encode()));
if (starttime != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), starttime.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), starttime.asn1Encode()));
if (endtime != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), endtime.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), endtime.asn1Encode()));
if (renewTill != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), renewTill.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), renewTill.asn1Encode()));
if (srealm != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), srealm.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), srealm.asn1Encode()));
if (sname != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), sname.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), sname.asn1Encode()));
if (caddr != null)
- v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), caddr.asn1Encode()));
+ v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), caddr.asn1Encode()));
DerValue der[] = new DerValue[v.size()];
v.copyInto(der);
DerOutputStream out = new DerOutputStream();
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/ccache/Credentials.java b/jdk/src/share/classes/sun/security/krb5/internal/ccache/Credentials.java
index 4665d9f63dc..0c7b1ed32b2 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/ccache/Credentials.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/ccache/Credentials.java
@@ -34,168 +34,171 @@ import sun.security.krb5.*;
import sun.security.krb5.internal.*;
public class Credentials {
- PrincipalName cname;
- Realm crealm;
+
+ PrincipalName cname;
+ Realm crealm;
PrincipalName sname;
- Realm srealm;
- EncryptionKey key;
- KerberosTime authtime;
- KerberosTime starttime;//optional
- KerberosTime endtime;
- KerberosTime renewTill; //optional
- HostAddresses caddr; //optional; for proxied tickets only
+ Realm srealm;
+ EncryptionKey key;
+ KerberosTime authtime;
+ KerberosTime starttime;//optional
+ KerberosTime endtime;
+ KerberosTime renewTill; //optional
+ HostAddresses caddr; //optional; for proxied tickets only
AuthorizationData authorizationData; //optional, not being actually used
public boolean isEncInSKey; // true if ticket is encrypted in another ticket's skey
- TicketFlags flags;
+ TicketFlags flags;
Ticket ticket;
- Ticket secondTicket; //optional
- private boolean DEBUG = Krb5.DEBUG;
+ Ticket secondTicket; //optional
+ private boolean DEBUG = Krb5.DEBUG;
- public Credentials(
- PrincipalName new_cname,
- PrincipalName new_sname,
- EncryptionKey new_key,
- KerberosTime new_authtime,
- KerberosTime new_starttime,
- KerberosTime new_endtime,
- KerberosTime new_renewTill,
- boolean new_isEncInSKey,
- TicketFlags new_flags,
- HostAddresses new_caddr,
- AuthorizationData new_authData,
- Ticket new_ticket,
- Ticket new_secondTicket) {
- cname = (PrincipalName)new_cname.clone();
- if (new_cname.getRealm() != null)
- crealm = (Realm)new_cname.getRealm().clone();
-
- sname = (PrincipalName)new_sname.clone();
- if (new_sname.getRealm() != null)
- srealm = (Realm)new_sname.getRealm().clone();
-
- key = (EncryptionKey)new_key.clone();
-
- authtime = (KerberosTime)new_authtime.clone();
- starttime = (KerberosTime)new_starttime.clone();
- endtime = (KerberosTime)new_endtime.clone();
- renewTill = (KerberosTime)new_renewTill.clone();
- if (new_caddr != null)
- caddr = (HostAddresses)new_caddr.clone();
- if (new_authData != null) {
- authorizationData
- = (AuthorizationData)new_authData.clone();
- }
-
- isEncInSKey = new_isEncInSKey;
- flags = (TicketFlags)new_flags.clone();
- ticket = (Ticket)(new_ticket.clone());
- if (new_secondTicket != null)
- secondTicket = (Ticket)new_secondTicket.clone();
+ public Credentials(
+ PrincipalName new_cname,
+ PrincipalName new_sname,
+ EncryptionKey new_key,
+ KerberosTime new_authtime,
+ KerberosTime new_starttime,
+ KerberosTime new_endtime,
+ KerberosTime new_renewTill,
+ boolean new_isEncInSKey,
+ TicketFlags new_flags,
+ HostAddresses new_caddr,
+ AuthorizationData new_authData,
+ Ticket new_ticket,
+ Ticket new_secondTicket) {
+ cname = (PrincipalName) new_cname.clone();
+ if (new_cname.getRealm() != null) {
+ crealm = (Realm) new_cname.getRealm().clone();
}
-
-
- public Credentials(
- KDCRep kdcRep,
- Ticket new_secondTicket,
- AuthorizationData new_authorizationData,
- boolean new_isEncInSKey
- ) {
- if (kdcRep.encKDCRepPart == null) //can't store while encrypted
- return;
- crealm = (Realm)kdcRep.crealm.clone();
- cname = (PrincipalName)kdcRep.cname.clone();
- ticket = (Ticket)kdcRep.ticket.clone();
- key = (EncryptionKey)kdcRep.encKDCRepPart.key.clone();
- flags = (TicketFlags)kdcRep.encKDCRepPart.flags.clone();
- authtime = (KerberosTime)kdcRep.encKDCRepPart.authtime.clone();
- starttime = (KerberosTime)kdcRep.encKDCRepPart.starttime.clone();
- endtime = (KerberosTime)kdcRep.encKDCRepPart.endtime.clone();
- renewTill = (KerberosTime)kdcRep.encKDCRepPart.renewTill.clone();
- srealm = (Realm)kdcRep.encKDCRepPart.srealm.clone();
- sname = (PrincipalName)kdcRep.encKDCRepPart.sname.clone();
- caddr = (HostAddresses)kdcRep.encKDCRepPart.caddr.clone();
- secondTicket = (Ticket)new_secondTicket.clone();
- authorizationData =
- (AuthorizationData)new_authorizationData.clone();
- isEncInSKey = new_isEncInSKey;
+ sname = (PrincipalName) new_sname.clone();
+ if (new_sname.getRealm() != null) {
+ srealm = (Realm) new_sname.getRealm().clone();
}
- public Credentials(KDCRep kdcRep) {
- this(kdcRep, null);
+ key = (EncryptionKey) new_key.clone();
+
+ authtime = (KerberosTime) new_authtime.clone();
+ starttime = (KerberosTime) new_starttime.clone();
+ endtime = (KerberosTime) new_endtime.clone();
+ renewTill = (KerberosTime) new_renewTill.clone();
+ if (new_caddr != null) {
+ caddr = (HostAddresses) new_caddr.clone();
+ }
+ if (new_authData != null) {
+ authorizationData = (AuthorizationData) new_authData.clone();
}
- public Credentials(KDCRep kdcRep, Ticket new_ticket) {
- sname = (PrincipalName)kdcRep.encKDCRepPart.sname.clone();
- srealm = (Realm)kdcRep.encKDCRepPart.srealm.clone();
- try {
- sname.setRealm(srealm);
- }
- catch (RealmException e) {
- }
- cname = (PrincipalName)kdcRep.cname.clone();
- crealm = (Realm)kdcRep.crealm.clone();
- try {
- cname.setRealm(crealm);
- }
- catch (RealmException e) {
- }
- key = (EncryptionKey)kdcRep.encKDCRepPart.key.clone();
- authtime = (KerberosTime)kdcRep.encKDCRepPart.authtime.clone();
- if (kdcRep.encKDCRepPart.starttime != null) {
- starttime = (KerberosTime)kdcRep.encKDCRepPart.starttime.clone();
- }
- else starttime = null;
- endtime = (KerberosTime)kdcRep.encKDCRepPart.endtime.clone();
- if (kdcRep.encKDCRepPart.renewTill != null) {
- renewTill = (KerberosTime)kdcRep.encKDCRepPart.renewTill.clone();
- }
- else renewTill = null;
- // if (kdcRep.msgType == Krb5.KRB_AS_REP) {
- // isEncInSKey = false;
- // secondTicket = null;
- // }
- flags = kdcRep.encKDCRepPart.flags;
- if (kdcRep.encKDCRepPart.caddr != null)
- caddr = (HostAddresses)kdcRep.encKDCRepPart.caddr.clone();
- else caddr = null;
- ticket = (Ticket)kdcRep.ticket.clone();
- if (new_ticket != null) {
- secondTicket = (Ticket)new_ticket.clone();
- isEncInSKey = true;
- } else {
- secondTicket = null;
- isEncInSKey = false;
- }
+ isEncInSKey = new_isEncInSKey;
+ flags = (TicketFlags) new_flags.clone();
+ ticket = (Ticket) (new_ticket.clone());
+ if (new_secondTicket != null) {
+ secondTicket = (Ticket) new_secondTicket.clone();
}
+ }
- /**
- * Checks if this credential is expired
- */
- public boolean isValid() {
- boolean valid = true;
- if (endtime.getTime() < System.currentTimeMillis()) {
- valid = false;
- }
- else if ((starttime.getTime() > System.currentTimeMillis())
- || ((starttime == null) && (authtime.getTime() > System.currentTimeMillis())))
- {
- valid = false;
- }
- return valid;
+ public Credentials(
+ KDCRep kdcRep,
+ Ticket new_secondTicket,
+ AuthorizationData new_authorizationData,
+ boolean new_isEncInSKey) {
+ if (kdcRep.encKDCRepPart == null) //can't store while encrypted
+ {
+ return;
}
+ crealm = (Realm) kdcRep.crealm.clone();
+ cname = (PrincipalName) kdcRep.cname.clone();
+ ticket = (Ticket) kdcRep.ticket.clone();
+ key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone();
+ flags = (TicketFlags) kdcRep.encKDCRepPart.flags.clone();
+ authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone();
+ starttime = (KerberosTime) kdcRep.encKDCRepPart.starttime.clone();
+ endtime = (KerberosTime) kdcRep.encKDCRepPart.endtime.clone();
+ renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone();
+ srealm = (Realm) kdcRep.encKDCRepPart.srealm.clone();
+ sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone();
+ caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone();
+ secondTicket = (Ticket) new_secondTicket.clone();
+ authorizationData =
+ (AuthorizationData) new_authorizationData.clone();
+ isEncInSKey = new_isEncInSKey;
+ }
- public PrincipalName getServicePrincipal() throws RealmException{
- if (sname.getRealm() == null) {
- sname.setRealm(srealm);
- }
- return sname;
- }
+ public Credentials(KDCRep kdcRep) {
+ this(kdcRep, null);
+ }
- public sun.security.krb5.Credentials setKrbCreds() {
- return new sun.security.krb5.Credentials(ticket,
- cname, sname, key, flags, authtime, starttime, endtime, renewTill, caddr);
+ public Credentials(KDCRep kdcRep, Ticket new_ticket) {
+ sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone();
+ srealm = (Realm) kdcRep.encKDCRepPart.srealm.clone();
+ try {
+ sname.setRealm(srealm);
+ } catch (RealmException e) {
}
+ cname = (PrincipalName) kdcRep.cname.clone();
+ crealm = (Realm) kdcRep.crealm.clone();
+ try {
+ cname.setRealm(crealm);
+ } catch (RealmException e) {
+ }
+ key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone();
+ authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone();
+ if (kdcRep.encKDCRepPart.starttime != null) {
+ starttime = (KerberosTime) kdcRep.encKDCRepPart.starttime.clone();
+ } else {
+ starttime = null;
+ }
+ endtime = (KerberosTime) kdcRep.encKDCRepPart.endtime.clone();
+ if (kdcRep.encKDCRepPart.renewTill != null) {
+ renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone();
+ } else {
+ renewTill = null;
+ }
+ // if (kdcRep.msgType == Krb5.KRB_AS_REP) {
+ // isEncInSKey = false;
+ // secondTicket = null;
+ // }
+ flags = kdcRep.encKDCRepPart.flags;
+ if (kdcRep.encKDCRepPart.caddr != null) {
+ caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone();
+ } else {
+ caddr = null;
+ }
+ ticket = (Ticket) kdcRep.ticket.clone();
+ if (new_ticket != null) {
+ secondTicket = (Ticket) new_ticket.clone();
+ isEncInSKey = true;
+ } else {
+ secondTicket = null;
+ isEncInSKey = false;
+ }
+ }
+
+ /**
+ * Checks if this credential is expired
+ */
+ public boolean isValid() {
+ boolean valid = true;
+ if (endtime.getTime() < System.currentTimeMillis()) {
+ valid = false;
+ } else if ((starttime.getTime() > System.currentTimeMillis())
+ || ((starttime == null) && (authtime.getTime() > System.currentTimeMillis()))) {
+ valid = false;
+ }
+ return valid;
+ }
+
+ public PrincipalName getServicePrincipal() throws RealmException {
+ if (sname.getRealm() == null) {
+ sname.setRealm(srealm);
+ }
+ return sname;
+ }
+
+ public sun.security.krb5.Credentials setKrbCreds() {
+ return new sun.security.krb5.Credentials(ticket,
+ cname, sname, key, flags, authtime, starttime, endtime, renewTill, caddr);
+ }
public KerberosTime getAuthTime() {
return authtime;
diff --git a/jdk/src/windows/native/sun/security/krb5/NativeCreds.c b/jdk/src/windows/native/sun/security/krb5/NativeCreds.c
index 879dab47388..5d2365a415a 100644
--- a/jdk/src/windows/native/sun/security/krb5/NativeCreds.c
+++ b/jdk/src/windows/native/sun/security/krb5/NativeCreds.c
@@ -88,9 +88,9 @@ VOID ShowNTError(LPSTR,NTSTATUS);
VOID
InitUnicodeString(
- PUNICODE_STRING DestinationString,
+ PUNICODE_STRING DestinationString,
PCWSTR SourceString OPTIONAL
- );
+);
jobject BuildTicket(JNIEnv *env, PUCHAR encodedTicket, ULONG encodedTicketSize);
@@ -108,215 +108,215 @@ jobject BuildKerberosTime(JNIEnv *env, PLARGE_INTEGER kerbtime);
*/
JNIEXPORT jint JNICALL JNI_OnLoad(
- JavaVM *jvm,
- void *reserved) {
+ JavaVM *jvm,
+ void *reserved) {
- jclass cls;
- JNIEnv *env;
+ jclass cls;
+ JNIEnv *env;
- if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
- return JNI_EVERSION; /* JNI version not supported */
- }
+ if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
+ return JNI_EVERSION; /* JNI version not supported */
+ }
- cls = (*env)->FindClass(env,"sun/security/krb5/internal/Ticket");
+ cls = (*env)->FindClass(env,"sun/security/krb5/internal/Ticket");
- if (cls == NULL) {
- printf("Couldn't find Ticket\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found Ticket\n");
- #endif /* DEBUG */
+ if (cls == NULL) {
+ printf("Couldn't find Ticket\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found Ticket\n");
+ #endif /* DEBUG */
- ticketClass = (*env)->NewWeakGlobalRef(env,cls);
- if (ticketClass == NULL) {
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Made NewWeakGlobalRef\n");
- #endif /* DEBUG */
+ ticketClass = (*env)->NewWeakGlobalRef(env,cls);
+ if (ticketClass == NULL) {
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Made NewWeakGlobalRef\n");
+ #endif /* DEBUG */
- cls = (*env)->FindClass(env, "sun/security/krb5/PrincipalName");
+ cls = (*env)->FindClass(env, "sun/security/krb5/PrincipalName");
- if (cls == NULL) {
- printf("Couldn't find PrincipalName\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found PrincipalName\n");
- #endif /* DEBUG */
+ if (cls == NULL) {
+ printf("Couldn't find PrincipalName\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found PrincipalName\n");
+ #endif /* DEBUG */
- principalNameClass = (*env)->NewWeakGlobalRef(env,cls);
- if (principalNameClass == NULL) {
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Made NewWeakGlobalRef\n");
- #endif /* DEBUG */
+ principalNameClass = (*env)->NewWeakGlobalRef(env,cls);
+ if (principalNameClass == NULL) {
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Made NewWeakGlobalRef\n");
+ #endif /* DEBUG */
- cls = (*env)->FindClass(env,"sun/security/util/DerValue");
+ cls = (*env)->FindClass(env,"sun/security/util/DerValue");
- if (cls == NULL) {
- printf("Couldn't find DerValue\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found DerValue\n");
- #endif /* DEBUG */
+ if (cls == NULL) {
+ printf("Couldn't find DerValue\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found DerValue\n");
+ #endif /* DEBUG */
- derValueClass = (*env)->NewWeakGlobalRef(env,cls);
- if (derValueClass == NULL) {
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Made NewWeakGlobalRef\n");
- #endif /* DEBUG */
+ derValueClass = (*env)->NewWeakGlobalRef(env,cls);
+ if (derValueClass == NULL) {
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Made NewWeakGlobalRef\n");
+ #endif /* DEBUG */
- cls = (*env)->FindClass(env,"sun/security/krb5/EncryptionKey");
+ cls = (*env)->FindClass(env,"sun/security/krb5/EncryptionKey");
- if (cls == NULL) {
- printf("Couldn't find EncryptionKey\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found EncryptionKey\n");
- #endif /* DEBUG */
+ if (cls == NULL) {
+ printf("Couldn't find EncryptionKey\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found EncryptionKey\n");
+ #endif /* DEBUG */
- encryptionKeyClass = (*env)->NewWeakGlobalRef(env,cls);
- if (encryptionKeyClass == NULL) {
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Made NewWeakGlobalRef\n");
- #endif /* DEBUG */
+ encryptionKeyClass = (*env)->NewWeakGlobalRef(env,cls);
+ if (encryptionKeyClass == NULL) {
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Made NewWeakGlobalRef\n");
+ #endif /* DEBUG */
- cls = (*env)->FindClass(env,"sun/security/krb5/internal/TicketFlags");
+ cls = (*env)->FindClass(env,"sun/security/krb5/internal/TicketFlags");
- if (cls == NULL) {
- printf("Couldn't find TicketFlags\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found TicketFlags\n");
- #endif /* DEBUG */
+ if (cls == NULL) {
+ printf("Couldn't find TicketFlags\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found TicketFlags\n");
+ #endif /* DEBUG */
- ticketFlagsClass = (*env)->NewWeakGlobalRef(env,cls);
- if (ticketFlagsClass == NULL) {
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Made NewWeakGlobalRef\n");
- #endif /* DEBUG */
+ ticketFlagsClass = (*env)->NewWeakGlobalRef(env,cls);
+ if (ticketFlagsClass == NULL) {
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Made NewWeakGlobalRef\n");
+ #endif /* DEBUG */
- cls = (*env)->FindClass(env,"sun/security/krb5/internal/KerberosTime");
+ cls = (*env)->FindClass(env,"sun/security/krb5/internal/KerberosTime");
- if (cls == NULL) {
- printf("Couldn't find KerberosTime\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found KerberosTime\n");
- #endif /* DEBUG */
+ if (cls == NULL) {
+ printf("Couldn't find KerberosTime\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found KerberosTime\n");
+ #endif /* DEBUG */
- kerberosTimeClass = (*env)->NewWeakGlobalRef(env,cls);
- if (kerberosTimeClass == NULL) {
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Made NewWeakGlobalRef\n");
- #endif /* DEBUG */
+ kerberosTimeClass = (*env)->NewWeakGlobalRef(env,cls);
+ if (kerberosTimeClass == NULL) {
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Made NewWeakGlobalRef\n");
+ #endif /* DEBUG */
- cls = (*env)->FindClass(env,"java/lang/String");
+ cls = (*env)->FindClass(env,"java/lang/String");
- if (cls == NULL) {
- printf("Couldn't find String\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found String\n");
- #endif /* DEBUG */
+ if (cls == NULL) {
+ printf("Couldn't find String\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found String\n");
+ #endif /* DEBUG */
- javaLangStringClass = (*env)->NewWeakGlobalRef(env,cls);
- if (javaLangStringClass == NULL) {
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Made NewWeakGlobalRef\n");
- #endif /* DEBUG */
+ javaLangStringClass = (*env)->NewWeakGlobalRef(env,cls);
+ if (javaLangStringClass == NULL) {
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Made NewWeakGlobalRef\n");
+ #endif /* DEBUG */
- derValueConstructor = (*env)->GetMethodID(env, derValueClass,
- "", "([B)V");
- if (derValueConstructor == 0) {
- printf("Couldn't find DerValue constructor\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found DerValue constructor\n");
- #endif /* DEBUG */
+ derValueConstructor = (*env)->GetMethodID(env, derValueClass,
+ "", "([B)V");
+ if (derValueConstructor == 0) {
+ printf("Couldn't find DerValue constructor\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found DerValue constructor\n");
+ #endif /* DEBUG */
- ticketConstructor = (*env)->GetMethodID(env, ticketClass,
- "", "(Lsun/security/util/DerValue;)V");
- if (ticketConstructor == 0) {
- printf("Couldn't find Ticket constructor\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found Ticket constructor\n");
- #endif /* DEBUG */
+ ticketConstructor = (*env)->GetMethodID(env, ticketClass,
+ "", "(Lsun/security/util/DerValue;)V");
+ if (ticketConstructor == 0) {
+ printf("Couldn't find Ticket constructor\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found Ticket constructor\n");
+ #endif /* DEBUG */
- principalNameConstructor = (*env)->GetMethodID(env, principalNameClass,
- "", "([Ljava/lang/String;)V");
- if (principalNameConstructor == 0) {
- printf("Couldn't find PrincipalName constructor\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found PrincipalName constructor\n");
- #endif /* DEBUG */
+ principalNameConstructor = (*env)->GetMethodID(env, principalNameClass,
+ "", "([Ljava/lang/String;)V");
+ if (principalNameConstructor == 0) {
+ printf("Couldn't find PrincipalName constructor\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found PrincipalName constructor\n");
+ #endif /* DEBUG */
- encryptionKeyConstructor = (*env)->GetMethodID(env, encryptionKeyClass,
- "", "(I[B)V");
- if (encryptionKeyConstructor == 0) {
- printf("Couldn't find EncryptionKey constructor\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found EncryptionKey constructor\n");
- #endif /* DEBUG */
+ encryptionKeyConstructor = (*env)->GetMethodID(env, encryptionKeyClass,
+ "", "(I[B)V");
+ if (encryptionKeyConstructor == 0) {
+ printf("Couldn't find EncryptionKey constructor\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found EncryptionKey constructor\n");
+ #endif /* DEBUG */
- ticketFlagsConstructor = (*env)->GetMethodID(env, ticketFlagsClass,
- "", "(I[B)V");
- if (ticketFlagsConstructor == 0) {
- printf("Couldn't find TicketFlags constructor\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found TicketFlags constructor\n");
- #endif /* DEBUG */
+ ticketFlagsConstructor = (*env)->GetMethodID(env, ticketFlagsClass,
+ "", "(I[B)V");
+ if (ticketFlagsConstructor == 0) {
+ printf("Couldn't find TicketFlags constructor\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found TicketFlags constructor\n");
+ #endif /* DEBUG */
- kerberosTimeConstructor = (*env)->GetMethodID(env, kerberosTimeClass,
- "", "(Ljava/lang/String;)V");
- if (kerberosTimeConstructor == 0) {
- printf("Couldn't find KerberosTime constructor\n");
- return JNI_ERR;
- }
- #ifdef DEBUG
- printf("Found KerberosTime constructor\n");
- #endif /* DEBUG */
+ kerberosTimeConstructor = (*env)->GetMethodID(env, kerberosTimeClass,
+ "", "(Ljava/lang/String;)V");
+ if (kerberosTimeConstructor == 0) {
+ printf("Couldn't find KerberosTime constructor\n");
+ return JNI_ERR;
+ }
+ #ifdef DEBUG
+ printf("Found KerberosTime constructor\n");
+ #endif /* DEBUG */
- // load the setRealm method in PrincipalName
- setRealmMethod = (*env)->GetMethodID(env, principalNameClass,
- "setRealm", "(Ljava/lang/String;)V");
- if (setRealmMethod == 0) {
- printf("Couldn't find setRealm in PrincipalName\n");
- return JNI_ERR;
- }
+ // load the setRealm method in PrincipalName
+ setRealmMethod = (*env)->GetMethodID(env, principalNameClass,
+ "setRealm", "(Ljava/lang/String;)V");
+ if (setRealmMethod == 0) {
+ printf("Couldn't find setRealm in PrincipalName\n");
+ return JNI_ERR;
+ }
- #ifdef DEBUG
- printf("Finished OnLoad processing\n");
- #endif /* DEBUG */
+ #ifdef DEBUG
+ printf("Finished OnLoad processing\n");
+ #endif /* DEBUG */
- return JNI_VERSION_1_2;
+ return JNI_VERSION_1_2;
}
/*
@@ -325,38 +325,38 @@ JNIEXPORT jint JNICALL JNI_OnLoad(
*/
JNIEXPORT void JNICALL JNI_OnUnload(
- JavaVM *jvm,
- void *reserved) {
+ JavaVM *jvm,
+ void *reserved) {
- JNIEnv *env;
+ JNIEnv *env;
- if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
- return; /* Nothing else we can do */
- }
+ if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2)) {
+ return; /* Nothing else we can do */
+ }
- if (ticketClass != NULL) {
- (*env)->DeleteWeakGlobalRef(env,ticketClass);
- }
- if (derValueClass != NULL) {
- (*env)->DeleteWeakGlobalRef(env,derValueClass);
- }
- if (principalNameClass != NULL) {
- (*env)->DeleteWeakGlobalRef(env,principalNameClass);
- }
- if (encryptionKeyClass != NULL) {
- (*env)->DeleteWeakGlobalRef(env,encryptionKeyClass);
- }
- if (ticketFlagsClass != NULL) {
- (*env)->DeleteWeakGlobalRef(env,ticketFlagsClass);
- }
- if (kerberosTimeClass != NULL) {
- (*env)->DeleteWeakGlobalRef(env,kerberosTimeClass);
- }
- if (javaLangStringClass != NULL) {
- (*env)->DeleteWeakGlobalRef(env,javaLangStringClass);
- }
+ if (ticketClass != NULL) {
+ (*env)->DeleteWeakGlobalRef(env,ticketClass);
+ }
+ if (derValueClass != NULL) {
+ (*env)->DeleteWeakGlobalRef(env,derValueClass);
+ }
+ if (principalNameClass != NULL) {
+ (*env)->DeleteWeakGlobalRef(env,principalNameClass);
+ }
+ if (encryptionKeyClass != NULL) {
+ (*env)->DeleteWeakGlobalRef(env,encryptionKeyClass);
+ }
+ if (ticketFlagsClass != NULL) {
+ (*env)->DeleteWeakGlobalRef(env,ticketFlagsClass);
+ }
+ if (kerberosTimeClass != NULL) {
+ (*env)->DeleteWeakGlobalRef(env,kerberosTimeClass);
+ }
+ if (javaLangStringClass != NULL) {
+ (*env)->DeleteWeakGlobalRef(env,javaLangStringClass);
+ }
- return;
+ return;
}
/*
@@ -365,31 +365,31 @@ JNIEXPORT void JNICALL JNI_OnUnload(
* Signature: ()Lsun/security/krb5/Credentials;
*/
JNIEXPORT jobject JNICALL Java_sun_security_krb5_Credentials_acquireDefaultNativeCreds(
- JNIEnv *env,
- jclass krbcredsClass) {
+ JNIEnv *env,
+ jclass krbcredsClass) {
- KERB_QUERY_TKT_CACHE_REQUEST CacheRequest;
- PKERB_RETRIEVE_TKT_RESPONSE TktCacheResponse = NULL;
- PKERB_RETRIEVE_TKT_REQUEST pTicketRequest = NULL;
- PKERB_RETRIEVE_TKT_RESPONSE pTicketResponse = NULL;
- NTSTATUS Status, SubStatus;
- ULONG requestSize = 0;
- ULONG responseSize = 0;
- ULONG rspSize = 0;
- HANDLE LogonHandle = NULL;
- ULONG PackageId;
- jobject ticket, clientPrincipal, targetPrincipal, encryptionKey;
- jobject ticketFlags, startTime, endTime, krbCreds = NULL;
- jobject authTime, renewTillTime, hostAddresses = NULL;
- KERB_EXTERNAL_TICKET *msticket;
- int ignore_cache = 0;
- FILETIME Now, EndTime, LocalEndTime;
+ KERB_QUERY_TKT_CACHE_REQUEST CacheRequest;
+ PKERB_RETRIEVE_TKT_RESPONSE TktCacheResponse = NULL;
+ PKERB_RETRIEVE_TKT_REQUEST pTicketRequest = NULL;
+ PKERB_RETRIEVE_TKT_RESPONSE pTicketResponse = NULL;
+ NTSTATUS Status, SubStatus;
+ ULONG requestSize = 0;
+ ULONG responseSize = 0;
+ ULONG rspSize = 0;
+ HANDLE LogonHandle = NULL;
+ ULONG PackageId;
+ jobject ticket, clientPrincipal, targetPrincipal, encryptionKey;
+ jobject ticketFlags, startTime, endTime, krbCreds = NULL;
+ jobject authTime, renewTillTime, hostAddresses = NULL;
+ KERB_EXTERNAL_TICKET *msticket;
+ int ignore_cache = 0;
+ FILETIME Now, EndTime, LocalEndTime;
- while (TRUE) {
+ while (TRUE) {
if (krbcredsConstructor == 0) {
- krbcredsConstructor = (*env)->GetMethodID(env, krbcredsClass, "",
- "(Lsun/security/krb5/internal/Ticket;Lsun/security/krb5/PrincipalName;Lsun/security/krb5/PrincipalName;Lsun/security/krb5/EncryptionKey;Lsun/security/krb5/internal/TicketFlags;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/HostAddresses;)V");
+ krbcredsConstructor = (*env)->GetMethodID(env, krbcredsClass, "",
+ "(Lsun/security/krb5/internal/Ticket;Lsun/security/krb5/PrincipalName;Lsun/security/krb5/PrincipalName;Lsun/security/krb5/EncryptionKey;Lsun/security/krb5/internal/TicketFlags;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/KerberosTime;Lsun/security/krb5/internal/HostAddresses;)V");
if (krbcredsConstructor == 0) {
printf("Couldn't find sun.security.krb5.Credentials constructor\n");
break;
@@ -510,88 +510,88 @@ JNIEXPORT jobject JNICALL Java_sun_security_krb5_Credentials_acquireDefaultNativ
msticket = &(pTicketResponse->Ticket);
}
-/*
+ /*
-typedef struct _KERB_RETRIEVE_TKT_RESPONSE {
- KERB_EXTERNAL_TICKET Ticket;
-} KERB_RETRIEVE_TKT_RESPONSE, *PKERB_RETRIEVE_TKT_RESPONSE;
+ typedef struct _KERB_RETRIEVE_TKT_RESPONSE {
+ KERB_EXTERNAL_TICKET Ticket;
+ } KERB_RETRIEVE_TKT_RESPONSE, *PKERB_RETRIEVE_TKT_RESPONSE;
-typedef struct _KERB_EXTERNAL_TICKET {
- PKERB_EXTERNAL_NAME ServiceName;
- PKERB_EXTERNAL_NAME TargetName;
- PKERB_EXTERNAL_NAME ClientName;
- UNICODE_STRING DomainName;
- UNICODE_STRING TargetDomainName;
- UNICODE_STRING AltTargetDomainName;
- KERB_CRYPTO_KEY SessionKey;
- ULONG TicketFlags;
- ULONG Flags;
- LARGE_INTEGER KeyExpirationTime;
- LARGE_INTEGER StartTime;
- LARGE_INTEGER EndTime;
- LARGE_INTEGER RenewUntil;
- LARGE_INTEGER TimeSkew;
- ULONG EncodedTicketSize;
- PUCHAR EncodedTicket; <========== Here's the good stuff
-} KERB_EXTERNAL_TICKET, *PKERB_EXTERNAL_TICKET;
+ typedef struct _KERB_EXTERNAL_TICKET {
+ PKERB_EXTERNAL_NAME ServiceName;
+ PKERB_EXTERNAL_NAME TargetName;
+ PKERB_EXTERNAL_NAME ClientName;
+ UNICODE_STRING DomainName;
+ UNICODE_STRING TargetDomainName;
+ UNICODE_STRING AltTargetDomainName;
+ KERB_CRYPTO_KEY SessionKey;
+ ULONG TicketFlags;
+ ULONG Flags;
+ LARGE_INTEGER KeyExpirationTime;
+ LARGE_INTEGER StartTime;
+ LARGE_INTEGER EndTime;
+ LARGE_INTEGER RenewUntil;
+ LARGE_INTEGER TimeSkew;
+ ULONG EncodedTicketSize;
+ PUCHAR EncodedTicket; <========== Here's the good stuff
+ } KERB_EXTERNAL_TICKET, *PKERB_EXTERNAL_TICKET;
-typedef struct _KERB_EXTERNAL_NAME {
- SHORT NameType;
- USHORT NameCount;
- UNICODE_STRING Names[ANYSIZE_ARRAY];
-} KERB_EXTERNAL_NAME, *PKERB_EXTERNAL_NAME;
+ typedef struct _KERB_EXTERNAL_NAME {
+ SHORT NameType;
+ USHORT NameCount;
+ UNICODE_STRING Names[ANYSIZE_ARRAY];
+ } KERB_EXTERNAL_NAME, *PKERB_EXTERNAL_NAME;
-typedef struct _LSA_UNICODE_STRING {
- USHORT Length;
- USHORT MaximumLength;
- PWSTR Buffer;
-} LSA_UNICODE_STRING, *PLSA_UNICODE_STRING;
+ typedef struct _LSA_UNICODE_STRING {
+ USHORT Length;
+ USHORT MaximumLength;
+ PWSTR Buffer;
+ } LSA_UNICODE_STRING, *PLSA_UNICODE_STRING;
-typedef LSA_UNICODE_STRING UNICODE_STRING, *PUNICODE_STRING;
+ typedef LSA_UNICODE_STRING UNICODE_STRING, *PUNICODE_STRING;
-typedef struct KERB_CRYPTO_KEY {
- LONG KeyType;
- ULONG Length;
- PUCHAR Value;
-} KERB_CRYPTO_KEY, *PKERB_CRYPTO_KEY;
+ typedef struct KERB_CRYPTO_KEY {
+ LONG KeyType;
+ ULONG Length;
+ PUCHAR Value;
+ } KERB_CRYPTO_KEY, *PKERB_CRYPTO_KEY;
-*/
+ */
// Build a com.sun.security.krb5.Ticket
ticket = BuildTicket(env, msticket->EncodedTicket,
msticket->EncodedTicketSize);
if (ticket == NULL) {
- break;
+ break;
}
// OK, have a Ticket, now need to get the client name
clientPrincipal = BuildPrincipal(env, msticket->ClientName,
msticket->TargetDomainName); // mdu
if (clientPrincipal == NULL) {
- break;
+ break;
}
// and the "name" of tgt
targetPrincipal = BuildPrincipal(env, msticket->ServiceName,
msticket->DomainName);
if (targetPrincipal == NULL) {
- break;
+ break;
}
// Get the encryption key
encryptionKey = BuildEncryptionKey(env, &(msticket->SessionKey));
if (encryptionKey == NULL) {
- break;
+ break;
}
// and the ticket flags
ticketFlags = BuildTicketFlags(env, &(msticket->TicketFlags));
if (ticketFlags == NULL) {
- break;
+ break;
}
// Get the start time
startTime = BuildKerberosTime(env, &(msticket->StartTime));
if (startTime == NULL) {
- break;
+ break;
}
/*
@@ -604,13 +604,13 @@ typedef struct KERB_CRYPTO_KEY {
// and the end time
endTime = BuildKerberosTime(env, &(msticket->EndTime));
if (endTime == NULL) {
- break;
+ break;
}
// Get the renew till time
renewTillTime = BuildKerberosTime(env, &(msticket->RenewUntil));
if (renewTillTime == NULL) {
- break;
+ break;
}
// and now go build a KrbCreds object
@@ -630,87 +630,87 @@ typedef struct KERB_CRYPTO_KEY {
hostAddresses);
break;
- } // end of WHILE
+ } // end of WHILE
- // clean up resources
- if (TktCacheResponse != NULL) {
- LsaFreeReturnBuffer(TktCacheResponse);
- }
- if (pTicketRequest) {
- LocalFree(pTicketRequest);
- }
- if (pTicketResponse != NULL) {
- LsaFreeReturnBuffer(pTicketResponse);
- }
+ // clean up resources
+ if (TktCacheResponse != NULL) {
+ LsaFreeReturnBuffer(TktCacheResponse);
+ }
+ if (pTicketRequest) {
+ LocalFree(pTicketRequest);
+ }
+ if (pTicketResponse != NULL) {
+ LsaFreeReturnBuffer(pTicketResponse);
+ }
- return krbCreds;
+ return krbCreds;
}
static NTSTATUS
ConstructTicketRequest(UNICODE_STRING DomainName,
PKERB_RETRIEVE_TKT_REQUEST *outRequest, ULONG *outSize)
{
- NTSTATUS Status;
- UNICODE_STRING TargetPrefix;
- USHORT TargetSize;
- ULONG RequestSize;
- ULONG Length;
- PKERB_RETRIEVE_TKT_REQUEST pTicketRequest = NULL;
+ NTSTATUS Status;
+ UNICODE_STRING TargetPrefix;
+ USHORT TargetSize;
+ ULONG RequestSize;
+ ULONG Length;
+ PKERB_RETRIEVE_TKT_REQUEST pTicketRequest = NULL;
- *outRequest = NULL;
- *outSize = 0;
+ *outRequest = NULL;
+ *outSize = 0;
- //
- // Set up the "krbtgt/" target prefix into a UNICODE_STRING so we
- // can easily concatenate it later.
- //
+ //
+ // Set up the "krbtgt/" target prefix into a UNICODE_STRING so we
+ // can easily concatenate it later.
+ //
- TargetPrefix.Buffer = L"krbtgt/";
- Length = (ULONG)wcslen(TargetPrefix.Buffer) * sizeof(WCHAR);
- TargetPrefix.Length = (USHORT)Length;
- TargetPrefix.MaximumLength = TargetPrefix.Length;
+ TargetPrefix.Buffer = L"krbtgt/";
+ Length = (ULONG)wcslen(TargetPrefix.Buffer) * sizeof(WCHAR);
+ TargetPrefix.Length = (USHORT)Length;
+ TargetPrefix.MaximumLength = TargetPrefix.Length;
- //
- // We will need to concatenate the "krbtgt/" prefix and the
- // Logon Session's DnsDomainName into our request's target name.
- //
- // Therefore, first compute the necessary buffer size for that.
- //
- // Note that we might theoretically have integer overflow.
- //
+ //
+ // We will need to concatenate the "krbtgt/" prefix and the
+ // Logon Session's DnsDomainName into our request's target name.
+ //
+ // Therefore, first compute the necessary buffer size for that.
+ //
+ // Note that we might theoretically have integer overflow.
+ //
- TargetSize = TargetPrefix.Length + DomainName.Length;
+ TargetSize = TargetPrefix.Length + DomainName.Length;
- //
- // The ticket request buffer needs to be a single buffer. That buffer
- // needs to include the buffer for the target name.
- //
+ //
+ // The ticket request buffer needs to be a single buffer. That buffer
+ // needs to include the buffer for the target name.
+ //
- RequestSize = sizeof (*pTicketRequest) + TargetSize;
+ RequestSize = sizeof (*pTicketRequest) + TargetSize;
- //
- // Allocate the request buffer and make sure it's zero-filled.
- //
+ //
+ // Allocate the request buffer and make sure it's zero-filled.
+ //
- pTicketRequest = (PKERB_RETRIEVE_TKT_REQUEST)
- LocalAlloc(LMEM_ZEROINIT, RequestSize);
- if (!pTicketRequest)
- return GetLastError();
+ pTicketRequest = (PKERB_RETRIEVE_TKT_REQUEST)
+ LocalAlloc(LMEM_ZEROINIT, RequestSize);
+ if (!pTicketRequest)
+ return GetLastError();
- //
- // Concatenate the target prefix with the previous reponse's
- // target domain.
- //
+ //
+ // Concatenate the target prefix with the previous reponse's
+ // target domain.
+ //
- pTicketRequest->TargetName.Length = 0;
- pTicketRequest->TargetName.MaximumLength = TargetSize;
- pTicketRequest->TargetName.Buffer = (PWSTR) (pTicketRequest + 1);
- Status = ConcatenateUnicodeStrings(&(pTicketRequest->TargetName),
- TargetPrefix,
- DomainName);
- *outRequest = pTicketRequest;
- *outSize = RequestSize;
- return Status;
+ pTicketRequest->TargetName.Length = 0;
+ pTicketRequest->TargetName.MaximumLength = TargetSize;
+ pTicketRequest->TargetName.Buffer = (PWSTR) (pTicketRequest + 1);
+ Status = ConcatenateUnicodeStrings(&(pTicketRequest->TargetName),
+ TargetPrefix,
+ DomainName);
+ *outRequest = pTicketRequest;
+ *outSize = RequestSize;
+ return Status;
}
DWORD
@@ -720,22 +720,22 @@ ConcatenateUnicodeStrings(
UNICODE_STRING Source2
)
{
- //
- // The buffers for Source1 and Source2 cannot overlap pTarget's
- // buffer. Source1.Length + Source2.Length must be <= 0xFFFF,
- // otherwise we overflow...
- //
+ //
+ // The buffers for Source1 and Source2 cannot overlap pTarget's
+ // buffer. Source1.Length + Source2.Length must be <= 0xFFFF,
+ // otherwise we overflow...
+ //
- USHORT TotalSize = Source1.Length + Source2.Length;
- PBYTE buffer = (PBYTE) pTarget->Buffer;
+ USHORT TotalSize = Source1.Length + Source2.Length;
+ PBYTE buffer = (PBYTE) pTarget->Buffer;
- if (TotalSize > pTarget->MaximumLength)
- return ERROR_INSUFFICIENT_BUFFER;
+ if (TotalSize > pTarget->MaximumLength)
+ return ERROR_INSUFFICIENT_BUFFER;
- pTarget->Length = TotalSize;
- memcpy(buffer, Source1.Buffer, Source1.Length);
- memcpy(buffer + Source1.Length, Source2.Buffer, Source2.Length);
- return ERROR_SUCCESS;
+ pTarget->Length = TotalSize;
+ memcpy(buffer, Source1.Buffer, Source1.Length);
+ memcpy(buffer + Source1.Length, Source2.Buffer, Source2.Length);
+ return ERROR_SUCCESS;
}
BOOL
@@ -783,27 +783,27 @@ ShowLastError(
DWORD dwError
)
{
- #define MAX_MSG_SIZE 256
+ #define MAX_MSG_SIZE 256
- static WCHAR szMsgBuf[MAX_MSG_SIZE];
- DWORD dwRes;
+ static WCHAR szMsgBuf[MAX_MSG_SIZE];
+ DWORD dwRes;
- printf("Error calling function %s: %lu\n", szAPI, dwError);
+ printf("Error calling function %s: %lu\n", szAPI, dwError);
- dwRes = FormatMessage (
- FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- dwError,
- 0,
- szMsgBuf,
- MAX_MSG_SIZE,
- NULL);
- if (0 == dwRes) {
- printf("FormatMessage failed with %d\n", GetLastError());
- // ExitProcess(EXIT_FAILURE);
- } else {
- printf("%S",szMsgBuf);
- }
+ dwRes = FormatMessage (
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ dwError,
+ 0,
+ szMsgBuf,
+ MAX_MSG_SIZE,
+ NULL);
+ if (0 == dwRes) {
+ printf("FormatMessage failed with %d\n", GetLastError());
+ // ExitProcess(EXIT_FAILURE);
+ } else {
+ printf("%S",szMsgBuf);
+ }
}
VOID
@@ -831,189 +831,189 @@ InitUnicodeString(
Length = (ULONG)wcslen( SourceString ) * sizeof( WCHAR );
DestinationString->Length = (USHORT)Length;
DestinationString->MaximumLength = (USHORT)(Length + sizeof(UNICODE_NULL));
- }
+ }
else {
DestinationString->MaximumLength = 0;
DestinationString->Length = 0;
- }
+ }
}
jobject BuildTicket(JNIEnv *env, PUCHAR encodedTicket, ULONG encodedTicketSize) {
- /* To build a Ticket, we first need to build a DerValue out of the EncodedTicket.
- * But before we can do that, we need to make a byte array out of the ET.
- */
+ /* To build a Ticket, we first need to build a DerValue out of the EncodedTicket.
+ * But before we can do that, we need to make a byte array out of the ET.
+ */
- jobject derValue, ticket;
- jbyteArray ary;
+ jobject derValue, ticket;
+ jbyteArray ary;
- ary = (*env)->NewByteArray(env,encodedTicketSize);
- if ((*env)->ExceptionOccurred(env)) {
- return (jobject) NULL;
- }
-
- (*env)->SetByteArrayRegion(env, ary, (jsize) 0, encodedTicketSize,
- (jbyte *)encodedTicket);
- if ((*env)->ExceptionOccurred(env)) {
- (*env)->DeleteLocalRef(env, ary);
- return (jobject) NULL;
- }
-
- derValue = (*env)->NewObject(env, derValueClass, derValueConstructor, ary);
- if ((*env)->ExceptionOccurred(env)) {
- (*env)->DeleteLocalRef(env, ary);
- return (jobject) NULL;
- }
+ ary = (*env)->NewByteArray(env,encodedTicketSize);
+ if ((*env)->ExceptionOccurred(env)) {
+ return (jobject) NULL;
+ }
+ (*env)->SetByteArrayRegion(env, ary, (jsize) 0, encodedTicketSize,
+ (jbyte *)encodedTicket);
+ if ((*env)->ExceptionOccurred(env)) {
(*env)->DeleteLocalRef(env, ary);
- ticket = (*env)->NewObject(env, ticketClass, ticketConstructor, derValue);
- if ((*env)->ExceptionOccurred(env)) {
- (*env)->DeleteLocalRef(env, derValue);
- return (jobject) NULL;
- }
+ return (jobject) NULL;
+ }
+
+ derValue = (*env)->NewObject(env, derValueClass, derValueConstructor, ary);
+ if ((*env)->ExceptionOccurred(env)) {
+ (*env)->DeleteLocalRef(env, ary);
+ return (jobject) NULL;
+ }
+
+ (*env)->DeleteLocalRef(env, ary);
+ ticket = (*env)->NewObject(env, ticketClass, ticketConstructor, derValue);
+ if ((*env)->ExceptionOccurred(env)) {
(*env)->DeleteLocalRef(env, derValue);
- return ticket;
+ return (jobject) NULL;
+ }
+ (*env)->DeleteLocalRef(env, derValue);
+ return ticket;
}
// mdu
jobject BuildPrincipal(JNIEnv *env, PKERB_EXTERNAL_NAME principalName,
UNICODE_STRING domainName) {
- /*
- * To build the Principal, we need to get the names out of
- * this goofy MS structure
- */
- jobject principal = NULL;
- jobject realmStr = NULL;
- jobjectArray stringArray;
- jstring tempString;
- int nameCount,i;
- PUNICODE_STRING scanner;
- WCHAR *realm;
- ULONG realmLen;
+ /*
+ * To build the Principal, we need to get the names out of
+ * this goofy MS structure
+ */
+ jobject principal = NULL;
+ jobject realmStr = NULL;
+ jobjectArray stringArray;
+ jstring tempString;
+ int nameCount,i;
+ PUNICODE_STRING scanner;
+ WCHAR *realm;
+ ULONG realmLen;
- realm = (WCHAR *) LocalAlloc(LMEM_ZEROINIT,
- ((domainName.Length)*sizeof(WCHAR) + sizeof(UNICODE_NULL)));
- wcsncpy(realm, domainName.Buffer, domainName.Length/sizeof(WCHAR));
+ realm = (WCHAR *) LocalAlloc(LMEM_ZEROINIT,
+ ((domainName.Length)*sizeof(WCHAR) + sizeof(UNICODE_NULL)));
+ wcsncpy(realm, domainName.Buffer, domainName.Length/sizeof(WCHAR));
- #ifdef DEBUG
- printf("Principal domain is %S\n", realm);
- printf("Name type is %x\n", principalName->NameType);
- printf("Name count is %x\n", principalName->NameCount);
- #endif
+ #ifdef DEBUG
+ printf("Principal domain is %S\n", realm);
+ printf("Name type is %x\n", principalName->NameType);
+ printf("Name count is %x\n", principalName->NameCount);
+ #endif
- nameCount = principalName->NameCount;
- stringArray = (*env)->NewObjectArray(env, nameCount,
- javaLangStringClass, NULL);
- if (stringArray == NULL) {
- printf("Can't allocate String array for Principal\n");
- LocalFree(realm);
- return principal;
- }
-
- for (i=0; iNames[i]);
-
- // OK, got a Char array, so construct a String
- tempString = (*env)->NewString(env, (const jchar*)scanner->Buffer,
- scanner->Length/sizeof(WCHAR));
- // Set the String into the StringArray
- (*env)->SetObjectArrayElement(env, stringArray, i, tempString);
-
- // Do I have to worry about storage reclamation here?
- }
- principal = (*env)->NewObject(env, principalNameClass,
- principalNameConstructor, stringArray);
-
- // now set the realm in the principal
- realmLen = (ULONG)wcslen((PWCHAR)realm);
- realmStr = (*env)->NewString(env, (PWCHAR)realm, (USHORT)realmLen);
- (*env)->CallVoidMethod(env, principal, setRealmMethod, realmStr);
-
- // free local resources
+ nameCount = principalName->NameCount;
+ stringArray = (*env)->NewObjectArray(env, nameCount,
+ javaLangStringClass, NULL);
+ if (stringArray == NULL) {
+ printf("Can't allocate String array for Principal\n");
LocalFree(realm);
-
return principal;
+ }
+
+ for (i=0; iNames[i]);
+
+ // OK, got a Char array, so construct a String
+ tempString = (*env)->NewString(env, (const jchar*)scanner->Buffer,
+ scanner->Length/sizeof(WCHAR));
+ // Set the String into the StringArray
+ (*env)->SetObjectArrayElement(env, stringArray, i, tempString);
+
+ // Do I have to worry about storage reclamation here?
+ }
+ principal = (*env)->NewObject(env, principalNameClass,
+ principalNameConstructor, stringArray);
+
+ // now set the realm in the principal
+ realmLen = (ULONG)wcslen((PWCHAR)realm);
+ realmStr = (*env)->NewString(env, (PWCHAR)realm, (USHORT)realmLen);
+ (*env)->CallVoidMethod(env, principal, setRealmMethod, realmStr);
+
+ // free local resources
+ LocalFree(realm);
+
+ return principal;
}
jobject BuildEncryptionKey(JNIEnv *env, PKERB_CRYPTO_KEY cryptoKey) {
- // First, need to build a byte array
- jbyteArray ary;
- jobject encryptionKey = NULL;
+ // First, need to build a byte array
+ jbyteArray ary;
+ jobject encryptionKey = NULL;
- ary = (*env)->NewByteArray(env,cryptoKey->Length);
- (*env)->SetByteArrayRegion(env, ary, (jsize) 0, cryptoKey->Length,
- (jbyte *)cryptoKey->Value);
- if ((*env)->ExceptionOccurred(env)) {
- (*env)->DeleteLocalRef(env, ary);
- } else {
- encryptionKey = (*env)->NewObject(env, encryptionKeyClass,
- encryptionKeyConstructor, cryptoKey->KeyType, ary);
- }
+ ary = (*env)->NewByteArray(env,cryptoKey->Length);
+ (*env)->SetByteArrayRegion(env, ary, (jsize) 0, cryptoKey->Length,
+ (jbyte *)cryptoKey->Value);
+ if ((*env)->ExceptionOccurred(env)) {
+ (*env)->DeleteLocalRef(env, ary);
+ } else {
+ encryptionKey = (*env)->NewObject(env, encryptionKeyClass,
+ encryptionKeyConstructor, cryptoKey->KeyType, ary);
+ }
- return encryptionKey;
+ return encryptionKey;
}
jobject BuildTicketFlags(JNIEnv *env, PULONG flags) {
- jobject ticketFlags = NULL;
- jbyteArray ary;
- /*
- * mdu: Convert the bytes to nework byte order before copying
- * them to a Java byte array.
- */
- ULONG nlflags = htonl(*flags);
+ jobject ticketFlags = NULL;
+ jbyteArray ary;
+ /*
+ * mdu: Convert the bytes to nework byte order before copying
+ * them to a Java byte array.
+ */
+ ULONG nlflags = htonl(*flags);
- ary = (*env)->NewByteArray(env, sizeof(*flags));
- (*env)->SetByteArrayRegion(env, ary, (jsize) 0, sizeof(*flags),
- (jbyte *)&nlflags);
- if ((*env)->ExceptionOccurred(env)) {
- (*env)->DeleteLocalRef(env, ary);
- } else {
- ticketFlags = (*env)->NewObject(env, ticketFlagsClass,
- ticketFlagsConstructor, sizeof(*flags)*8, ary);
- }
+ ary = (*env)->NewByteArray(env, sizeof(*flags));
+ (*env)->SetByteArrayRegion(env, ary, (jsize) 0, sizeof(*flags),
+ (jbyte *)&nlflags);
+ if ((*env)->ExceptionOccurred(env)) {
+ (*env)->DeleteLocalRef(env, ary);
+ } else {
+ ticketFlags = (*env)->NewObject(env, ticketFlagsClass,
+ ticketFlagsConstructor, sizeof(*flags)*8, ary);
+ }
- return ticketFlags;
+ return ticketFlags;
}
jobject BuildKerberosTime(JNIEnv *env, PLARGE_INTEGER kerbtime) {
- jobject kerberosTime = NULL;
- jstring stringTime = NULL;
- SYSTEMTIME systemTime;
- WCHAR timeString[16];
- WCHAR month[3];
- WCHAR day[3];
- WCHAR hour[3];
- WCHAR minute[3];
- WCHAR second[3];
+ jobject kerberosTime = NULL;
+ jstring stringTime = NULL;
+ SYSTEMTIME systemTime;
+ WCHAR timeString[16];
+ WCHAR month[3];
+ WCHAR day[3];
+ WCHAR hour[3];
+ WCHAR minute[3];
+ WCHAR second[3];
- if (FileTimeToSystemTime((FILETIME *)kerbtime, &systemTime)) {
-// XXX Cannot use %02.2ld, because the leading 0 is ignored for integers.
-// So, print them to strings, and then print them to the master string with a
-// format pattern that makes it two digits and prefix with a 0 if necessary.
- swprintf( (wchar_t *)month, L"%2.2d", systemTime.wMonth);
- swprintf( (wchar_t *)day, L"%2.2d", systemTime.wDay);
- swprintf( (wchar_t *)hour, L"%2.2d", systemTime.wHour);
- swprintf( (wchar_t *)minute, L"%2.2d", systemTime.wMinute);
- swprintf( (wchar_t *)second, L"%2.2d", systemTime.wSecond);
- swprintf( (wchar_t *)timeString,
- L"%ld%02.2s%02.2s%02.2s%02.2s%02.2sZ",
+ if (FileTimeToSystemTime((FILETIME *)kerbtime, &systemTime)) {
+ // XXX Cannot use %02.2ld, because the leading 0 is ignored for integers.
+ // So, print them to strings, and then print them to the master string with a
+ // format pattern that makes it two digits and prefix with a 0 if necessary.
+ swprintf( (wchar_t *)month, L"%2.2d", systemTime.wMonth);
+ swprintf( (wchar_t *)day, L"%2.2d", systemTime.wDay);
+ swprintf( (wchar_t *)hour, L"%2.2d", systemTime.wHour);
+ swprintf( (wchar_t *)minute, L"%2.2d", systemTime.wMinute);
+ swprintf( (wchar_t *)second, L"%2.2d", systemTime.wSecond);
+ swprintf( (wchar_t *)timeString,
+ L"%ld%02.2s%02.2s%02.2s%02.2s%02.2sZ",
systemTime.wYear,
month,
day,
hour,
minute,
second );
- #ifdef DEBUG
- printf("%S\n", (wchar_t *)timeString);
- #endif /* DEBUG */
- stringTime = (*env)->NewString(env, timeString,
- (sizeof(timeString)/sizeof(WCHAR))-1);
- if (stringTime != NULL) { // everything's OK so far
- kerberosTime = (*env)->NewObject(env, kerberosTimeClass,
- kerberosTimeConstructor, stringTime);
- }
+ #ifdef DEBUG
+ printf("%S\n", (wchar_t *)timeString);
+ #endif /* DEBUG */
+ stringTime = (*env)->NewString(env, timeString,
+ (sizeof(timeString)/sizeof(WCHAR))-1);
+ if (stringTime != NULL) { // everything's OK so far
+ kerberosTime = (*env)->NewObject(env, kerberosTimeClass,
+ kerberosTimeConstructor, stringTime);
}
- return kerberosTime;
+ }
+ return kerberosTime;
}
From ffacce23977bf834184fc339d99f6bbe594d04b1 Mon Sep 17 00:00:00 2001
From: Jean-Christophe Collet
Date: Wed, 5 Mar 2008 11:40:22 +0100
Subject: [PATCH 026/126] 6641309: Wrong Cookie separator used in
HttpURLConnection
Added a space to cookie separator. Generified the code and added tags.
Reviewed-by: chegar
---
.../www/protocol/http/HttpURLConnection.java | 58 +++++---
.../net/CookieHandler/CookieManagerTest.java | 30 ++--
.../sun/net/www/protocol/http/B6641309.java | 129 ++++++++++++++++++
3 files changed, 184 insertions(+), 33 deletions(-)
create mode 100644 jdk/test/sun/net/www/protocol/http/B6641309.java
diff --git a/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java b/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
index fb1f3b05ed1..b0cd7c8e856 100644
--- a/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
@@ -64,11 +64,6 @@ import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.net.MalformedURLException;
import java.nio.ByteBuffer;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
-import java.nio.channels.Selector;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.SelectableChannel;
import java.lang.reflect.*;
/**
@@ -824,6 +819,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* - get input, [read input,] get output, [write output]
*/
+ @Override
public synchronized OutputStream getOutputStream() throws IOException {
try {
@@ -908,30 +904,25 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
URI uri = ParseUtil.toURI(url);
if (uri != null) {
- Map cookies = cookieHandler.get(uri, requests.getHeaders(EXCLUDE_HEADERS));
+ Map> cookies = cookieHandler.get(uri, requests.getHeaders(EXCLUDE_HEADERS));
if (!cookies.isEmpty()) {
- Set s = cookies.entrySet();
- Iterator k_itr = s.iterator();
- while (k_itr.hasNext()) {
- Map.Entry entry = (Map.Entry)k_itr.next();
- String key = (String)entry.getKey();
+ for (Map.Entry> entry : cookies.entrySet()) {
+ String key = entry.getKey();
// ignore all entries that don't have "Cookie"
// or "Cookie2" as keys
if (!"Cookie".equalsIgnoreCase(key) &&
!"Cookie2".equalsIgnoreCase(key)) {
continue;
}
- List l = (List)entry.getValue();
+ List l = entry.getValue();
if (l != null && !l.isEmpty()) {
- Iterator v_itr = l.iterator();
StringBuilder cookieValue = new StringBuilder();
- while (v_itr.hasNext()) {
- String value = (String)v_itr.next();
- cookieValue.append(value).append(';');
+ for (String value : l) {
+ cookieValue.append(value).append("; ");
}
- // strip off the ending ;-sign
+ // strip off the trailing '; '
try {
- requests.add(key, cookieValue.substring(0, cookieValue.length() - 1));
+ requests.add(key, cookieValue.substring(0, cookieValue.length() - 2));
} catch (StringIndexOutOfBoundsException ignored) {
// no-op
}
@@ -950,6 +941,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
} // end of getting cookies
}
+ @Override
+ @SuppressWarnings("empty-statement")
public synchronized InputStream getInputStream() throws IOException {
if (!doInput) {
@@ -1386,6 +1379,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
}
+ @Override
public InputStream getErrorStream() {
if (connected && responseCode >= 400) {
// Client Error 4xx and Server Error 5xx
@@ -2152,6 +2146,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* Gets a header field by name. Returns null if not known.
* @param name the name of the header field
*/
+ @Override
public String getHeaderField(String name) {
try {
getInputStream();
@@ -2174,6 +2169,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* @return a Map of header fields
* @since 1.4
*/
+ @Override
public Map getHeaderFields() {
try {
getInputStream();
@@ -2190,6 +2186,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* Gets a header field by index. Returns null if not known.
* @param n the index of the header field
*/
+ @Override
public String getHeaderField(int n) {
try {
getInputStream();
@@ -2205,6 +2202,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* Gets a header field by index. Returns null if not known.
* @param n the index of the header field
*/
+ @Override
public String getHeaderFieldKey(int n) {
try {
getInputStream();
@@ -2222,6 +2220,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* exists, overwrite its value with the new value.
* @param value the value to be set
*/
+ @Override
public void setRequestProperty(String key, String value) {
if (connected)
throw new IllegalStateException("Already connected");
@@ -2243,6 +2242,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* @see #getRequestProperties(java.lang.String)
* @since 1.4
*/
+ @Override
public void addRequestProperty(String key, String value) {
if (connected)
throw new IllegalStateException("Already connected");
@@ -2262,6 +2262,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
requests.set(key, value);
}
+ @Override
public String getRequestProperty (String key) {
// don't return headers containing security sensitive information
if (key != null) {
@@ -2286,6 +2287,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* @throws IllegalStateException if already connected
* @since 1.4
*/
+ @Override
public Map getRequestProperties() {
if (connected)
throw new IllegalStateException("Already connected");
@@ -2294,6 +2296,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
return requests.getHeaders(EXCLUDE_HEADERS);
}
+ @Override
public void setConnectTimeout(int timeout) {
if (timeout < 0)
throw new IllegalArgumentException("timeouts can't be negative");
@@ -2313,6 +2316,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* @see java.net.URLConnection#connect()
* @since 1.5
*/
+ @Override
public int getConnectTimeout() {
return (connectTimeout < 0 ? 0 : connectTimeout);
}
@@ -2337,6 +2341,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* @see java.io.InputStream#read()
* @since 1.5
*/
+ @Override
public void setReadTimeout(int timeout) {
if (timeout < 0)
throw new IllegalArgumentException("timeouts can't be negative");
@@ -2354,10 +2359,12 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* @see java.io.InputStream#read()
* @since 1.5
*/
+ @Override
public int getReadTimeout() {
return readTimeout < 0 ? 0 : readTimeout;
}
+ @Override
protected void finalize() {
// this should do nothing. The stream finalizer will close
// the fd
@@ -2437,6 +2444,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* @see java.io.FilterInputStream#in
* @see java.io.FilterInputStream#reset()
*/
+ @Override
public synchronized void mark(int readlimit) {
super.mark(readlimit);
if (cacheRequest != null) {
@@ -2466,6 +2474,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* @see java.io.FilterInputStream#in
* @see java.io.FilterInputStream#mark(int)
*/
+ @Override
public synchronized void reset() throws IOException {
super.reset();
if (cacheRequest != null) {
@@ -2474,6 +2483,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
}
+ @Override
public int read() throws IOException {
try {
byte[] b = new byte[1];
@@ -2487,10 +2497,12 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
}
+ @Override
public int read(byte[] b) throws IOException {
return read(b, 0, b.length);
}
+ @Override
public int read(byte[] b, int off, int len) throws IOException {
try {
int newLen = super.read(b, off, len);
@@ -2521,6 +2533,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
}
+ @Override
public void close () throws IOException {
try {
if (outputStream != null) {
@@ -2565,6 +2578,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
error = false;
}
+ @Override
public void write (int b) throws IOException {
checkError();
written ++;
@@ -2574,10 +2588,12 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
out.write (b);
}
+ @Override
public void write (byte[] b) throws IOException {
write (b, 0, b.length);
}
+ @Override
public void write (byte[] b, int off, int len) throws IOException {
checkError();
written += len;
@@ -2608,6 +2624,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
return closed && ! error;
}
+ @Override
public void close () throws IOException {
if (closed) {
return;
@@ -2726,6 +2743,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
}
+ @Override
public int available() throws IOException {
if (is == null) {
return buffer.remaining();
@@ -2740,10 +2758,12 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
return (ret == -1? ret : (b[0] & 0x00FF));
}
+ @Override
public int read(byte[] b) throws IOException {
return read(b, 0, b.length);
}
+ @Override
public int read(byte[] b, int off, int len) throws IOException {
int rem = buffer.remaining();
if (rem > 0) {
@@ -2759,6 +2779,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
}
+ @Override
public void close() throws IOException {
buffer = null;
if (is != null) {
@@ -2775,6 +2796,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
class EmptyInputStream extends InputStream {
+ @Override
public int available() {
return 0;
}
diff --git a/jdk/test/java/net/CookieHandler/CookieManagerTest.java b/jdk/test/java/net/CookieHandler/CookieManagerTest.java
index a2c9db3b411..b83c27fcefc 100644
--- a/jdk/test/java/net/CookieHandler/CookieManagerTest.java
+++ b/jdk/test/java/net/CookieHandler/CookieManagerTest.java
@@ -132,17 +132,17 @@ class CookieHttpTransaction implements HttpCallback {
),
new CookieTestCase("Set-Cookie",
"PART_NUMBER=ROCKET_LAUNCHER_0001; path=/;" + "domain=." + localHostAddr,
- "CUSTOMER=WILE:BOB;PART_NUMBER=ROCKET_LAUNCHER_0001",
+ "CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001",
"/"
),
new CookieTestCase("Set-Cookie",
"SHIPPING=FEDEX; path=/foo;" + "domain=." + localHostAddr,
- "CUSTOMER=WILE:BOB;PART_NUMBER=ROCKET_LAUNCHER_0001",
+ "CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001",
"/"
),
new CookieTestCase("Set-Cookie",
"SHIPPING=FEDEX; path=/foo;" + "domain=." + localHostAddr,
- "CUSTOMER=WILE:BOB;PART_NUMBER=ROCKET_LAUNCHER_0001;SHIPPING=FEDEX",
+ "CUSTOMER=WILE:BOB; PART_NUMBER=ROCKET_LAUNCHER_0001; SHIPPING=FEDEX",
"/foo"
)
};
@@ -157,7 +157,7 @@ class CookieHttpTransaction implements HttpCallback {
),
new CookieTestCase("Set-Cookie",
"PART_NUMBER=RIDING_ROCKET_0023; path=/ammo;" + "domain=." + localHostAddr,
- "PART_NUMBER=RIDING_ROCKET_0023;PART_NUMBER=ROCKET_LAUNCHER_0001",
+ "PART_NUMBER=RIDING_ROCKET_0023; PART_NUMBER=ROCKET_LAUNCHER_0001",
"/ammo"
)
};
@@ -167,17 +167,17 @@ class CookieHttpTransaction implements HttpCallback {
testCases[count++] = new CookieTestCase[]{
new CookieTestCase("Set-Cookie2",
"Customer=\"WILE_E_COYOTE\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr,
- "$Version=\"1\";Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
+ "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
"/acme/login"
),
new CookieTestCase("Set-Cookie2",
"Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\";" + "domain=." + localHostAddr,
- "$Version=\"1\";Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"" + ";Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"",
+ "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"",
"/acme/pickitem"
),
new CookieTestCase("Set-Cookie2",
"Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr,
- "$Version=\"1\";Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"" + ";Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"" + ";Shipping=\"FedEx\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"",
+ "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"" + "; Shipping=\"FedEx\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"",
"/acme/shipping"
)
};
@@ -187,17 +187,17 @@ class CookieHttpTransaction implements HttpCallback {
testCases[count++] = new CookieTestCase[]{
new CookieTestCase("Set-Cookie2",
"Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr,
- "$Version=\"1\";Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
+ "$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
"/acme/ammo"
),
new CookieTestCase("Set-Cookie2",
"Part_Number=\"Riding_Rocket_0023\"; Version=\"1\"; Path=\"/acme/ammo\";" + "domain=." + localHostAddr,
- "$Version=\"1\";Part_Number=\"Riding_Rocket_0023\";$Path=\"/acme/ammo\";$Domain=\"." + localHostAddr + "\"" + ";Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"",
+ "$Version=\"1\"; Part_Number=\"Riding_Rocket_0023\";$Path=\"/acme/ammo\";$Domain=\"." + localHostAddr + "\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"",
"/acme/ammo"
),
new CookieTestCase("",
"",
- "$Version=\"1\";Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"",
+ "$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";" + "$Domain=\"." + localHostAddr + "\"",
"/acme/parts"
)
};
@@ -207,12 +207,12 @@ class CookieHttpTransaction implements HttpCallback {
testCases[count++] = new CookieTestCase[]{
new CookieTestCase("Set-Cookie2",
"Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr,
- "$Version=\"1\";Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
+ "$Version=\"1\"; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
"/acme"
),
new CookieTestCase("Set-Cookie2",
"Part_Number=\"Rocket_Launcher_2000\"; Version=\"1\"; Path=\"/acme\";" + "domain=." + localHostAddr,
- "$Version=\"1\";Part_Number=\"Rocket_Launcher_2000\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
+ "$Version=\"1\"; Part_Number=\"Rocket_Launcher_2000\";$Path=\"/acme\";$Domain=\"." + localHostAddr + "\"",
"/acme"
)
};
@@ -222,17 +222,17 @@ class CookieHttpTransaction implements HttpCallback {
testCases[count++] = new CookieTestCase[]{
new CookieTestCase("Set-Cookie2",
"Customer=\"WILE_E_COYOTE\"; Version=\"1\"; Path=\"/acme\"",
- "$Version=\"1\";Customer=\"WILE_E_COYOTE\";$Path=\"/acme\"",
+ "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\"",
"/acme/login"
),
new CookieTestCase("Set-Cookie2",
"Part_Number=\"Rocket_Launcher_0001\"; Version=\"1\";Path=\"/acme\"",
- "$Version=\"1\";Customer=\"WILE_E_COYOTE\";$Path=\"/acme\"" + ";Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\"",
+ "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\"",
"/acme/pickitem"
),
new CookieTestCase("Set-Cookie2",
"Shipping=\"FedEx\"; Version=\"1\"; Path=\"/acme\"",
- "$Version=\"1\";Customer=\"WILE_E_COYOTE\";$Path=\"/acme\"" + ";Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\"" + ";Shipping=\"FedEx\";$Path=\"/acme\"",
+ "$Version=\"1\"; Customer=\"WILE_E_COYOTE\";$Path=\"/acme\"" + "; Part_Number=\"Rocket_Launcher_0001\";$Path=\"/acme\"" + "; Shipping=\"FedEx\";$Path=\"/acme\"",
"/acme/shipping"
)
};
diff --git a/jdk/test/sun/net/www/protocol/http/B6641309.java b/jdk/test/sun/net/www/protocol/http/B6641309.java
new file mode 100644
index 00000000000..15e8fdc31bc
--- /dev/null
+++ b/jdk/test/sun/net/www/protocol/http/B6641309.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6641309
+ * @summary Wrong Cookie separator used in HttpURLConnection
+ */
+
+import java.net.*;
+import java.util.*;
+import java.io.*;
+import com.sun.net.httpserver.*;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ExecutorService;
+
+public class B6641309
+{
+ com.sun.net.httpserver.HttpServer httpServer;
+ ExecutorService executorService;
+
+ public static void main(String[] args)
+ {
+ new B6641309();
+ }
+
+ public B6641309()
+ {
+ try {
+ startHttpServer();
+ doClient();
+ } catch (IOException ioe) {
+ System.err.println(ioe);
+ }
+ }
+
+ void doClient() {
+ CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
+ try {
+ InetSocketAddress address = httpServer.getAddress();
+
+ // GET Request
+ URL url = new URL("http://localhost:" + address.getPort() + "/test/");
+ CookieHandler ch = CookieHandler.getDefault();
+ Map> header = new HashMap>();
+ List values = new LinkedList();
+ values.add("Test1Cookie=TEST1; path=/test/");
+ values.add("Test2Cookie=TEST2; path=/test/");
+ header.put("Set-Cookie", values);
+
+ // preload the CookieHandler with a cookie for our URL
+ // so that it will be sent during the first request
+ ch.put(url.toURI(), header);
+ HttpURLConnection uc = (HttpURLConnection)url.openConnection();
+ int resp = uc.getResponseCode();
+ if (resp != 200)
+ throw new RuntimeException("Failed: Response code from GET is not 200");
+
+ System.out.println("Response code from GET = 200 OK");
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ } finally {
+ httpServer.stop(1);
+ executorService.shutdown();
+ }
+ }
+
+ /**
+ * Http Server
+ */
+ public void startHttpServer() throws IOException {
+ httpServer = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(0), 0);
+
+ // create HttpServer context
+ HttpContext ctx = httpServer.createContext("/test/", new MyHandler());
+
+ executorService = Executors.newCachedThreadPool();
+ httpServer.setExecutor(executorService);
+ httpServer.start();
+ }
+
+ class MyHandler implements HttpHandler {
+ public void handle(HttpExchange t) throws IOException {
+ InputStream is = t.getRequestBody();
+ Headers reqHeaders = t.getRequestHeaders();
+ int i = 0;
+ // Read till end of stream
+ do {
+ i = is.read();
+ } while (i != -1);
+ is.close();
+
+ List cookies = reqHeaders.get("Cookie");
+ if (cookies != null) {
+ for (String str : cookies) {
+ // The separator between the 2 cookies should be
+ // a semi-colon AND a space
+ if (str.equals("Test1Cookie=TEST1; Test2Cookie=TEST2"))
+ t.sendResponseHeaders(200, -1);
+ }
+ }
+ t.sendResponseHeaders(400, -1);
+ t.close();
+ }
+ }
+}
From 578a880feef75eb2cd4476489838de0aacfb0d06 Mon Sep 17 00:00:00 2001
From: Weijun Wang
Date: Wed, 5 Mar 2008 21:55:33 +0800
Subject: [PATCH 027/126] 6648972: KDCReq.init always read padata
PA-DATA is optional, only read it when it exists
Reviewed-by: valeriep
---
.../security/krb5/internal/ETypeInfo2.java | 8 +-
.../sun/security/krb5/internal/KDCReq.java | 4 +-
.../security/krb5/OptionPADataInKDCReq.java | 123 ++++++++++++++++++
3 files changed, 129 insertions(+), 6 deletions(-)
create mode 100644 jdk/test/sun/security/krb5/OptionPADataInKDCReq.java
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/ETypeInfo2.java b/jdk/src/share/classes/sun/security/krb5/internal/ETypeInfo2.java
index 110e38b0806..30bf4dfb3c9 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/ETypeInfo2.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/ETypeInfo2.java
@@ -100,16 +100,16 @@ public class ETypeInfo2 {
// salt
if (encoding.getData().available() > 0) {
- der = encoding.getData().getDerValue();
- if ((der.getTag() & 0x1F) == 0x01) {
+ if ((encoding.getData().peekByte() & 0x1F) == 0x01) {
+ der = encoding.getData().getDerValue();
this.saltStr = der.getData().getGeneralString();
}
}
// s2kparams
if (encoding.getData().available() > 0) {
- der = encoding.getData().getDerValue();
- if ((der.getTag() & 0x1F) == 0x02) {
+ if ((encoding.getData().peekByte() & 0x1F) == 0x02) {
+ der = encoding.getData().getDerValue();
this.s2kparams = der.getData().getOctetString();
}
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/KDCReq.java b/jdk/src/share/classes/sun/security/krb5/internal/KDCReq.java
index fee4567c3c6..a46f6436cd8 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/KDCReq.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/KDCReq.java
@@ -144,8 +144,8 @@ public class KDCReq {
} else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
- subDer = der.getData().getDerValue();
- if ((subDer.getTag() & 0x01F) == 0x03) {
+ if ((der.getData().peekByte() & 0x1F) == 0x03) {
+ subDer = der.getData().getDerValue();
DerValue subsubDer = subDer.getData().getDerValue();
if (subsubDer.getTag() != DerValue.tag_SequenceOf) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
diff --git a/jdk/test/sun/security/krb5/OptionPADataInKDCReq.java b/jdk/test/sun/security/krb5/OptionPADataInKDCReq.java
new file mode 100644
index 00000000000..2229b541e89
--- /dev/null
+++ b/jdk/test/sun/security/krb5/OptionPADataInKDCReq.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+/*
+ * @test
+ * @bug 6648972
+ * @summary KDCReq.init always read padata
+ */
+import sun.security.krb5.internal.ETypeInfo2;
+import sun.security.krb5.internal.KDCReq;
+import sun.security.util.DerValue;
+
+public class OptionPADataInKDCReq {
+ public static void main(String[] args) throws Exception {
+ /*
+ * This is a AS-REQ block without padata. The content is --
+ [APPLICATION 10] SEQUENCE {
+ [1] INTEGER 5
+ [2] INTEGER 10
+ [4] SEQUENCE {
+ [0] BIT STRING 01000000 10000001 00000000 00010000
+ [1] SEQUENCE {
+ [0] INTEGER 1
+ [1] SEQUENCE {
+ STRING administrator
+ }
+ }
+ [2] STRING N3
+ [3] SEQUENCE {
+ [0] INTEGER 2
+ [1] SEQUENCE {
+ STRING krbtgt
+ STRING N3
+ }
+ }
+ [5] TIME Sun Sep 13 10:48:05 CST 2037
+ [6] TIME Sun Sep 13 10:48:05 CST 2037
+ [7] INTEGER 2101281516
+ [8] SEQUENCE {
+ INTEGER 23
+ INTEGER -133
+ INTEGER -128
+ INTEGER 3
+ INTEGER 1
+ INTEGER 24
+ INTEGER -135
+ }
+ [9] SEQUENCE {
+ SEQUENCE {
+ [0] INTEGER 20
+ [1] OCTET STRING
+ 0000: 58 50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 XP
+ }
+ }
+ }
+ }
+ */
+ byte[] b = {
+ (byte)0x6a, (byte)0x81, (byte)0xbf, (byte)0x30, (byte)0x81, (byte)0xbc, (byte)0xa1, (byte)0x03,
+ (byte)0x02, (byte)0x01, (byte)0x05, (byte)0xa2, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x0a,
+ (byte)0xa4, (byte)0x81, (byte)0xaf, (byte)0x30, (byte)0x81, (byte)0xac, (byte)0xa0, (byte)0x07,
+ (byte)0x03, (byte)0x05, (byte)0x00, (byte)0x40, (byte)0x81, (byte)0x00, (byte)0x10, (byte)0xa1,
+ (byte)0x1a, (byte)0x30, (byte)0x18, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01,
+ (byte)0xa1, (byte)0x11, (byte)0x30, (byte)0x0f, (byte)0x1b, (byte)0x0d, (byte)0x61, (byte)0x64,
+ (byte)0x6d, (byte)0x69, (byte)0x6e, (byte)0x69, (byte)0x73, (byte)0x74, (byte)0x72, (byte)0x61,
+ (byte)0x74, (byte)0x6f, (byte)0x72, (byte)0xa2, (byte)0x04, (byte)0x1b, (byte)0x02, (byte)0x4e,
+ (byte)0x33, (byte)0xa3, (byte)0x17, (byte)0x30, (byte)0x15, (byte)0xa0, (byte)0x03, (byte)0x02,
+ (byte)0x01, (byte)0x02, (byte)0xa1, (byte)0x0e, (byte)0x30, (byte)0x0c, (byte)0x1b, (byte)0x06,
+ (byte)0x6b, (byte)0x72, (byte)0x62, (byte)0x74, (byte)0x67, (byte)0x74, (byte)0x1b, (byte)0x02,
+ (byte)0x4e, (byte)0x33, (byte)0xa5, (byte)0x11, (byte)0x18, (byte)0x0f, (byte)0x32, (byte)0x30,
+ (byte)0x33, (byte)0x37, (byte)0x30, (byte)0x39, (byte)0x31, (byte)0x33, (byte)0x30, (byte)0x32,
+ (byte)0x34, (byte)0x38, (byte)0x30, (byte)0x35, (byte)0x5a, (byte)0xa6, (byte)0x11, (byte)0x18,
+ (byte)0x0f, (byte)0x32, (byte)0x30, (byte)0x33, (byte)0x37, (byte)0x30, (byte)0x39, (byte)0x31,
+ (byte)0x33, (byte)0x30, (byte)0x32, (byte)0x34, (byte)0x38, (byte)0x30, (byte)0x35, (byte)0x5a,
+ (byte)0xa7, (byte)0x06, (byte)0x02, (byte)0x04, (byte)0x7d, (byte)0x3f, (byte)0x02, (byte)0xec,
+ (byte)0xa8, (byte)0x19, (byte)0x30, (byte)0x17, (byte)0x02, (byte)0x01, (byte)0x17, (byte)0x02,
+ (byte)0x02, (byte)0xff, (byte)0x7b, (byte)0x02, (byte)0x01, (byte)0x80, (byte)0x02, (byte)0x01,
+ (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0x02, (byte)0x01, (byte)0x18, (byte)0x02,
+ (byte)0x02, (byte)0xff, (byte)0x79, (byte)0xa9, (byte)0x1d, (byte)0x30, (byte)0x1b, (byte)0x30,
+ (byte)0x19, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x14, (byte)0xa1, (byte)0x12,
+ (byte)0x04, (byte)0x10, (byte)0x58, (byte)0x50, (byte)0x20, (byte)0x20, (byte)0x20, (byte)0x20,
+ (byte)0x20, (byte)0x20, (byte)0x20, (byte)0x20, (byte)0x20, (byte)0x20, (byte)0x20, (byte)0x20,
+ (byte)0x20, (byte)0x20,
+ };
+ new KDCReq(b, 0x0a);
+
+ /*
+ * This is a fake ETYPEINFO2 block with no salt
+ SEQUENCE {
+ [0] INTEGER 0
+ [2] OCTET STRING 0000: 00 .
+ }
+ */
+ byte[] b2 = {
+ (byte)0x30, (byte)0x0a, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0xa2,
+ (byte)0x03, (byte)0x04, (byte)0x01, (byte)0x00,
+ };
+
+ ETypeInfo2 e2 = new ETypeInfo2(new DerValue(b2));
+ if (e2.getSalt() != null || e2.getParams() == null) {
+ throw new Exception("ETypeInfo2 decoding error");
+ }
+ }
+}
From 0c6743a97086dd3c574e2d00b5a338f56a04ac97 Mon Sep 17 00:00:00 2001
From: Weijun Wang
Date: Wed, 5 Mar 2008 22:15:45 +0800
Subject: [PATCH 028/126] 6590930: reed/write does not match for ccache
Add null-awareness to ccache read
Reviewed-by: valeriep
---
.../internal/ccache/CCacheInputStream.java | 12 ++-
.../krb5/internal/ccache/Credentials.java | 27 ++++--
jdk/test/sun/security/krb5/TimeInCCache.java | 93 +++++++++++++++++++
3 files changed, 121 insertions(+), 11 deletions(-)
create mode 100644 jdk/test/sun/security/krb5/TimeInCCache.java
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java b/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java
index 5a62d6d2508..9271d9bcefb 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java
@@ -338,15 +338,19 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC
System.out.println(">>>DEBUG key type: " + key.getEType());
long times[] = readTimes();
KerberosTime authtime = new KerberosTime(times[0]);
- KerberosTime starttime = new KerberosTime(times[1]);
+ KerberosTime starttime =
+ (times[1]==0) ? null : new KerberosTime(times[1]);
KerberosTime endtime = new KerberosTime(times[2]);
- KerberosTime renewTill = new KerberosTime(times[3]);
+ KerberosTime renewTill =
+ (times[3]==0) ? null : new KerberosTime(times[3]);
if (DEBUG) {
System.out.println(">>>DEBUG auth time: " + authtime.toDate().toString());
- System.out.println(">>>DEBUG start time: " + starttime.toDate().toString());
+ System.out.println(">>>DEBUG start time: " +
+ ((starttime==null)?"null":starttime.toDate().toString()));
System.out.println(">>>DEBUG end time: " + endtime.toDate().toString());
- System.out.println(">>>DEBUG renew_till time: " + renewTill.toDate().toString());
+ System.out.println(">>>DEBUG renew_till time: " +
+ ((renewTill==null)?"null":renewTill.toDate().toString()));
}
boolean skey = readskey();
boolean flags[] = readFlags();
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/ccache/Credentials.java b/jdk/src/share/classes/sun/security/krb5/internal/ccache/Credentials.java
index 0c7b1ed32b2..ff45cb73d37 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/ccache/Credentials.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/ccache/Credentials.java
@@ -79,9 +79,13 @@ public class Credentials {
key = (EncryptionKey) new_key.clone();
authtime = (KerberosTime) new_authtime.clone();
- starttime = (KerberosTime) new_starttime.clone();
+ if (new_starttime != null) {
+ starttime = (KerberosTime) new_starttime.clone();
+ }
endtime = (KerberosTime) new_endtime.clone();
- renewTill = (KerberosTime) new_renewTill.clone();
+ if (new_renewTill != null) {
+ renewTill = (KerberosTime) new_renewTill.clone();
+ }
if (new_caddr != null) {
caddr = (HostAddresses) new_caddr.clone();
}
@@ -112,9 +116,13 @@ public class Credentials {
key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone();
flags = (TicketFlags) kdcRep.encKDCRepPart.flags.clone();
authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone();
- starttime = (KerberosTime) kdcRep.encKDCRepPart.starttime.clone();
+ if (kdcRep.encKDCRepPart.starttime != null) {
+ starttime = (KerberosTime) kdcRep.encKDCRepPart.starttime.clone();
+ }
endtime = (KerberosTime) kdcRep.encKDCRepPart.endtime.clone();
- renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone();
+ if (kdcRep.encKDCRepPart.renewTill != null) {
+ renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone();
+ }
srealm = (Realm) kdcRep.encKDCRepPart.srealm.clone();
sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone();
caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone();
@@ -181,9 +189,14 @@ public class Credentials {
boolean valid = true;
if (endtime.getTime() < System.currentTimeMillis()) {
valid = false;
- } else if ((starttime.getTime() > System.currentTimeMillis())
- || ((starttime == null) && (authtime.getTime() > System.currentTimeMillis()))) {
- valid = false;
+ } else if (starttime != null) {
+ if (starttime.getTime() > System.currentTimeMillis()) {
+ valid = false;
+ }
+ } else {
+ if (authtime.getTime() > System.currentTimeMillis()) {
+ valid = false;
+ }
}
return valid;
}
diff --git a/jdk/test/sun/security/krb5/TimeInCCache.java b/jdk/test/sun/security/krb5/TimeInCCache.java
new file mode 100644
index 00000000000..5ef8b5370df
--- /dev/null
+++ b/jdk/test/sun/security/krb5/TimeInCCache.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+/*
+ * @test
+ * @bug 6590930
+ * @summary read/write does not match for ccache
+ */
+
+import java.io.ByteArrayInputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import sun.security.krb5.internal.ccache.CCacheInputStream;
+import sun.security.krb5.internal.ccache.Credentials;
+
+public class TimeInCCache {
+ public static void main(String[] args) throws Exception {
+ // A trivial cache file, with startdate and renewTill being zero.
+ // The endtime is set to sometime in year 2022, so that isValid()
+ // will always check starttime.
+ byte[] ccache = new byte[]{
+ 5, 4, 0, 12, 0, 1, 0, 8, -1, -1, -1, 19, -1, -2, 89, 51,
+ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 10, 77, 65, 88, 73,
+ 46, 76, 79, 67, 65, 76, 0, 0, 0, 5, 100, 117, 109, 109, 121, 0,
+ 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 10, 77, 65, 88, 73, 46,
+ 76, 79, 67, 65, 76, 0, 0, 0, 5, 100, 117, 109, 109, 121, 0, 0,
+ 0, 0, 0, 0, 0, 2, 0, 0, 0, 10, 77, 65, 88, 73, 46, 76,
+ 79, 67, 65, 76, 0, 0, 0, 6, 107, 114, 98, 116, 103, 116, 0, 0,
+ 0, 10, 77, 65, 88, 73, 46, 76, 79, 67, 65, 76, 0, 17, 0, 0,
+ 0, 16, -78, -85, -90, -50, -68, 115, 68, 8, -39, -109, 91, 61, -17, -27,
+ -122, -120, 71, 69, 16, -121, 0, 0, 0, 0, 98, 69, 16, -121, 0, 0,
+ 0, 0, 0, 64, -32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 0, 97, -127, -3, 48, -127, -6, -96, 3, 2, 1, 5, -95, 12,
+ 27, 10, 77, 65, 88, 73, 46, 76, 79, 67, 65, 76, -94, 31, 48, 29,
+ -96, 3, 2, 1, 0, -95, 22, 48, 20, 27, 6, 107, 114, 98, 116, 103,
+ 116, 27, 10, 77, 65, 88, 73, 46, 76, 79, 67, 65, 76, -93, -127, -61,
+ 48, -127, -64, -96, 3, 2, 1, 17, -95, 3, 2, 1, 1, -94, -127, -77,
+ 4, -127, -80, 43, 65, -66, 34, 21, -34, 37, 35, 32, 50, -14, 122, 77,
+ -3, -29, 37, 99, 50, 125, -43, -96, -78, 85, 23, 41, -80, 68, 2, -109,
+ -27, 38, -41, -72, -32, 127, 63, -76, -22, 81, 33, -114, -30, 104, 125, -81,
+ -29, 70, -25, 23, 100, -75, -25, 62, -120, -78, -61, -100, -74, 50, -117, -127,
+ -16, 79, -106, 62, -39, 91, 100, -10, 23, -88, -18, -47, 51, -19, 113, 18,
+ 98, -101, 31, 98, 22, -81, 11, -41, -42, 67, 87, 92, -2, 42, -54, 79,
+ 49, -90, 43, -37, 90, -102, 125, 62, -88, -77, 100, 102, 23, -57, -51, 38,
+ 68, -44, -57, -102, 103, -6, 85, -58, 74, -117, -87, 67, -103, -36, 110, -122,
+ 115, 12, 118, -106, -114, -51, 79, 68, 32, -91, -53, -5, -51, 89, 72, 70,
+ 123, -12, -95, 9, 40, -30, -117, 74, 77, 38, 91, 126, -82, 17, 98, 98,
+ -49, 78, 36, 36, 103, -76, -100, -23, 118, -92, -8, 80, 103, -23, -98, 56,
+ 21, 65, -77, 0, 0, 0, 0
+ };
+ System.setProperty("sun.security.krb5.debug", "true"); // test code changes in DEBUG
+ CCacheInputStream cis = new CCacheInputStream(new ByteArrayInputStream(ccache));
+ cis.readVersion();
+ cis.readTag();
+ cis.readPrincipal(0x504);
+ Method m = CCacheInputStream.class.getDeclaredMethod("readCred", Integer.TYPE);
+ m.setAccessible(true);
+ Credentials c = (Credentials) m.invoke(cis, new Integer(0x504));
+ sun.security.krb5.Credentials cc = c.setKrbCreds();
+
+ // 1. Make sure starttime is still null
+ if (cc.getStartTime() != null) {
+ throw new Exception("Fail, starttime should be zero here");
+ }
+
+ // 2. Make sure renewTill is still null
+ if (cc.getRenewTill() != null) {
+ throw new Exception("Fail, renewTill should be zero here");
+ }
+
+ // 3. Make sure isValid works
+ c.isValid();
+ }
+}
From be421c50f197807b0c20436a4d9212e083009301 Mon Sep 17 00:00:00 2001
From: Weijun Wang
Date: Wed, 5 Mar 2008 22:16:06 +0800
Subject: [PATCH 029/126] 6664612: debug output leaked
Reviewed-by: valeriep
---
.../sun/security/krb5/internal/ccache/CCacheInputStream.java | 4 +++-
.../sun/security/krb5/internal/crypto/dk/AesDkCrypto.java | 4 +++-
.../sun/security/krb5/internal/crypto/dk/ArcFourCrypto.java | 4 +++-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java b/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java
index 9271d9bcefb..64c3f8cd85b 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java
@@ -215,7 +215,9 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC
addrType = read(2);
addrLength = read(4);
if (!(addrLength == 4 || addrLength == 16)) {
- System.out.println("Incorrect address format.");
+ if (DEBUG) {
+ System.out.println("Incorrect address format.");
+ }
return null;
}
byte[] result = new byte[addrLength];
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/crypto/dk/AesDkCrypto.java b/jdk/src/share/classes/sun/security/krb5/internal/crypto/dk/AesDkCrypto.java
index 31919fc51f5..ea6e2d3eb24 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/crypto/dk/AesDkCrypto.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/crypto/dk/AesDkCrypto.java
@@ -440,7 +440,9 @@ public class AesDkCrypto extends DkCrypto {
for (int i = 0; i < hashSize; i++) {
if (calculatedHmac[i] != ciphertext[hmacOffset+i]) {
cksumFailed = true;
- System.err.println("Checksum failed !");
+ if (debug) {
+ System.err.println("Checksum failed !");
+ }
break;
}
}
diff --git a/jdk/src/share/classes/sun/security/krb5/internal/crypto/dk/ArcFourCrypto.java b/jdk/src/share/classes/sun/security/krb5/internal/crypto/dk/ArcFourCrypto.java
index 57a0c091721..8d4c89d60b3 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/crypto/dk/ArcFourCrypto.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/crypto/dk/ArcFourCrypto.java
@@ -397,7 +397,9 @@ public class ArcFourCrypto extends DkCrypto {
for (int i = 0; i < hashSize; i++) {
if (calculatedHmac[i] != ciphertext[i]) {
cksumFailed = true;
- System.err.println("Checksum failed !");
+ if (debug) {
+ System.err.println("Checksum failed !");
+ }
break;
}
}
From 45c655a782143312678b0e75ccd9bb2597f40389 Mon Sep 17 00:00:00 2001
From: Jean-Christophe Collet
Date: Wed, 5 Mar 2008 17:16:14 +0100
Subject: [PATCH 030/126] 6660405: HttpURLConnection returns the wrong
InputStream
Set inputStream back to null in disconnectInternal().
Reviewed-by: chegar
---
.../www/protocol/http/HttpURLConnection.java | 1 +
.../sun/net/www/protocol/http/B6660405.java | 163 ++++++++++++++++++
2 files changed, 164 insertions(+)
create mode 100644 jdk/test/sun/net/www/protocol/http/B6660405.java
diff --git a/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java b/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
index b0cd7c8e856..ce030c8c5b8 100644
--- a/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
@@ -2048,6 +2048,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
*/
private void disconnectInternal() {
responseCode = -1;
+ inputStream = null;
if (pi != null) {
pi.finishTracking();
pi = null;
diff --git a/jdk/test/sun/net/www/protocol/http/B6660405.java b/jdk/test/sun/net/www/protocol/http/B6660405.java
new file mode 100644
index 00000000000..2309497c2fb
--- /dev/null
+++ b/jdk/test/sun/net/www/protocol/http/B6660405.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6660405
+ * @summary HttpURLConnection returns the wrong InputStream
+ */
+
+import java.net.*;
+import java.util.*;
+import java.io.*;
+import com.sun.net.httpserver.*;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ExecutorService;
+
+public class B6660405
+{
+ com.sun.net.httpserver.HttpServer httpServer;
+ ExecutorService executorService;
+
+ static class MyCacheResponse extends CacheResponse {
+ private byte[] buf = new byte[1024];
+
+ public MyCacheResponse() {
+ }
+
+ @Override
+ public Map> getHeaders() throws IOException
+ {
+ Map> h = new HashMap>();
+ ArrayList l = new ArrayList();
+ l.add("HTTP/1.1 200 OK");
+ h.put(null, l);
+ l = new ArrayList();
+ l.add("1024");
+ h.put("Content-Length", l);
+ return h;
+ }
+
+ @Override
+ public InputStream getBody() throws IOException
+ {
+ return new ByteArrayInputStream(buf);
+ }
+
+ }
+ static class MyResponseCache extends ResponseCache {
+
+ public MyResponseCache() {
+ }
+
+ @Override
+ public CacheResponse get(URI uri, String rqstMethod, Map> rqstHeaders) throws IOException
+ {
+ if (uri.getPath().equals("/redirect/index.html")) {
+ return new MyCacheResponse();
+ }
+ return null;
+ }
+
+ @Override
+ public CacheRequest put(URI uri, URLConnection conn) throws IOException
+ {
+ return null;
+ }
+
+ }
+
+ public static void main(String[] args)
+ {
+ new B6660405();
+ }
+
+ public B6660405()
+ {
+ try {
+ startHttpServer();
+ doClient();
+ } catch (IOException ioe) {
+ System.err.println(ioe);
+ }
+ }
+
+ void doClient() {
+ ResponseCache.setDefault(new MyResponseCache());
+ try {
+ InetSocketAddress address = httpServer.getAddress();
+
+ // GET Request
+ URL url = new URL("http://localhost:" + address.getPort() + "/test/index.html");
+ HttpURLConnection uc = (HttpURLConnection)url.openConnection();
+ int code = uc.getResponseCode();
+ System.err.println("response code = " + code);
+ int l = uc.getContentLength();
+ System.err.println("content-length = " + l);
+ InputStream in = uc.getInputStream();
+ int i = 0;
+ // Read till end of stream
+ do {
+ i = in.read();
+ } while (i != -1);
+ in.close();
+ } catch (IOException e) {
+ throw new RuntimeException("Got the wrong InputStream after checking headers");
+ } finally {
+ httpServer.stop(1);
+ executorService.shutdown();
+ }
+ }
+
+ /**
+ * Http Server
+ */
+ public void startHttpServer() throws IOException {
+ httpServer = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(0), 0);
+
+ // create HttpServer context
+ HttpContext ctx = httpServer.createContext("/test/", new MyHandler());
+
+ executorService = Executors.newCachedThreadPool();
+ httpServer.setExecutor(executorService);
+ httpServer.start();
+ }
+
+ class MyHandler implements HttpHandler {
+ public void handle(HttpExchange t) throws IOException {
+ InputStream is = t.getRequestBody();
+ Headers reqHeaders = t.getRequestHeaders();
+ Headers resHeaders = t.getResponseHeaders();
+
+ int i = 0;
+ // Read till end of stream
+ do {
+ i = is.read();
+ } while (i != -1);
+ is.close();
+ resHeaders.add("Location", "http://foo.bar/redirect/index.html");
+ t.sendResponseHeaders(302, -1);
+ t.close();
+ }
+ }
+}
From e33dde98175ea7d0d66790f510e74b10108725df Mon Sep 17 00:00:00 2001
From: Jean-Christophe Collet
Date: Wed, 5 Mar 2008 18:11:33 +0100
Subject: [PATCH 031/126] 6651717: Debug output statement left in
MailToURLConnection
Removed output statement, removed unused imports, added override tags.
Reviewed-by: chegar
---
.../net/www/protocol/mailto/MailToURLConnection.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/jdk/src/share/classes/sun/net/www/protocol/mailto/MailToURLConnection.java b/jdk/src/share/classes/sun/net/www/protocol/mailto/MailToURLConnection.java
index d939ce5515b..53367aead96 100644
--- a/jdk/src/share/classes/sun/net/www/protocol/mailto/MailToURLConnection.java
+++ b/jdk/src/share/classes/sun/net/www/protocol/mailto/MailToURLConnection.java
@@ -29,9 +29,6 @@ import java.net.URL;
import java.net.InetAddress;
import java.net.SocketPermission;
import java.io.*;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.StringTokenizer;
import java.security.Permission;
import sun.net.www.*;
import sun.net.smtp.SmtpClient;
@@ -86,11 +83,11 @@ public class MailToURLConnection extends URLConnection {
}
public void connect() throws IOException {
- System.err.println("connect. Timeout = " + connectTimeout);
client = new SmtpClient(connectTimeout);
client.setReadTimeout(readTimeout);
}
+ @Override
public synchronized OutputStream getOutputStream() throws IOException {
if (os != null) {
return os;
@@ -107,6 +104,7 @@ public class MailToURLConnection extends URLConnection {
return os;
}
+ @Override
public Permission getPermission() throws IOException {
if (permission == null) {
connect();
@@ -116,22 +114,26 @@ public class MailToURLConnection extends URLConnection {
return permission;
}
+ @Override
public void setConnectTimeout(int timeout) {
if (timeout < 0)
throw new IllegalArgumentException("timeouts can't be negative");
connectTimeout = timeout;
}
+ @Override
public int getConnectTimeout() {
return (connectTimeout < 0 ? 0 : connectTimeout);
}
+ @Override
public void setReadTimeout(int timeout) {
if (timeout < 0)
throw new IllegalArgumentException("timeouts can't be negative");
readTimeout = timeout;
}
+ @Override
public int getReadTimeout() {
return readTimeout < 0 ? 0 : readTimeout;
}
From d8e9d2232314cb96314b3c22405a73b0e08c7583 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Wed, 5 Mar 2008 18:56:03 -0800
Subject: [PATCH 032/126] 6662830: OpenJDK build testing results
Small corrections in the README.
Reviewed-by: xdono
---
README-builds.html | 45 ++++++++++++++++++++-------------------------
1 file changed, 20 insertions(+), 25 deletions(-)
diff --git a/README-builds.html b/README-builds.html
index 6530865db54..096d192e2b9 100644
--- a/README-builds.html
+++ b/README-builds.html
@@ -342,32 +342,29 @@
- The source code for the
- OpenJDK is
- delivered in 3 sibling directories:
+ The source code for the OpenJDK is delivered in a set of
+ directories:
hotspot,
langtools,
corba,
jaxws,
jaxp,
- jdk
and
+ jdk.
The hotspot directory contains the source code and make
- files for
- building the
- OpenJDK
- Hotspot Virtual Machine.
- The jdk
- directory contains the source code and make files for
- building the
- OpenJDK
- runtime libraries, tools and demos.
- The top level Makefile is used to build the complete OpenJDK
- release including building the hotspot
- VM, staging the VM binaries, and building the
- OpenJDK
- runtime libraries,
- tools and demos.
+ files for building the OpenJDK Hotspot Virtual Machine.
+ The langtools directory contains the source code and make
+ files for building the OpenJDK javac and language tools.
+ The corba directory contains the source code and make
+ files for building the OpenJDK Corba files.
+ The jaxws directory contains the source code and make
+ files for building the OpenJDK JAXWS files.
+ The jaxp directory contains the source code and make
+ files for building the OpenJDK JAXP files.
+ The jdk directory contains the source code and make files for
+ building the OpenJDK runtime libraries and misc files.
+ The top level Makefile
+ is used to build the entire OpenJDK.
@@ -730,17 +727,15 @@
under an open-source license.
In order to build an OpenJDK binary from source code,
you must first download and install the appropriate
- binary plug bundles from the OpenJDK Download area.
+ binary plug bundles from the OpenJDK, go to the
+ OpenJDK site and select
+ the "Bundles(7)" link.
During the OpenJDK build process these "binary plugs"
for the encumbered components will be copied into your
resulting OpenJDK binary build image.
These binary plug files are only for the purpose of
building an OpenJDK binary.
- Download the Binary Plugs by selecting the Downloads
- link at
- the OpenJDK site,
- install the bundle,
- and make sure you set
+ Make sure you set
ALT_BINARY_PLUGS_PATH
to the root of this installation.
From 86d2ba8dfca2d85236a3a7f5d8d50f08b004749c Mon Sep 17 00:00:00 2001
From: Kumar Srinivasan
Date: Thu, 6 Mar 2008 07:51:28 -0800
Subject: [PATCH 033/126] 6596475: (launcher) javaw should call
InitCommonControls
Javaw does not show error window after manifest changes.
Reviewed-by: darcy
---
jdk/make/java/jli/Makefile | 1 +
jdk/make/java/main/java/Makefile | 2 +-
jdk/make/java/main/javaw/Makefile | 2 +-
jdk/src/share/bin/java.c | 4 +---
jdk/src/share/bin/java.h | 5 ++++-
jdk/src/share/bin/main.c | 2 --
jdk/src/solaris/bin/java_md.c | 12 ++++++------
jdk/src/windows/bin/java_md.c | 23 ++++++++++++++++++-----
8 files changed, 32 insertions(+), 19 deletions(-)
diff --git a/jdk/make/java/jli/Makefile b/jdk/make/java/jli/Makefile
index fb8868fd37d..236654fd4a9 100644
--- a/jdk/make/java/jli/Makefile
+++ b/jdk/make/java/jli/Makefile
@@ -107,6 +107,7 @@ endif # PLATFORM
ifeq ($(PLATFORM), windows)
EXTRA_LIBS = advapi32.lib \
+ comctl32.lib \
user32.lib
JAVALIB =
diff --git a/jdk/make/java/main/java/Makefile b/jdk/make/java/main/java/Makefile
index ad924f6663e..5c876294c98 100644
--- a/jdk/make/java/main/java/Makefile
+++ b/jdk/make/java/main/java/Makefile
@@ -43,7 +43,7 @@ include $(BUILDDIR)/common/Defs.gmk
# Override the default version info with our own resource file (see 5106536)
ifeq ($(PLATFORM), windows)
-LDLIBS_COMMON += user32.lib
+LDLIBS_COMMON += user32.lib comctl32.lib
ifdef OPENJDK
RC_FLAGS += -i "$(PLATFORM_SRC)/resource/icons"
else
diff --git a/jdk/make/java/main/javaw/Makefile b/jdk/make/java/main/javaw/Makefile
index 9afb5d0133d..1c03b23fab7 100644
--- a/jdk/make/java/main/javaw/Makefile
+++ b/jdk/make/java/main/javaw/Makefile
@@ -46,7 +46,7 @@ STATIC_JLI = true
include $(BUILDDIR)/common/Defs.gmk
OTHER_CPPFLAGS += -DJAVAW
-LDLIBS_COMMON += user32.lib
+LDLIBS_COMMON += user32.lib comctl32.lib
# Override the default version info with our own resource file (see 5106536)
ifeq ($(PLATFORM), windows)
diff --git a/jdk/src/share/bin/java.c b/jdk/src/share/bin/java.c
index 2e86de9a401..47c2fc17cd0 100644
--- a/jdk/src/share/bin/java.c
+++ b/jdk/src/share/bin/java.c
@@ -205,9 +205,7 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */
_wc_enabled = cpwildcard;
_ergo_policy = ergo;
- if (javaw == JNI_TRUE)
- SetJavaw();
-
+ InitLauncher(javaw);
DumpState();
/*
diff --git a/jdk/src/share/bin/java.h b/jdk/src/share/bin/java.h
index c86c5d107db..291b6755690 100644
--- a/jdk/src/share/bin/java.h
+++ b/jdk/src/share/bin/java.h
@@ -172,7 +172,6 @@ const char* GetDotVersion();
const char* GetFullVersion();
jboolean IsJavaArgs();
jboolean IsJavaw();
-void SetJavaw();
jint GetErgoPolicy();
jboolean ServerClassMachine();
@@ -180,5 +179,9 @@ jboolean ServerClassMachine();
static int ContinueInNewThread(InvocationFunctions* ifn, int argc, char** argv,
char* jarfile, char* classname, int ret);
+/*
+ * Initialize platform specific settings
+ */
+void InitLauncher(jboolean javaw);
#endif /* _JAVA_H_ */
diff --git a/jdk/src/share/bin/main.c b/jdk/src/share/bin/main.c
index 7052159f267..88d9190a555 100644
--- a/jdk/src/share/bin/main.c
+++ b/jdk/src/share/bin/main.c
@@ -64,8 +64,6 @@ main(int argc, char ** argv)
margv = argv;
#endif /* JAVAW */
- JLI_SetTraceLauncher();
-
return JLI_Launch(margc, margv,
sizeof(const_jargs) / sizeof(char *), const_jargs,
sizeof(const_appclasspath) / sizeof(char *), const_appclasspath,
diff --git a/jdk/src/solaris/bin/java_md.c b/jdk/src/solaris/bin/java_md.c
index 5d96c2780f0..74dd1a3ef8e 100644
--- a/jdk/src/solaris/bin/java_md.c
+++ b/jdk/src/solaris/bin/java_md.c
@@ -1299,12 +1299,6 @@ void SetJavaLauncherPlatformProps() {
AddOption(pid_prop_str, NULL);
#endif
}
-void
-SetJavaw()
-{
- /* noop on UNIX */
- return;
-}
jboolean
IsJavaw()
@@ -1312,3 +1306,9 @@ IsJavaw()
/* noop on UNIX */
return JNI_FALSE;
}
+
+void
+InitLauncher(jboolean javaw)
+{
+ JLI_SetTraceLauncher();
+}
diff --git a/jdk/src/windows/bin/java_md.c b/jdk/src/windows/bin/java_md.c
index 2e1c787838d..f252e0b1b38 100644
--- a/jdk/src/windows/bin/java_md.c
+++ b/jdk/src/windows/bin/java_md.c
@@ -33,6 +33,7 @@
#include
#include
#include
+#include
#include
#include "java.h"
@@ -52,11 +53,6 @@ static jboolean GetJREPath(char *path, jint pathsize);
static jboolean _isjavaw = JNI_FALSE;
-void
-SetJavaw()
-{
- _isjavaw = JNI_TRUE;
-}
jboolean
IsJavaw()
@@ -999,3 +995,20 @@ ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void
/* Linux only, empty on windows. */
void SetJavaLauncherPlatformProps() {}
+
+void
+InitLauncher(boolean javaw)
+{
+ INITCOMMONCONTROLSEX icx;
+
+ /*
+ * Required for javaw mode MessageBox output as well as for
+ * HotSpot -XX:+ShowMessageBoxOnError in java mode, an empty
+ * flag field is sufficient to perform the basic UI initialization.
+ */
+ memset(&icx, 0, sizeof(INITCOMMONCONTROLSEX));
+ icx.dwSize = sizeof(INITCOMMONCONTROLSEX);
+ InitCommonControlsEx(&icx);
+ _isjavaw = javaw;
+ JLI_SetTraceLauncher();
+}
From 9a2759ee8df8c88c9440000388611b6bc37b7890 Mon Sep 17 00:00:00 2001
From: Bradford Wetmore
Date: Thu, 6 Mar 2008 10:35:28 -0800
Subject: [PATCH 034/126] 6623830: SCCS cleanup has broken two regression tests
Reviewed-by: chegar
---
jdk/test/java/net/ResponseCache/file2.1 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jdk/test/java/net/ResponseCache/file2.1 b/jdk/test/java/net/ResponseCache/file2.1
index 428de11adaa..1878bc2fe88 100644
--- a/jdk/test/java/net/ResponseCache/file2.1
+++ b/jdk/test/java/net/ResponseCache/file2.1
@@ -1,4 +1,4 @@
-/* @test
+/* @test @(#)file2.1 1.1 03/08/09
* @summary Unit test for java.net.ResponseCacheHandler
* @bug 4837267
* @author Yingxian Wang
From 373ad3f1c5c9db94fc2abb2071b58e04bc7f0b62 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Thu, 6 Mar 2008 11:37:14 -0800
Subject: [PATCH 035/126] 6628146: Exclude the .hgignore and .hgtags files from
the source bundles
Just add to list of SCM files.
Reviewed-by: xdono
---
jdk/make/common/shared/Platform.gmk | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/jdk/make/common/shared/Platform.gmk b/jdk/make/common/shared/Platform.gmk
index 915454a940c..648dcbeb7d6 100644
--- a/jdk/make/common/shared/Platform.gmk
+++ b/jdk/make/common/shared/Platform.gmk
@@ -101,10 +101,10 @@ REQUIRED_FREETYPE_VERSION=2.3.0
# so they will not be included when copying directory trees
# or packaging up .jar files, etc. This applies to all workspaces.
#
-SCM_DIRs = .hg .svn CVS RCS SCCS Codemgr_wsdata deleted_files
+SCM_DIRs = .hg .svn CVS RCS SCCS Codemgr_wsdata deleted_files .hgignore .hgtags
# When changing SCM_DIRs also change SCM_DIRS_rexp and SCM_DIRS_prune:
-SCM_DIRS_rexp = ".hg|.svn|CVS|RCS|SCCS|Codemgr_wsdata|deleted_files"
-SCM_DIRS_prune = \( -name .hg -o -name .svn -o -name CVS -o -name RCS -o -name SCCS -o -name Codemgr_wsdata -o -name deleted_files \) -prune
+SCM_DIRS_rexp = ".hg|.svn|CVS|RCS|SCCS|Codemgr_wsdata|deleted_files|.hgignore|.hgtags"
+SCM_DIRS_prune = \( -name .hg -o -name .svn -o -name CVS -o -name RCS -o -name SCCS -o -name Codemgr_wsdata -o -name deleted_files -o -name .hgignore -o -name .hgtags \) -prune
# Don't define this unless it's not defined
ifndef VARIANT
From 2dae31e47ce2c9c4ee6e424881894bcbb647b771 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Thu, 6 Mar 2008 13:56:47 -0800
Subject: [PATCH 036/126] 6624808: corba makefiles not using langtools compiler
If supplied, the langtools javac should be used.
Reviewed-by: xdono
---
corba/make/common/shared/Defs.gmk | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/corba/make/common/shared/Defs.gmk b/corba/make/common/shared/Defs.gmk
index 8cd237fed51..c7832863e34 100644
--- a/corba/make/common/shared/Defs.gmk
+++ b/corba/make/common/shared/Defs.gmk
@@ -281,6 +281,13 @@ endif
# Get platform specific settings
include $(BUILDDIR)/common/shared/Defs-$(PLATFORM).gmk
+# Components
+ifdef ALT_LANGTOOLS_DIST
+ LANGTOOLS_DIST :=$(call FullPath,$(ALT_LANGTOOLS_DIST))
+else
+ LANGTOOLS_DIST =
+endif
+
# These are the same on all platforms but require the above platform include 1st
# BOOTDIR: Bootstrap JDK, previous released JDK.
From 623bcb71a54056435bbfadfa53edffc71dd207c8 Mon Sep 17 00:00:00 2001
From: Bradford Wetmore
Date: Thu, 6 Mar 2008 16:06:45 -0800
Subject: [PATCH 037/126] 6578538: com.sun.crypto.provider.SunJCE instance leak
using KRB5 and LoginContext
Reviewed-by: valeriep
---
.../sun/crypto/provider/PBKDF2KeyImpl.java | 8 ++-
.../provider/KeyFactory/TestProviderLeak.java | 72 +++++++++++++++++++
2 files changed, 79 insertions(+), 1 deletion(-)
create mode 100644 jdk/test/com/sun/crypto/provider/KeyFactory/TestProviderLeak.java
diff --git a/jdk/src/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java b/jdk/src/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java
index afb9b3e94a5..ee5ed5a9229 100644
--- a/jdk/src/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java
+++ b/jdk/src/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java
@@ -34,6 +34,7 @@ import java.security.KeyRep;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
@@ -107,12 +108,17 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
throw new InvalidKeySpecException("Key length is negative");
}
try {
- this.prf = Mac.getInstance(prfAlgo, new SunJCE());
+ this.prf = Mac.getInstance(prfAlgo, "SunJCE");
} catch (NoSuchAlgorithmException nsae) {
// not gonna happen; re-throw just in case
InvalidKeySpecException ike = new InvalidKeySpecException();
ike.initCause(nsae);
throw ike;
+ } catch (NoSuchProviderException nspe) {
+ // Again, not gonna happen; re-throw just in case
+ InvalidKeySpecException ike = new InvalidKeySpecException();
+ ike.initCause(nspe);
+ throw ike;
}
this.key = deriveKey(prf, passwdBytes, salt, iterCount, keyLength);
}
diff --git a/jdk/test/com/sun/crypto/provider/KeyFactory/TestProviderLeak.java b/jdk/test/com/sun/crypto/provider/KeyFactory/TestProviderLeak.java
new file mode 100644
index 00000000000..6fe480cb6e0
--- /dev/null
+++ b/jdk/test/com/sun/crypto/provider/KeyFactory/TestProviderLeak.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6578538
+ * @summary com.sun.crypto.provider.SunJCE instance leak using KRB5 and
+ * LoginContext
+ * @author Brad Wetmore
+ *
+ * @run main/othervm -Xmx2m TestProviderLeak
+ */
+
+/*
+ * We force the leak to become a problem by specifying the minimum
+ * size heap we can (above). In current runs on a server and client
+ * machine, it took roughly 220-240 iterations to have the memory leak
+ * shut down other operations. It complained about "Unable to verify
+ * the SunJCE provider."
+ */
+
+import javax.crypto.*;
+import javax.crypto.spec.*;
+
+public class TestProviderLeak {
+ private static void dumpMemoryStats(String s) throws Exception {
+ Runtime rt = Runtime.getRuntime();
+ System.out.println(s + ":\t" +
+ rt.freeMemory() + " bytes free");
+ }
+
+ public static void main(String [] args) throws Exception {
+ SecretKeyFactory skf =
+ SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1", "SunJCE");
+ PBEKeySpec pbeKS = new PBEKeySpec(
+ "passPhrase".toCharArray(), new byte [] { 0 }, 5, 512);
+ for (int i = 0; i <= 1000; i++) {
+ try {
+ skf.generateSecret(pbeKS);
+ if ((i % 20) == 0) {
+ // Calling gc() isn't dependable, but doesn't hurt.
+ // Gives better output in leak cases.
+ System.gc();
+ dumpMemoryStats("Iteration " + i);
+ }
+ } catch (Exception e) {
+ dumpMemoryStats("\nException seen at iteration " + i);
+ throw e;
+ }
+ }
+ }
+}
From b02a978ac4384851d1b1c2dc4533da845aeda427 Mon Sep 17 00:00:00 2001
From: Chris Hegarty
Date: Fri, 7 Mar 2008 09:57:22 +0000
Subject: [PATCH 038/126] 6667108: typo in javadoc for
java.net.Socket.getRemoteSocketAddress()
Simple typo in method specification.
Reviewed-by: jccollet
---
jdk/src/share/classes/java/net/Socket.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jdk/src/share/classes/java/net/Socket.java b/jdk/src/share/classes/java/net/Socket.java
index c02dd4e2855..478bece1577 100644
--- a/jdk/src/share/classes/java/net/Socket.java
+++ b/jdk/src/share/classes/java/net/Socket.java
@@ -731,7 +731,7 @@ class Socket implements java.io.Closeable {
* then this method will continue to return the connected address
* after the socket is closed.
*
- * @return a SocketAddress reprensenting the remote endpoint of this
+ * @return a SocketAddress representing the remote endpoint of this
* socket, or null if it is not connected yet.
* @see #getInetAddress()
* @see #getPort()
From b8383dba86319e0ce71af09484c5b6fd2321c4dc Mon Sep 17 00:00:00 2001
From: Chris Hegarty
Date: Fri, 7 Mar 2008 11:30:32 +0000
Subject: [PATCH 039/126] 6615656: Removed unimplemented java.net methods
Reviewed-by: jccollet
---
jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java | 1 -
jdk/src/share/classes/java/net/NetworkInterface.java | 2 --
jdk/src/solaris/classes/java/net/PlainSocketImpl.java | 3 ---
jdk/src/windows/classes/java/net/DualStackPlainSocketImpl.java | 3 ---
jdk/src/windows/classes/java/net/TwoStacksPlainSocketImpl.java | 3 ---
5 files changed, 12 deletions(-)
diff --git a/jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java b/jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java
index ffc23824b61..41c39f0e15f 100644
--- a/jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java
+++ b/jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java
@@ -664,7 +664,6 @@ abstract class AbstractPlainSocketImpl extends SocketImpl
abstract void socketSetOption(int cmd, boolean on, Object value)
throws SocketException;
abstract int socketGetOption(int opt, Object iaContainerObj) throws SocketException;
- abstract int socketGetOption1(int opt, Object iaContainerObj, FileDescriptor fd) throws SocketException;
abstract void socketSendUrgentData(int data)
throws IOException;
diff --git a/jdk/src/share/classes/java/net/NetworkInterface.java b/jdk/src/share/classes/java/net/NetworkInterface.java
index 8b2899c48d9..0ce3a8d580b 100644
--- a/jdk/src/share/classes/java/net/NetworkInterface.java
+++ b/jdk/src/share/classes/java/net/NetworkInterface.java
@@ -425,8 +425,6 @@ public final class NetworkInterface {
return virtual;
}
- private native static long getSubnet0(String name, int ind) throws SocketException;
- private native static Inet4Address getBroadcast0(String name, int ind) throws SocketException;
private native static boolean isUp0(String name, int ind) throws SocketException;
private native static boolean isLoopback0(String name, int ind) throws SocketException;
private native static boolean supportsMulticast0(String name, int ind) throws SocketException;
diff --git a/jdk/src/solaris/classes/java/net/PlainSocketImpl.java b/jdk/src/solaris/classes/java/net/PlainSocketImpl.java
index 113bcb0183e..25e2bab81f5 100644
--- a/jdk/src/solaris/classes/java/net/PlainSocketImpl.java
+++ b/jdk/src/solaris/classes/java/net/PlainSocketImpl.java
@@ -76,9 +76,6 @@ class PlainSocketImpl extends AbstractPlainSocketImpl
native int socketGetOption(int opt, Object iaContainerObj) throws SocketException;
- native int socketGetOption1(int opt, Object iaContainerObj, FileDescriptor fd)
- throws SocketException;
-
native void socketSendUrgentData(int data) throws IOException;
}
diff --git a/jdk/src/windows/classes/java/net/DualStackPlainSocketImpl.java b/jdk/src/windows/classes/java/net/DualStackPlainSocketImpl.java
index 116046603f8..4e92df7f687 100644
--- a/jdk/src/windows/classes/java/net/DualStackPlainSocketImpl.java
+++ b/jdk/src/windows/classes/java/net/DualStackPlainSocketImpl.java
@@ -218,9 +218,6 @@ class DualStackPlainSocketImpl extends AbstractPlainSocketImpl
return value;
}
- int socketGetOption1(int opt, Object iaContainerObj, FileDescriptor fd)
- throws SocketException {return 0;} // un-implemented REMOVE
-
void socketSendUrgentData(int data) throws IOException {
int nativefd = checkAndReturnNativeFD();
sendOOB(nativefd, data);
diff --git a/jdk/src/windows/classes/java/net/TwoStacksPlainSocketImpl.java b/jdk/src/windows/classes/java/net/TwoStacksPlainSocketImpl.java
index 9475bd3f7a1..13851124b32 100644
--- a/jdk/src/windows/classes/java/net/TwoStacksPlainSocketImpl.java
+++ b/jdk/src/windows/classes/java/net/TwoStacksPlainSocketImpl.java
@@ -199,8 +199,5 @@ class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl
native int socketGetOption(int opt, Object iaContainerObj) throws SocketException;
- native int socketGetOption1(int opt, Object iaContainerObj, FileDescriptor fd)
- throws SocketException;
-
native void socketSendUrgentData(int data) throws IOException;
}
From 1b9d87730f2e79cbd91cabad4fdc2281b47d99b8 Mon Sep 17 00:00:00 2001
From: Chris Hegarty
Date: Fri, 7 Mar 2008 11:51:27 +0000
Subject: [PATCH 040/126] 6591358: documentation error in
URLConnection.setRequestProperty("accept", ...)
Simple doc change, "accept" -> "Accept"
Reviewed-by: jccollet
---
jdk/src/share/classes/java/net/URLConnection.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/jdk/src/share/classes/java/net/URLConnection.java b/jdk/src/share/classes/java/net/URLConnection.java
index c1236bd3a63..a78032a2fcc 100644
--- a/jdk/src/share/classes/java/net/URLConnection.java
+++ b/jdk/src/share/classes/java/net/URLConnection.java
@@ -1072,7 +1072,7 @@ public abstract class URLConnection {
* properties to be appended into a single property.
*
* @param key the keyword by which the request is known
- * (e.g., "accept").
+ * (e.g., "Accept").
* @param value the value associated with it.
* @throws IllegalStateException if already connected
* @throws NullPointerException if key is null
@@ -1096,7 +1096,7 @@ public abstract class URLConnection {
* existing values associated with the same key.
*
* @param key the keyword by which the request is known
- * (e.g., "accept").
+ * (e.g., "Accept").
* @param value the value associated with it.
* @throws IllegalStateException if already connected
* @throws NullPointerException if key is null
@@ -1120,7 +1120,7 @@ public abstract class URLConnection {
* Returns the value of the named general request property for this
* connection.
*
- * @param key the keyword by which the request is known (e.g., "accept").
+ * @param key the keyword by which the request is known (e.g., "Accept").
* @return the value of the named general request property for this
* connection. If key is null, then null is returned.
* @throws IllegalStateException if already connected
@@ -1164,7 +1164,7 @@ public abstract class URLConnection {
* these properties.
*
* @param key the keyword by which the request is known
- * (e.g., "accept").
+ * (e.g., "Accept").
* @param value the value associated with the key.
*
* @see java.net.URLConnection#setRequestProperty(java.lang.String,java.lang.String)
@@ -1183,7 +1183,7 @@ public abstract class URLConnection {
* Returns the value of the default request property. Default request
* properties are set for every connection.
*
- * @param key the keyword by which the request is known (e.g., "accept").
+ * @param key the keyword by which the request is known (e.g., "Accept").
* @return the value of the default request property
* for the specified key.
*
From 349fef2b701708d3aa218d67e246fdcb22d07924 Mon Sep 17 00:00:00 2001
From: Chris Hegarty
Date: Fri, 7 Mar 2008 13:00:44 +0000
Subject: [PATCH 041/126] 6628576: InterfaceAddress.equals() NPE when broadcast
field == null
Update logic in equals to correctly handle nulls.
Reviewed-by: michaelm
---
.../classes/java/net/InterfaceAddress.java | 6 +-
.../java/net/InterfaceAddress/Equals.java | 119 ++++++++++++++++++
2 files changed, 121 insertions(+), 4 deletions(-)
create mode 100644 jdk/test/java/net/InterfaceAddress/Equals.java
diff --git a/jdk/src/share/classes/java/net/InterfaceAddress.java b/jdk/src/share/classes/java/net/InterfaceAddress.java
index e352c35f80b..66a65358cbc 100644
--- a/jdk/src/share/classes/java/net/InterfaceAddress.java
+++ b/jdk/src/share/classes/java/net/InterfaceAddress.java
@@ -103,11 +103,9 @@ public class InterfaceAddress {
return false;
}
InterfaceAddress cmp = (InterfaceAddress) obj;
- if ((address != null & cmp.address == null) ||
- (!address.equals(cmp.address)))
+ if ( !(address == null ? cmp.address == null : address.equals(cmp.address)) )
return false;
- if ((broadcast != null & cmp.broadcast == null) ||
- (!broadcast.equals(cmp.broadcast)))
+ if ( !(broadcast == null ? cmp.broadcast == null : broadcast.equals(cmp.broadcast)) )
return false;
if (maskLength != cmp.maskLength)
return false;
diff --git a/jdk/test/java/net/InterfaceAddress/Equals.java b/jdk/test/java/net/InterfaceAddress/Equals.java
new file mode 100644
index 00000000000..5403bebe04c
--- /dev/null
+++ b/jdk/test/java/net/InterfaceAddress/Equals.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 6628576
+ * @summary InterfaceAddress.equals() NPE when broadcast field == null
+ */
+
+import java.net.InterfaceAddress;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+
+public class Equals
+{
+ public static void main(String[] args) {
+ InterfaceAddress ia1;
+ InterfaceAddress ia2;
+ InetAddress loopbackAddr = InetAddress.getLoopbackAddress();
+ InetAddress broadcast1 = null;
+ InetAddress broadcast2 = null;
+
+ try {
+ broadcast1 = InetAddress.getByName("255.255.255.0");
+ broadcast2 = InetAddress.getByName("255.255.0.0");
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ }
+
+ ia1 = createInterfaceAddress(loopbackAddr, (InetAddress) null, (short)45);
+ ia2 = createInterfaceAddress(loopbackAddr, (InetAddress) null, (short)45);
+
+ compare(ia1, ia2, true);
+
+ ia2 = createInterfaceAddress(loopbackAddr, broadcast1, (short)45);
+ compare(ia1, ia2, false);
+
+ ia2 = createInterfaceAddress((InetAddress)null, broadcast1, (short)45);
+ compare(ia1, ia2, false);
+
+ ia1 = createInterfaceAddress(loopbackAddr, broadcast2, (short)45);
+ ia2 = createInterfaceAddress(loopbackAddr, broadcast2, (short)45);
+ compare(ia1, ia2, true);
+
+ ia1.equals(null);
+ }
+
+ static void compare(InterfaceAddress ia1, InterfaceAddress ia2, boolean equal) {
+ if (ia1.equals(ia2) != equal)
+ throw new RuntimeException("Failed: " + ia1 + " not equals to " + ia2);
+
+ if (ia2.equals(ia1) != equal)
+ throw new RuntimeException("Failed: " + ia2 + " not equals to " + ia1);
+ }
+
+ /**
+ * Returns an InterfaceAddress instance with its fields set the the values
+ * specificed.
+ */
+ static InterfaceAddress createInterfaceAddress(
+ InetAddress address, InetAddress broadcast, short prefixlength) {
+ try {
+ Class IAClass = InterfaceAddress.class;
+ InterfaceAddress ia;
+ Constructor ctr = IAClass.getDeclaredConstructor();
+ ctr.setAccessible(true);
+
+ Field addressField = IAClass.getDeclaredField("address");
+ addressField.setAccessible(true);
+
+ Field broadcastField = IAClass.getDeclaredField("broadcast");
+ broadcastField.setAccessible(true);
+
+ Field maskLengthField = IAClass.getDeclaredField("maskLength");
+ maskLengthField.setAccessible(true);
+
+ ia = ctr.newInstance();
+ addressField.set(ia, address);
+ broadcastField.set(ia, broadcast);
+ maskLengthField.setShort(ia, prefixlength);
+
+ return ia;
+ } catch (NoSuchFieldException nsfe) {
+ nsfe.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ } catch (InstantiationException ie) {
+ ie.printStackTrace();
+ } catch (IllegalAccessException iae) {
+ iae.printStackTrace();
+ } catch (InvocationTargetException ite) {
+ ite.printStackTrace();
+ }
+
+ return null;
+ }
+}
From afd3b1f4ba2113f1e2a5f5d503f3451880605669 Mon Sep 17 00:00:00 2001
From: Chris Hegarty
Date: Fri, 7 Mar 2008 15:15:54 +0000
Subject: [PATCH 042/126] 6672682: Forgotten file from CR 6615656
Reviewed-by: michaelm
---
jdk/src/windows/classes/java/net/PlainSocketImpl.java | 5 -----
1 file changed, 5 deletions(-)
diff --git a/jdk/src/windows/classes/java/net/PlainSocketImpl.java b/jdk/src/windows/classes/java/net/PlainSocketImpl.java
index c65c71c670f..cde60b53087 100644
--- a/jdk/src/windows/classes/java/net/PlainSocketImpl.java
+++ b/jdk/src/windows/classes/java/net/PlainSocketImpl.java
@@ -304,11 +304,6 @@ class PlainSocketImpl extends AbstractPlainSocketImpl
return impl.socketGetOption(opt, iaContainerObj);
}
- int socketGetOption1(int opt, Object iaContainerObj, FileDescriptor fd)
- throws SocketException {
- return impl.socketGetOption1(opt, iaContainerObj, fd);
- }
-
void socketSendUrgentData(int data) throws IOException {
impl.socketSendUrgentData(data);
}
From 950ab581668ed5c5cdb6c60ad27393e6c11fdef3 Mon Sep 17 00:00:00 2001
From: Chris Hegarty
Date: Fri, 7 Mar 2008 07:25:17 -0800
Subject: [PATCH 043/126] 6628661: NTLM-authentication doesn't work with
non-ASCII letters
Use JNU_GetStringPlatformChars to convert jstrings to the locale specific native C strings
Reviewed-by: michaelm
---
.../net/www/protocol/http/NTLMAuthSequence.c | 37 +++++++++++++++----
1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c b/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c
index 4d4e56ee807..580e2fabadb 100644
--- a/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c
+++ b/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c
@@ -36,6 +36,8 @@
#include
#include
+#include "jni_util.h"
+
#define SECURITY_WIN32
#include "sspi.h"
#include "issperr.h"
@@ -117,22 +119,36 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_getCrede
{
SEC_WINNT_AUTH_IDENTITY AuthId;
SEC_WINNT_AUTH_IDENTITY * pAuthId;
- CHAR *pUser = 0;
- CHAR *pDomain = 0;
- CHAR *pPassword = 0;
+ const CHAR *pUser = 0;
+ const CHAR *pDomain = 0;
+ const CHAR *pPassword = 0;
CredHandle *pCred;
TimeStamp ltime;
jboolean isCopy;
SECURITY_STATUS ss;
if (user != 0) {
- pUser = (CHAR *)(*env)->GetStringUTFChars(env, user, &isCopy);
+ pUser = JNU_GetStringPlatformChars(env, user, &isCopy);
+ if (pUser == NULL)
+ return 0; // pending Exception
}
if (domain != 0) {
- pDomain = (CHAR *)(*env)->GetStringUTFChars(env, domain, &isCopy);
+ pDomain = JNU_GetStringPlatformChars(env, domain, &isCopy);
+ if (pDomain == NULL) {
+ if (pUser != NULL)
+ JNU_ReleaseStringPlatformChars(env, user, pUser);
+ return 0; // pending Exception
+ }
}
if (password != 0) {
- pPassword = (CHAR *)(*env)->GetStringUTFChars(env, password, &isCopy);
+ pPassword = JNU_GetStringPlatformChars(env, password, &isCopy);
+ if (pPassword == NULL) {
+ if(pUser != NULL)
+ JNU_ReleaseStringPlatformChars(env, user, pUser);
+ if(pDomain != NULL)
+ JNU_ReleaseStringPlatformChars(env, domain, pDomain);
+ return 0; // pending Exception
+ }
}
pCred = (CredHandle *)malloc(sizeof (CredHandle));
@@ -167,6 +183,14 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_getCrede
pCred, <ime
);
+ /* Release resources held by JNU_GetStringPlatformChars */
+ if (pUser != NULL)
+ JNU_ReleaseStringPlatformChars(env, user, pUser);
+ if (pPassword != NULL)
+ JNU_ReleaseStringPlatformChars(env, password, pPassword);
+ if (pDomain != NULL)
+ JNU_ReleaseStringPlatformChars(env, domain, pDomain);
+
if (ss == 0) {
return (jlong) pCred;
} else {
@@ -181,7 +205,6 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_get
VOID *pInput = 0;
DWORD inputLen;
CHAR buffOut[512];
- DWORD pcbBuffOut;
jboolean isCopy;
SECURITY_STATUS ss;
SecBufferDesc OutBuffDesc;
From 077f55f47081da77b51683fabd05d00f0eebcb58 Mon Sep 17 00:00:00 2001
From: Chris Hegarty
Date: Fri, 7 Mar 2008 17:17:49 +0000
Subject: [PATCH 044/126] 6631048: Problem when writing on output stream of
HttpURLConnection
Fix up logic in ChunkedOutputStream.write
Reviewed-by: jccollet
---
.../sun/net/www/http/ChunkedOutputStream.java | 13 ++-
.../www/http/ChunkedOutputStream/Test.java | 98 ++++++++++++++++++-
2 files changed, 108 insertions(+), 3 deletions(-)
diff --git a/jdk/src/share/classes/sun/net/www/http/ChunkedOutputStream.java b/jdk/src/share/classes/sun/net/www/http/ChunkedOutputStream.java
index a06b5afe228..5f4a7902f62 100644
--- a/jdk/src/share/classes/sun/net/www/http/ChunkedOutputStream.java
+++ b/jdk/src/share/classes/sun/net/www/http/ChunkedOutputStream.java
@@ -177,14 +177,23 @@ public class ChunkedOutputStream extends PrintStream {
return;
}
- if (len > MAX_BUF_SIZE) {
+ int l = preferredChunkSize - count;
+
+ if ((len > MAX_BUF_SIZE) && (len > l)) {
+ /* current chunk is empty just write the data */
+ if (count == 0) {
+ count = len;
+ flush (b, false, off);
+ return;
+ }
+
/* first finish the current chunk */
- int l = preferredChunkSize - count;
if (l > 0) {
System.arraycopy(b, off, buf, count, l);
count = preferredChunkSize;
flush(buf, false);
}
+
count = len - l;
/* Now write the rest of the data */
flush (b, false, l+off);
diff --git a/jdk/test/sun/net/www/http/ChunkedOutputStream/Test.java b/jdk/test/sun/net/www/http/ChunkedOutputStream/Test.java
index 89bc8b3bf85..3866761ade6 100644
--- a/jdk/test/sun/net/www/http/ChunkedOutputStream/Test.java
+++ b/jdk/test/sun/net/www/http/ChunkedOutputStream/Test.java
@@ -23,7 +23,7 @@
/**
* @test
- * @bug 5026745
+ * @bug 5026745 6631048
* @run main/othervm/timeout=500 Test
* @summary Cannot flush output stream when writing to an HttpUrlConnection
*/
@@ -158,6 +158,50 @@ public class Test implements HttpHandler {
exchange.sendResponseHeaders(200, 0);
}
break;
+ case 10: /* test11 */
+ printRequestURI(exchange);
+ is = exchange.getRequestBody();
+ s = read (is, str1.length());
+
+ error = false;
+ for (int i=10; i< 30 * 1024; i++) {
+ byte c = (byte)is.read();
+
+ if (c != (byte)i) {
+ error = true;
+ System.out.println ("error at position " + i);
+ }
+ }
+ if (!s.equals(str1) ) {
+ System.out.println ("received string : " + s);
+ exchange.sendResponseHeaders(500, 0);
+ } else if (error) {
+ System.out.println ("error");
+ exchange.sendResponseHeaders(500, 0);
+ } else {
+ exchange.sendResponseHeaders(200, 0);
+ }
+ break;
+ case 11: /* test12 */
+ printRequestURI(exchange);
+ is = exchange.getRequestBody();
+
+ error = false;
+ for (int i=10; i< 30 * 1024; i++) {
+ byte c = (byte)is.read();
+
+ if (c != (byte)i) {
+ error = true;
+ System.out.println ("error at position " + i);
+ }
+ }
+ if (error) {
+ System.out.println ("error");
+ exchange.sendResponseHeaders(500, 0);
+ } else {
+ exchange.sendResponseHeaders(200, 0);
+ }
+ break;
}
exchange.close();
count ++;
@@ -390,6 +434,56 @@ public class Test implements HttpHandler {
}
}
+ static void test11 (String u) throws Exception {
+ URL url = new URL (u);
+ System.out.println ("client opening connection to: " + u);
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ urlc.setChunkedStreamingMode (36 * 1024);
+ urlc.setDoOutput(true);
+ urlc.setRequestMethod ("POST");
+ OutputStream os = urlc.getOutputStream ();
+ byte[] buf = new byte [30 * 1024];
+ for (int i=0; i< 30 * 1024; i++) {
+ buf[i] = (byte) i;
+ }
+ /* write a small bit first, and then the large buffer */
+ os.write (str1.getBytes());
+ //os.write (buf, 10, buf.length - 10); /* skip 10 bytes to test offset */
+ os.write (buf, 10, (10 * 1024) - 10);
+ os.write (buf, (10 * 1024), (10 * 1024));
+ os.write (buf, (20 * 1024), (10 * 1024));
+ os.close();
+ InputStream is = urlc.getInputStream();
+ is.close();
+ int ret = urlc.getResponseCode();
+ if (ret != 200) {
+ throw new Exception ("Expected 200: got " + ret);
+ }
+ }
+
+ static void test12 (String u) throws Exception {
+ URL url = new URL (u);
+ System.out.println ("client opening connection to: " + u);
+ HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
+ urlc.setChunkedStreamingMode (36 * 1024);
+ urlc.setDoOutput(true);
+ urlc.setRequestMethod ("POST");
+ OutputStream os = urlc.getOutputStream ();
+ byte[] buf = new byte [30 * 1024];
+ for (int i=0; i< 30 * 1024; i++) {
+ buf[i] = (byte) i;
+ }
+ os.write (buf, 10, buf.length - 10); /* skip 10 bytes to test offset */
+ os.close();
+ InputStream is = urlc.getInputStream();
+ is.close();
+ int ret = urlc.getResponseCode();
+ if (ret != 200) {
+ throw new Exception ("Expected 200: got " + ret);
+ }
+ }
+
+
static com.sun.net.httpserver.HttpServer httpserver;
public static void main (String[] args) throws Exception {
@@ -411,6 +505,8 @@ public class Test implements HttpHandler {
test8("http://localhost:"+ port + "/test/test8");
test9("http://localhost:"+ port + "/test/test9");
test10("http://localhost:"+ port + "/test/test10");
+ test11("http://localhost:"+ port + "/test/test11");
+ test12("http://localhost:"+ port + "/test/test12");
} finally {
if (httpserver != null)
httpserver.stop(0);
From b85d2a9e765a46729527990ad434068459821d09 Mon Sep 17 00:00:00 2001
From: Weijun Wang
Date: Sat, 8 Mar 2008 22:49:45 +0800
Subject: [PATCH 045/126] 6634644: broken fragment, should use @link
Reviewed-by: mullan
---
.../classes/javax/security/cert/X509Certificate.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/jdk/src/share/classes/javax/security/cert/X509Certificate.java b/jdk/src/share/classes/javax/security/cert/X509Certificate.java
index e5849e5c520..14ccaffaffd 100644
--- a/jdk/src/share/classes/javax/security/cert/X509Certificate.java
+++ b/jdk/src/share/classes/javax/security/cert/X509Certificate.java
@@ -363,7 +363,7 @@ public abstract class X509Certificate extends Certificate {
* subject Name
*
*
- * See getIssuerDN for Name
+ *
See {@link #getIssuerDN() getIssuerDN} for Name
* and other relevant definitions.
*
* @return a Principal whose name is the subject name.
@@ -393,7 +393,7 @@ public abstract class X509Certificate extends Certificate {
/**
* Gets the notAfter date from the validity period of
- * the certificate. See getNotBefore
+ * the certificate. See {@link #getNotBefore() getNotBefore}
* for relevant ASN.1 definitions.
*
* @return the end date of the validity period.
@@ -429,7 +429,7 @@ public abstract class X509Certificate extends Certificate {
* For example, the string "1.2.840.10040.4.3" identifies the SHA-1
* with DSA signature algorithm, as per the PKIX part I.
*
- *
See getSigAlgName for
+ *
See {@link #getSigAlgName() getSigAlgName} for
* relevant ASN.1 definitions.
*
* @return the signature algorithm OID string.
@@ -442,7 +442,7 @@ public abstract class X509Certificate extends Certificate {
* algorithm parameters are null; the parameters are usually
* supplied with the certificate's public key.
*
- *
See getSigAlgName for
+ *
See {@link #getSigAlgName() getSigAlgName} for
* relevant ASN.1 definitions.
*
* @return the DER-encoded signature algorithm parameters, or
From e75aa5c3abdc26625cfb45cb4bab48f34cc9c9df Mon Sep 17 00:00:00 2001
From: Weijun Wang
Date: Sat, 8 Mar 2008 22:51:14 +0800
Subject: [PATCH 046/126] 6643094: Test on keytool -startdate forgets about
December
Reviewed-by: xuelei
---
jdk/test/sun/security/tools/keytool/StartDateTest.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/jdk/test/sun/security/tools/keytool/StartDateTest.java b/jdk/test/sun/security/tools/keytool/StartDateTest.java
index 4c47ad724b8..7e3e5bad103 100644
--- a/jdk/test/sun/security/tools/keytool/StartDateTest.java
+++ b/jdk/test/sun/security/tools/keytool/StartDateTest.java
@@ -52,15 +52,15 @@ public class StartDateTest {
cal.setTime(getIssueDate());
System.out.println(cal);
if (cal.get(Calendar.YEAR) != year + 1) {
- throw new Exception("Function #1 check fails");
+ throw new Exception("Function check #1 fails");
}
run("-keystore jks -storetype jks -storepass changeit -keypass changeit -alias me " +
"-selfcert -startdate +1m");
cal.setTime(getIssueDate());
System.out.println(cal);
- if (cal.get(Calendar.MONTH) != month + 1) {
- throw new Exception("Function #1 check fails");
+ if (cal.get(Calendar.MONTH) != (month + 1) % 12) {
+ throw new Exception("Function check #2 fails");
}
new File("jks").delete();
From 095647f3a47ffd6f83493645ee96d9fb8ed76488 Mon Sep 17 00:00:00 2001
From: Weijun Wang
Date: Sat, 8 Mar 2008 22:52:20 +0800
Subject: [PATCH 047/126] 6597349: KeyStore.getCertificateChain() may not
return the full chain
Reviewed-by: mullan
---
jdk/src/share/classes/java/security/KeyStore.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jdk/src/share/classes/java/security/KeyStore.java b/jdk/src/share/classes/java/security/KeyStore.java
index f19a231bfbd..ced20e27446 100644
--- a/jdk/src/share/classes/java/security/KeyStore.java
+++ b/jdk/src/share/classes/java/security/KeyStore.java
@@ -789,7 +789,7 @@ public class KeyStore {
* @param alias the alias name
*
* @return the certificate chain (ordered with the user's certificate first
- * and the root certificate authority last), or null if the given alias
+ * followed by zero or more certificate authorities), or null if the given alias
* does not exist or does not contain a certificate chain
*
* @exception KeyStoreException if the keystore has not been initialized
From 6b9d629f069faeb157e3594dd0754cca466a6a98 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Sun, 9 Mar 2008 13:11:51 -0700
Subject: [PATCH 048/126] 6649270: Change by-default openjdk building in
control/make/makefile to use open source tree
Change build rules to allow for openjdk builds by default when building the closed or production build.
Reviewed-by: xdono
---
Makefile | 115 ++++++++++++++++++++++++++++-------------
make/Defs-internal.gmk | 2 -
2 files changed, 80 insertions(+), 37 deletions(-)
diff --git a/Makefile b/Makefile
index 5e06900266b..3ced65f0e31 100644
--- a/Makefile
+++ b/Makefile
@@ -42,6 +42,17 @@ ifndef CONTROL_TOPDIR
fi)
endif
+# Openjdk sources (only used if SKIP_OPENJDK_BUILD!=true)
+OPENJDK_SOURCETREE=$(TOPDIR)/openjdk
+OPENJDK_BUILDDIR:=$(shell \
+ if [ -r $(OPENJDK_SOURCETREE)/control/make/Makefile ]; then \
+ echo "$(OPENJDK_SOURCETREE)/control/make"; \
+ elif [ -r $(OPENJDK_SOURCETREE)/Makefile ]; then \
+ echo "$(OPENJDK_SOURCETREE)"; \
+ else \
+ echo "."; \
+ fi)
+
ifndef JDK_TOPDIR
JDK_TOPDIR=$(TOPDIR)/jdk
endif
@@ -81,12 +92,28 @@ include ./make/deploy-rules.gmk
all:: setup build
-setup:
+setup: openjdk_check
$(MKDIR) -p $(OUTPUTDIR)/j2sdk-image
$(MKDIR) -p $(ABS_OUTPUTDIR)/j2sdk-image
$(MKDIR) -p $(OUTPUTDIR)-fastdebug/j2sdk-image
$(MKDIR) -p $(ABS_OUTPUTDIR)-fastdebug/j2sdk-image
+# Check on whether we really can build the openjdk, need source etc.
+openjdk_check:
+ifneq ($(SKIP_OPENJDK_BUILD), true)
+ @$(ECHO) " "
+ @$(ECHO) "================================================="
+ @if [ ! -r $(OPENJDK_BUILDDIR)/Makefile ] ; then \
+ $(ECHO) "ERROR: No openjdk source tree available at: $(OPENJDK_BUILDDIR)"; \
+ exit 1; \
+ else \
+ $(ECHO) "OpenJDK will be built after JDK is built"; \
+ $(ECHO) " OPENJDK_BUILDDIR=$(OPENJDK_BUILDDIR)"; \
+ fi
+ @$(ECHO) "================================================="
+ @$(ECHO) " "
+endif
+
build:: sanity
clobber::
@@ -190,46 +217,64 @@ ifneq ($(SKIP_COMPARE_IMAGES), true)
all :: compare-image
endif
-ifeq ($(SKIP_OPENJDK_BUILD), false)
+ifneq ($(SKIP_OPENJDK_BUILD), true)
+ all :: openjdk_build
+endif
+
+# If we have bundle rules, we have a chance here to do a complete cycle
+# build, of production and open build.
+# FIXUP: We should create the openjdk source bundle and build that?
+# But how do we reliable create or get at a formal openjdk source tree?
+# The one we have needs to be trimmed of built bits and closed dirs.
+# The repositories might not be available.
+# The openjdk source bundle is probably not available.
+
+ifneq ($(SKIP_OPENJDK_BUILD), true)
ifeq ($(BUILD_JDK), true)
ifeq ($(BUNDLE_RULES_AVAILABLE), true)
- # If we have bundle rules, we have a chance here to do a complete cycle
- # build, of closed and open build.
- # FIXUP: We should create the openjdk source bundle and build that?
- ABS_OPENJDK_PLUGS=$(ABS_OUTPUTDIR)/$(OPENJDK_BINARY_PLUGS_INAME)
- ABS_OPENJDK_OUTPUTDIR=$(ABS_OUTPUTDIR)/openjdk
- OPENJDK_BUILD_NAME_PREFIX \
- = $(J2SDK_NAME)-$(JDK_MKTG_UNDERSCORE_VERSION)-$(MILESTONE)
- OPENJDK_BUILD_NAME_SUFFIX \
- = $(BUILD_NUMBER)-$(PLATFORM)-$(ARCH)-$(BUNDLE_DATE)
- OPENJDK_BUILD_NAME \
- = $(OPENJDK_BUILD_NAME_PREFIX)-openjdk-$(OPENJDK_BUILD_NAME_SUFFIX)
- OPENJDK_BUILD_BINARY_ZIP \
- = $(ABS_BIN_BUNDLEDIR)/$(OPENJDK_BUILD_NAME).zip
- all :: openjdk-build
- openjdk-build:
+
+OPENJDK_PLUGS=$(ABS_OUTPUTDIR)/$(OPENJDK_BINARY_PLUGS_INAME)
+OPENJDK_OUTPUTDIR=$(ABS_OUTPUTDIR)/open-output
+OPENJDK_BUILD_NAME \
+ = openjdk-$(JDK_MINOR_VERSION)-$(BUILD_NUMBER)-$(PLATFORM)-$(ARCH)-$(BUNDLE_DATE)
+OPENJDK_BUILD_BINARY_ZIP=$(ABS_BIN_BUNDLEDIR)/$(OPENJDK_BUILD_NAME).zip
+BUILT_IMAGE=$(ABS_OUTPUTDIR)/j2sdk-image
+ifeq ($(PLATFORM)$(ARCH_DATA_MODEL),solaris64)
+ OPENJDK_BOOTDIR=$(BOOTDIR)
+ OPENJDK_IMPORTJDK=$(JDK_IMPORT_PATH)
+else
+ OPENJDK_BOOTDIR=$(BUILT_IMAGE)
+ OPENJDK_IMPORTJDK=$(BUILT_IMAGE)
+endif
+
+openjdk_build:
@$(ECHO) " "
@$(ECHO) "================================================="
@$(ECHO) "Starting openjdk build"
+ @$(ECHO) " Using: ALT_JDK_DEVTOOLS_DIR=$(JDK_DEVTOOLS_DIR)"
@$(ECHO) "================================================="
@$(ECHO) " "
- $(RM) -r $(ABS_OPENJDK_OUTPUTDIR)
- $(MKDIR) -p $(ABS_OPENJDK_OUTPUTDIR)
- $(MAKE) OPENJDK=true \
- BUILD_LANGTOOLS=$(BUILD_LANGTOOLS) \
- BUILD_CORBA=$(BUILD_CORBA) \
- BUILD_JAXP=$(BUILD_JAXP) \
- BUILD_JAXWS=$(BUILD_JAXWS) \
- BUILD_HOTSPOT=$(BUILD_HOTSPOT) \
- ALT_OUTPUTDIR=$(ABS_OPENJDK_OUTPUTDIR) \
- ALT_BINARY_PLUGS_PATH=$(ABS_OUTPUTDIR)/$(OPENJDK_BINARY_PLUGS_INAME) \
- ALT_BOOTDIR=$(ABS_OUTPUTDIR)/j2sdk-image \
- ALT_JDK_IMPORT_PATH=$(ABS_OUTPUTDIR)/j2sdk-image \
- product_build
+ $(RM) -r $(OPENJDK_OUTPUTDIR)
+ $(MKDIR) -p $(OPENJDK_OUTPUTDIR)
+ ($(CD) $(OPENJDK_BUILDDIR) && $(MAKE) \
+ OPENJDK=true \
+ ALT_JDK_DEVTOOLS_DIR=$(JDK_DEVTOOLS_DIR) \
+ ALT_OUTPUTDIR=$(OPENJDK_OUTPUTDIR) \
+ ALT_BINARY_PLUGS_PATH=$(OPENJDK_PLUGS) \
+ ALT_BOOTDIR=$(OPENJDK_BOOTDIR) \
+ ALT_JDK_IMPORT_PATH=$(OPENJDK_IMPORTJDK) \
+ product_build )
$(RM) $(OPENJDK_BUILD_BINARY_ZIP)
- ( $(CD) $(ABS_OPENJDK_OUTPUTDIR)/j2sdk-image && \
+ ( $(CD) $(OPENJDK_OUTPUTDIR)/j2sdk-image && \
$(ZIPEXE) -q -r $(OPENJDK_BUILD_BINARY_ZIP) .)
- $(RM) -r $(ABS_OPENJDK_OUTPUTDIR)
+ $(RM) -r $(OPENJDK_OUTPUTDIR)
+ @$(ECHO) " "
+ @$(ECHO) "================================================="
+ @$(ECHO) "Finished openjdk build"
+ @$(ECHO) " Binary Bundle: $(OPENJDK_BUILD_BINARY_ZIP)"
+ @$(ECHO) "================================================="
+ @$(ECHO) " "
+
endif
endif
endif
@@ -432,11 +477,11 @@ endif
# Cycle build. Build the jdk, use it to build the jdk again.
################################################################
-ABS_BOOTJDK_OUTPUTDIR=$(ABS_OUTPUTDIR)/bootjdk
+ABS_BOOTDIR_OUTPUTDIR=$(ABS_OUTPUTDIR)/bootjdk
boot_cycle:
- $(MAKE) ALT_OUTPUTDIR=$(ABS_BOOTJDK_OUTPUTDIR) product_build
- $(MAKE) ALT_BOOTDIR=$(ABS_BOOTJDK_OUTPUTDIR)/j2sdk-image product_build
+ $(MAKE) ALT_OUTPUTDIR=$(ABS_BOOTDIR_OUTPUTDIR) product_build
+ $(MAKE) ALT_BOOTDIR=$(ABS_BOOTDIR_OUTPUTDIR)/j2sdk-image product_build
################################################################
# JPRT rule to build
diff --git a/make/Defs-internal.gmk b/make/Defs-internal.gmk
index 6d4c81ca6ff..7343049c61b 100644
--- a/make/Defs-internal.gmk
+++ b/make/Defs-internal.gmk
@@ -151,8 +151,6 @@ ifdef OPENJDK
else
ifndef SKIP_OPENJDK_BUILD
SKIP_OPENJDK_BUILD = false
- # FIXUP: until freetype fixed on linux and solaris rmi build fixed
- SKIP_OPENJDK_BUILD = true
endif
endif
From fbfab433d554d7b9e20e4204b7a2c0cae6caf010 Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Sun, 9 Mar 2008 14:16:49 -0700
Subject: [PATCH 049/126] 6672777: Broken deploy build from jdk fix 6668781 for
cygwin windows
Deploy workspace does not set BUILDDIR, uses it, assumes it is jdk/make.
Reviewed-by: xdono
---
jdk/make/common/Defs.gmk | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/jdk/make/common/Defs.gmk b/jdk/make/common/Defs.gmk
index 6048744384e..92da33487ce 100644
--- a/jdk/make/common/Defs.gmk
+++ b/jdk/make/common/Defs.gmk
@@ -41,7 +41,15 @@
SUN_MAKE_TEST:sh = echo "ERROR: PLEASE USE GNU VERSION OF MAKE"; exit 33
ifndef JDK_TOPDIR
- JDK_TOPDIR=$(BUILDDIR)/..
+ ifdef BUILDDIR
+ JDK_TOPDIR=$(BUILDDIR)/..
+ else
+ JDK_TOPDIR:=$(error "ERROR: Cannot define top of jdk repository")
+ endif
+endif
+ifndef BUILDDIR
+ # Hack, due to deploy repository using this file.
+ BUILDDIR=$(JDK_TOPDIR)/make
endif
ifndef JDK_MAKE_SHARED_DIR
JDK_MAKE_SHARED_DIR=$(JDK_TOPDIR)/make/common/shared
From 6377bd6f3ab4a4a540f611cfd9149dd5fe2b1ffc Mon Sep 17 00:00:00 2001
From: Kelly O'Hair
Date: Sun, 9 Mar 2008 15:47:58 -0700
Subject: [PATCH 050/126] 6649672: Adjustments to OUTPUTDIR default and mkdirs
to avoid empty directory clutter
Cleanup of OUTPUTDIR handling
Reviewed-by: xdono
---
Makefile | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 3ced65f0e31..43b36254335 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,8 @@
# have any questions.
#
+BUILD_PARENT_DIRECTORY=.
+
ifndef TOPDIR
TOPDIR:=$(shell \
if [ -r ./j2se/make/Makefile -o -r ./jdk/make/Makefile ]; then \
@@ -66,6 +68,7 @@ include ./make/Defs-internal.gmk
all::
@$(ECHO) $(PLATFORM) $(ARCH) $(RELEASE) build started: `$(DATE) '+%y-%m-%d %H:%M'`
+ $(MKDIR) -p $(OUTPUTDIR)
# Rules for sanity checks
include ./make/sanity-rules.gmk
@@ -94,12 +97,9 @@ all:: setup build
setup: openjdk_check
$(MKDIR) -p $(OUTPUTDIR)/j2sdk-image
- $(MKDIR) -p $(ABS_OUTPUTDIR)/j2sdk-image
- $(MKDIR) -p $(OUTPUTDIR)-fastdebug/j2sdk-image
- $(MKDIR) -p $(ABS_OUTPUTDIR)-fastdebug/j2sdk-image
# Check on whether we really can build the openjdk, need source etc.
-openjdk_check:
+openjdk_check: FRC
ifneq ($(SKIP_OPENJDK_BUILD), true)
@$(ECHO) " "
@$(ECHO) "================================================="
@@ -170,7 +170,7 @@ endif
COMMON_DEBUG_FLAGS= \
DEBUG_NAME=$(DEBUG_NAME) \
- ALT_OUTPUTDIR=$(_OUTPUTDIR)-$(DEBUG_NAME) \
+ ALT_OUTPUTDIR=$(ABS_OUTPUTDIR)-$(DEBUG_NAME) \
NO_DOCS=true
product_build: setup
@@ -501,3 +501,6 @@ include ./make/jprt.gmk
j2se_fastdebug_only: jdk_fastdebug_only
j2se_only: jdk_only
+# Force target
+FRC:
+
From 13ced2b9352e23eee1cc8650e49b51dd38a084e8 Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Sun, 9 Mar 2008 21:56:42 -0700
Subject: [PATCH 051/126] 4499288: (cs spec) Charset terminology problems
Reviewed-by: mr, iris
---
.../classes/java/nio/charset/Charset.java | 51 +++++++++++--------
1 file changed, 31 insertions(+), 20 deletions(-)
diff --git a/jdk/src/share/classes/java/nio/charset/Charset.java b/jdk/src/share/classes/java/nio/charset/Charset.java
index 13723432712..4c166d519a2 100644
--- a/jdk/src/share/classes/java/nio/charset/Charset.java
+++ b/jdk/src/share/classes/java/nio/charset/Charset.java
@@ -212,36 +212,47 @@ import sun.security.action.GetPropertyAction;
*
* Terminology
*
- * The name of this class is taken from the terms used in RFC 2278. In that
- * document a charset is defined as the combination of a coded character
- * set and a character-encoding scheme.
+ *
The name of this class is taken from the terms used in
+ * RFC 2278.
+ * In that document a charset is defined as the combination of
+ * one or more coded character sets and a character-encoding scheme.
+ * (This definition is confusing; some other software systems define
+ * charset as a synonym for coded character set.)
*
*
A coded character set is a mapping between a set of abstract
* characters and a set of integers. US-ASCII, ISO 8859-1,
- * JIS X 0201, and full Unicode, which is the same as
- * ISO 10646-1, are examples of coded character sets.
+ * JIS X 0201, and Unicode are examples of coded character sets.
*
- *
A character-encoding scheme is a mapping between a coded
- * character set and a set of octet (eight-bit byte) sequences. UTF-8, UCS-2,
- * UTF-16, ISO 2022, and EUC are examples of character-encoding schemes.
- * Encoding schemes are often associated with a particular coded character set;
- * UTF-8, for example, is used only to encode Unicode. Some schemes, however,
- * are associated with multiple character sets; EUC, for example, can be used
- * to encode characters in a variety of Asian character sets.
+ *
Some standards have defined a character set to be simply a
+ * set of abstract characters without an associated assigned numbering.
+ * An alphabet is an example of such a character set. However, the subtle
+ * distinction between character set and coded character set
+ * is rarely used in practice; the former has become a short form for the
+ * latter, including in the Java API specification.
+ *
+ *
A character-encoding scheme is a mapping between one or more
+ * coded character sets and a set of octet (eight-bit byte) sequences.
+ * UTF-8, UTF-16, ISO 2022, and EUC are examples of
+ * character-encoding schemes. Encoding schemes are often associated with
+ * a particular coded character set; UTF-8, for example, is used only to
+ * encode Unicode. Some schemes, however, are associated with multiple
+ * coded character sets; EUC, for example, can be used to encode
+ * characters in a variety of Asian coded character sets.
*
*
When a coded character set is used exclusively with a single
- * character-encoding scheme then the corresponding charset is usually named
- * for the character set; otherwise a charset is usually named for the encoding
- * scheme and, possibly, the locale of the character sets that it supports.
- * Hence US-ASCII is the name of the charset for US-ASCII while
+ * character-encoding scheme then the corresponding charset is usually
+ * named for the coded character set; otherwise a charset is usually named
+ * for the encoding scheme and, possibly, the locale of the coded
+ * character sets that it supports. Hence US-ASCII is both the
+ * name of a coded character set and of the charset that encodes it, while
* EUC-JP is the name of the charset that encodes the
* JIS X 0201, JIS X 0208, and JIS X 0212
- * character sets.
+ * coded character sets for the Japanese language.
*
*
The native character encoding of the Java programming language is
- * UTF-16. A charset in the Java platform therefore defines a mapping between
- * sequences of sixteen-bit UTF-16 code units and sequences of bytes.
+ * UTF-16. A charset in the Java platform therefore defines a mapping
+ * between sequences of sixteen-bit UTF-16 code units (that is, sequences
+ * of chars) and sequences of bytes.
*
*
* @author Mark Reinhold
From 14120d1c34e84e53b83b212683a6de6ac8f66bb4 Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Sun, 9 Mar 2008 21:56:42 -0700
Subject: [PATCH 052/126] 6671834: (str) Eliminate StringCoding.java compile
warnings
Reviewed-by: iris
---
.../share/classes/java/lang/StringCoding.java | 21 ++++++++++---------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/jdk/src/share/classes/java/lang/StringCoding.java b/jdk/src/share/classes/java/lang/StringCoding.java
index 7eb302130d1..d3a23a8816d 100644
--- a/jdk/src/share/classes/java/lang/StringCoding.java
+++ b/jdk/src/share/classes/java/lang/StringCoding.java
@@ -53,22 +53,23 @@ class StringCoding {
private StringCoding() { }
- /* The cached coders for each thread
- */
- private static ThreadLocal decoder = new ThreadLocal();
- private static ThreadLocal encoder = new ThreadLocal();
+ /** The cached coders for each thread */
+ private final static ThreadLocal> decoder =
+ new ThreadLocal>();
+ private final static ThreadLocal> encoder =
+ new ThreadLocal>();
private static boolean warnUnsupportedCharset = true;
- private static Object deref(ThreadLocal tl) {
- SoftReference sr = (SoftReference)tl.get();
+ private static T deref(ThreadLocal> tl) {
+ SoftReference sr = tl.get();
if (sr == null)
return null;
return sr.get();
}
- private static void set(ThreadLocal tl, Object ob) {
- tl.set(new SoftReference(ob));
+ private static void set(ThreadLocal> tl, T ob) {
+ tl.set(new SoftReference(ob));
}
// Trim the given byte array to the given length
@@ -174,7 +175,7 @@ class StringCoding {
static char[] decode(String charsetName, byte[] ba, int off, int len)
throws UnsupportedEncodingException
{
- StringDecoder sd = (StringDecoder)deref(decoder);
+ StringDecoder sd = deref(decoder);
String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
if ((sd == null) || !(csn.equals(sd.requestedCharsetName())
|| csn.equals(sd.charsetName()))) {
@@ -273,7 +274,7 @@ class StringCoding {
static byte[] encode(String charsetName, char[] ca, int off, int len)
throws UnsupportedEncodingException
{
- StringEncoder se = (StringEncoder)deref(encoder);
+ StringEncoder se = deref(encoder);
String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
if ((se == null) || !(csn.equals(se.requestedCharsetName())
|| csn.equals(se.charsetName()))) {
From f7ce4bc4ab4e069fa2f4a60f9c24ff576bf03bd5 Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Sun, 9 Mar 2008 21:56:42 -0700
Subject: [PATCH 053/126] 6633613: (str) StringCoding optimizations to avoid
unnecessary array copies with Charset arg
Reviewed-by: iris
---
jdk/src/share/classes/java/lang/StringCoding.java | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/jdk/src/share/classes/java/lang/StringCoding.java b/jdk/src/share/classes/java/lang/StringCoding.java
index d3a23a8816d..f9d8ef3e66b 100644
--- a/jdk/src/share/classes/java/lang/StringCoding.java
+++ b/jdk/src/share/classes/java/lang/StringCoding.java
@@ -194,8 +194,7 @@ class StringCoding {
static char[] decode(Charset cs, byte[] ba, int off, int len) {
StringDecoder sd = new StringDecoder(cs, cs.name());
- byte[] b = Arrays.copyOf(ba, ba.length);
- return sd.decode(b, off, len);
+ return sd.decode(Arrays.copyOfRange(ba, off, off + len), 0, len);
}
static char[] decode(byte[] ba, int off, int len) {
@@ -293,8 +292,7 @@ class StringCoding {
static byte[] encode(Charset cs, char[] ca, int off, int len) {
StringEncoder se = new StringEncoder(cs, cs.name());
- char[] c = Arrays.copyOf(ca, ca.length);
- return se.encode(c, off, len);
+ return se.encode(Arrays.copyOfRange(ca, off, off + len), 0, len);
}
static byte[] encode(char[] ca, int off, int len) {
From 4d5b9980281cfae3dac5f913593cffb30c2cfed9 Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Mon, 10 Mar 2008 14:32:50 -0700
Subject: [PATCH 054/126] 6631966: (process) Raise Windows pipe buffer size an
extra 24 bytes (win)
Reviewed-by: alanb, iris
---
jdk/src/windows/native/java/lang/ProcessImpl_md.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/jdk/src/windows/native/java/lang/ProcessImpl_md.c b/jdk/src/windows/native/java/lang/ProcessImpl_md.c
index fd9da8e4168..71113a7d5b4 100644
--- a/jdk/src/windows/native/java/lang/ProcessImpl_md.c
+++ b/jdk/src/windows/native/java/lang/ProcessImpl_md.c
@@ -33,7 +33,12 @@
#include
#include
-#define PIPE_SIZE 4096
+/* We try to make sure that we can read and write 4095 bytes (the
+ * fixed limit on Linux) to the pipe on all operating systems without
+ * deadlock. Windows 2000 inexplicably appears to need an extra 24
+ * bytes of slop to avoid deadlock.
+ */
+#define PIPE_SIZE (4096+24)
char *
extractExecutablePath(JNIEnv *env, char *source)
From a686efe6ac9be1d68648950ff48515f522df9b31 Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Mon, 10 Mar 2008 14:32:51 -0700
Subject: [PATCH 055/126] 6632696: Writing to closed output files (writeBytes)
leaks native memory (unix)
Reviewed-by: alanb, iris
---
jdk/src/share/native/java/io/io_util.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/jdk/src/share/native/java/io/io_util.c b/jdk/src/share/native/java/io/io_util.c
index 4f7372babb9..f8fc714bbdc 100644
--- a/jdk/src/share/native/java/io/io_util.c
+++ b/jdk/src/share/native/java/io/io_util.c
@@ -40,7 +40,7 @@ readSingle(JNIEnv *env, jobject this, jfieldID fid) {
char ret;
FD fd = GET_FD(this, fid);
if (fd == -1) {
- JNU_ThrowIOException (env, "Stream Closed");
+ JNU_ThrowIOException(env, "Stream Closed");
return -1;
}
nread = IO_Read(fd, &ret, 1);
@@ -94,7 +94,7 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes,
fd = GET_FD(this, fid);
if (fd == -1) {
- JNU_ThrowIOException (env, "Stream Closed");
+ JNU_ThrowIOException(env, "Stream Closed");
return -1;
}
@@ -121,7 +121,7 @@ writeSingle(JNIEnv *env, jobject this, jint byte, jfieldID fid) {
int n;
FD fd = GET_FD(this, fid);
if (fd == -1) {
- JNU_ThrowIOException (env, "Stream Closed");
+ JNU_ThrowIOException(env, "Stream Closed");
return;
}
n = IO_Write(fd, &c, 1);
@@ -172,8 +172,8 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes,
while (len > 0) {
fd = GET_FD(this, fid);
if (fd == -1) {
- JNU_ThrowIOException (env, "Stream Closed");
- return;
+ JNU_ThrowIOException(env, "Stream Closed");
+ break;
}
n = IO_Write(fd, buf+off, len);
if (n == JVM_IO_ERR) {
From 2c1daccc0a45183696a90bdb80094daf6f296b6f Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Mon, 10 Mar 2008 14:32:51 -0700
Subject: [PATCH 056/126] 6631362: Nuke io_util_md.c:handleFileSizeFD (win)
Reviewed-by: alanb, iris
---
jdk/src/windows/native/java/io/io_util_md.c | 18 ------------------
jdk/src/windows/native/java/io/io_util_md.h | 1 -
2 files changed, 19 deletions(-)
diff --git a/jdk/src/windows/native/java/io/io_util_md.c b/jdk/src/windows/native/java/io/io_util_md.c
index a18894ca885..342e8cdc017 100644
--- a/jdk/src/windows/native/java/io/io_util_md.c
+++ b/jdk/src/windows/native/java/io/io_util_md.c
@@ -444,24 +444,6 @@ handleSetLength(jlong fd, jlong length) {
return 0;
}
-int
-handleFileSizeFD(jlong fd, jlong *size)
-{
- DWORD sizeLow = 0;
- DWORD sizeHigh = 0;
- HANDLE h = (HANDLE)fd;
- if (h == INVALID_HANDLE_VALUE) {
- return -1;
- }
- sizeLow = GetFileSize(h, &sizeHigh);
- if (sizeLow == ((DWORD)-1)) {
- if (GetLastError() != ERROR_SUCCESS) {
- return -1;
- }
- }
- return (((jlong)sizeHigh) << 32) | sizeLow;
-}
-
JNIEXPORT
size_t
handleRead(jlong fd, void *buf, jint len)
diff --git a/jdk/src/windows/native/java/io/io_util_md.h b/jdk/src/windows/native/java/io/io_util_md.h
index fdbd5bf22e2..bf9047d7c65 100644
--- a/jdk/src/windows/native/java/io/io_util_md.h
+++ b/jdk/src/windows/native/java/io/io_util_md.h
@@ -38,7 +38,6 @@ void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags);
int handleAvailable(jlong fd, jlong *pbytes);
JNIEXPORT int handleSync(jlong fd);
int handleSetLength(jlong fd, jlong length);
-int handleFileSizeFD(jlong fd, jlong *size);
JNIEXPORT size_t handleRead(jlong fd, void *buf, jint len);
JNIEXPORT size_t handleWrite(jlong fd, const void *buf, jint len);
jint handleClose(JNIEnv *env, jobject this, jfieldID fid);
From 8d412f036d7fa56e18c2d771f012d3e4959255d8 Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Mon, 10 Mar 2008 14:32:51 -0700
Subject: [PATCH 057/126] 6631437: File{In,Out}putStream minor improvements to
spec and stylistic improvements to code
Reviewed-by: alanb, iris
---
.../classes/java/io/FileInputStream.java | 12 +++++-----
.../classes/java/io/FileOutputStream.java | 24 +++++++++----------
2 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/jdk/src/share/classes/java/io/FileInputStream.java b/jdk/src/share/classes/java/io/FileInputStream.java
index 8575e6d9397..a37c69c6239 100644
--- a/jdk/src/share/classes/java/io/FileInputStream.java
+++ b/jdk/src/share/classes/java/io/FileInputStream.java
@@ -48,15 +48,15 @@ public
class FileInputStream extends InputStream
{
/* File Descriptor - handle to the open file */
- private FileDescriptor fd;
+ private final FileDescriptor fd;
private FileChannel channel = null;
- private Object closeLock = new Object();
+ private final Object closeLock = new Object();
private volatile boolean closed = false;
- private static ThreadLocal runningFinalize =
- new ThreadLocal();
+ private static final ThreadLocal runningFinalize =
+ new ThreadLocal();
private static boolean isRunningFinalize() {
Boolean val;
@@ -151,7 +151,7 @@ class FileInputStream extends InputStream
* is thrown.
*
* This constructor does not throw an exception if fdObj
- * is {link java.io.FileDescriptor#valid() invalid}.
+ * is {@link java.io.FileDescriptor#valid() invalid}.
* However, if the methods are invoked on the resulting stream to attempt
* I/O on the stream, an IOException is thrown.
*
@@ -389,7 +389,7 @@ class FileInputStream extends InputStream
* @see java.io.FileInputStream#close()
*/
protected void finalize() throws IOException {
- if ((fd != null) && (fd != fd.in)) {
+ if ((fd != null) && (fd != FileDescriptor.in)) {
/*
* Finalizer should not release the FileDescriptor if another
diff --git a/jdk/src/share/classes/java/io/FileOutputStream.java b/jdk/src/share/classes/java/io/FileOutputStream.java
index 695f43150fe..f6b880a503e 100644
--- a/jdk/src/share/classes/java/io/FileOutputStream.java
+++ b/jdk/src/share/classes/java/io/FileOutputStream.java
@@ -52,20 +52,18 @@ public
class FileOutputStream extends OutputStream
{
/**
- * The system dependent file descriptor. The value is
- * 1 more than actual file descriptor. This means that
- * the default value 0 indicates that the file is not open.
+ * The system dependent file descriptor.
*/
- private FileDescriptor fd;
+ private final FileDescriptor fd;
private FileChannel channel= null;
private boolean append = false;
- private Object closeLock = new Object();
+ private final Object closeLock = new Object();
private volatile boolean closed = false;
- private static ThreadLocal runningFinalize =
- new ThreadLocal();
+ private static final ThreadLocal runningFinalize =
+ new ThreadLocal();
private static boolean isRunningFinalize() {
Boolean val;
@@ -75,7 +73,7 @@ class FileOutputStream extends OutputStream
}
/**
- * Creates an output file stream to write to the file with the
+ * Creates a file output stream to write to the file with the
* specified name. A new FileDescriptor object is
* created to represent this file connection.
*
@@ -100,8 +98,8 @@ class FileOutputStream extends OutputStream
}
/**
- * Creates an output file stream to write to the file with the specified
- * name. If the second argument is true, then
+ * Creates a file output stream to write to the file with the specified
+ * name. If the second argument is true, then
* bytes will be written to the end of the file rather than the beginning.
* A new FileDescriptor object is created to represent this
* file connection.
@@ -211,7 +209,7 @@ class FileOutputStream extends OutputStream
}
/**
- * Creates an output file stream to write to the specified file
+ * Creates a file output stream to write to the specified file
* descriptor, which represents an existing connection to an actual
* file in the file system.
*
@@ -223,7 +221,7 @@ class FileOutputStream extends OutputStream
* is thrown.
*
* This constructor does not throw an exception if fdObj
- * is {link java.io.FileDescriptor#valid() invalid}.
+ * is {@link java.io.FileDescriptor#valid() invalid}.
* However, if the methods are invoked on the resulting stream to attempt
* I/O on the stream, an IOException is thrown.
*
@@ -408,7 +406,7 @@ class FileOutputStream extends OutputStream
*/
protected void finalize() throws IOException {
if (fd != null) {
- if (fd == fd.out || fd == fd.err) {
+ if (fd == FileDescriptor.out || fd == FileDescriptor.err) {
flush();
} else {
From 504a24907dc225b19cd807040b1db9a24606034c Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Mon, 10 Mar 2008 14:32:51 -0700
Subject: [PATCH 058/126] 6631352: File{OutputStream,Writer} should implement
atomic append mode using FILE_APPEND_DATA (win)
Reviewed-by: alanb, iris
---
jdk/make/java/java/mapfile-vers | 1 -
.../classes/java/io/FileOutputStream.java | 23 ++----
.../classes/sun/nio/ch/FileChannelImpl.java | 49 ++++-------
jdk/src/share/native/java/io/io_util.c | 2 +-
.../native/java/io/FileOutputStream_md.c | 11 +--
.../native/java/io/FileOutputStream_md.c | 36 +--------
jdk/src/windows/native/java/io/io_util_md.c | 13 ++-
.../io/FileOutputStream/AtomicAppend.java | 81 +++++++++++++++++++
8 files changed, 120 insertions(+), 96 deletions(-)
create mode 100644 jdk/test/java/io/FileOutputStream/AtomicAppend.java
diff --git a/jdk/make/java/java/mapfile-vers b/jdk/make/java/java/mapfile-vers
index 4599570449e..38f9e126d82 100644
--- a/jdk/make/java/java/mapfile-vers
+++ b/jdk/make/java/java/mapfile-vers
@@ -85,7 +85,6 @@ SUNWprivate_1.1 {
Java_java_io_FileOutputStream_close0;
Java_java_io_FileOutputStream_initIDs;
Java_java_io_FileOutputStream_open;
- Java_java_io_FileOutputStream_openAppend;
Java_java_io_FileOutputStream_write;
Java_java_io_FileOutputStream_writeBytes;
Java_java_io_FileSystem_getFileSystem;
diff --git a/jdk/src/share/classes/java/io/FileOutputStream.java b/jdk/src/share/classes/java/io/FileOutputStream.java
index f6b880a503e..f252237d89f 100644
--- a/jdk/src/share/classes/java/io/FileOutputStream.java
+++ b/jdk/src/share/classes/java/io/FileOutputStream.java
@@ -58,8 +58,6 @@ class FileOutputStream extends OutputStream
private FileChannel channel= null;
- private boolean append = false;
-
private final Object closeLock = new Object();
private volatile boolean closed = false;
private static final ThreadLocal runningFinalize =
@@ -200,12 +198,7 @@ class FileOutputStream extends OutputStream
}
fd = new FileDescriptor();
fd.incrementAndGetUseCount();
- this.append = append;
- if (append) {
- openAppend(name);
- } else {
- open(name);
- }
+ open(name, append);
}
/**
@@ -250,16 +243,12 @@ class FileOutputStream extends OutputStream
}
/**
- * Opens a file, with the specified name, for writing.
+ * Opens a file, with the specified name, for overwriting or appending.
* @param name name of file to be opened
+ * @param append whether the file is to be opened in append mode
*/
- private native void open(String name) throws FileNotFoundException;
-
- /**
- * Opens a file, with the specified name, for appending.
- * @param name name of file to be opened
- */
- private native void openAppend(String name) throws FileNotFoundException;
+ private native void open(String name, boolean append)
+ throws FileNotFoundException;
/**
* Writes the specified byte to this file output stream. Implements
@@ -383,7 +372,7 @@ class FileOutputStream extends OutputStream
public FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
- channel = FileChannelImpl.open(fd, false, true, this, append);
+ channel = FileChannelImpl.open(fd, false, true, this);
/*
* Increment fd's use count. Invoking the channel's close()
diff --git a/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java
index 4aa21dbd18a..aae23b7664b 100644
--- a/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java
+++ b/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java
@@ -52,39 +52,37 @@ public class FileChannelImpl
{
// Used to make native read and write calls
- private static NativeDispatcher nd;
+ private static final NativeDispatcher nd;
// Memory allocation size for mapping buffers
- private static long allocationGranularity;
+ private static final long allocationGranularity;
// Cached field for MappedByteBuffer.isAMappedBuffer
- private static Field isAMappedBufferField;
+ private static final Field isAMappedBufferField;
// File descriptor
- private FileDescriptor fd;
+ private final FileDescriptor fd;
// File access mode (immutable)
- private boolean writable;
- private boolean readable;
- private boolean appending;
+ private final boolean writable;
+ private final boolean readable;
// Required to prevent finalization of creating stream (immutable)
- private Object parent;
+ private final Object parent;
// Thread-safe set of IDs of native threads, for signalling
- private NativeThreadSet threads = new NativeThreadSet(2);
+ private final NativeThreadSet threads = new NativeThreadSet(2);
// Lock for operations involving position and size
- private Object positionLock = new Object();
+ private final Object positionLock = new Object();
private FileChannelImpl(FileDescriptor fd, boolean readable,
- boolean writable, Object parent, boolean append)
+ boolean writable, Object parent)
{
this.fd = fd;
this.readable = readable;
this.writable = writable;
this.parent = parent;
- this.appending = append;
}
// Invoked by getChannel() methods
@@ -94,14 +92,7 @@ public class FileChannelImpl
boolean readable, boolean writable,
Object parent)
{
- return new FileChannelImpl(fd, readable, writable, parent, false);
- }
-
- public static FileChannel open(FileDescriptor fd,
- boolean readable, boolean writable,
- Object parent, boolean append)
- {
- return new FileChannelImpl(fd, readable, writable, parent, append);
+ return new FileChannelImpl(fd, readable, writable, parent);
}
private void ensureOpen() throws IOException {
@@ -134,15 +125,7 @@ public class FileChannelImpl
// superclass AbstractInterruptibleChannel, but the isOpen logic in
// that method will prevent this method from being reinvoked.
//
- if (parent instanceof FileInputStream)
- ((FileInputStream)parent).close();
- else if (parent instanceof FileOutputStream)
- ((FileOutputStream)parent).close();
- else if (parent instanceof RandomAccessFile)
- ((RandomAccessFile)parent).close();
- else
- assert false;
-
+ ((java.io.Closeable)parent).close();
} else {
nd.close(fd);
}
@@ -218,8 +201,6 @@ public class FileChannelImpl
if (!isOpen())
return 0;
ti = threads.add();
- if (appending)
- position(size());
do {
n = IOUtil.write(fd, src, -1, nd, positionLock);
} while ((n == IOStatus.INTERRUPTED) && isOpen());
@@ -244,8 +225,6 @@ public class FileChannelImpl
if (!isOpen())
return 0;
ti = threads.add();
- if (appending)
- position(size());
do {
n = IOUtil.write(fd, srcs, nd);
} while ((n == IOStatus.INTERRUPTED) && isOpen());
@@ -1051,7 +1030,7 @@ public class FileChannelImpl
private FileKey fileKey;
FileLockReference(FileLock referent,
- ReferenceQueue queue,
+ ReferenceQueue queue,
FileKey key) {
super(referent, queue);
this.fileKey = key;
@@ -1073,7 +1052,7 @@ public class FileChannelImpl
new ConcurrentHashMap>();
// reference queue for cleared refs
- private static ReferenceQueue queue = new ReferenceQueue();
+ private static ReferenceQueue queue = new ReferenceQueue();
// the enclosing file channel
private FileChannelImpl fci;
diff --git a/jdk/src/share/native/java/io/io_util.c b/jdk/src/share/native/java/io/io_util.c
index f8fc714bbdc..f355069cd0a 100644
--- a/jdk/src/share/native/java/io/io_util.c
+++ b/jdk/src/share/native/java/io/io_util.c
@@ -95,7 +95,7 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes,
fd = GET_FD(this, fid);
if (fd == -1) {
JNU_ThrowIOException(env, "Stream Closed");
- return -1;
+ return -1;
}
nread = IO_Read(fd, buf, len);
diff --git a/jdk/src/solaris/native/java/io/FileOutputStream_md.c b/jdk/src/solaris/native/java/io/FileOutputStream_md.c
index 3bee404589c..4fc5904660b 100644
--- a/jdk/src/solaris/native/java/io/FileOutputStream_md.c
+++ b/jdk/src/solaris/native/java/io/FileOutputStream_md.c
@@ -53,13 +53,10 @@ Java_java_io_FileOutputStream_initIDs(JNIEnv *env, jclass fdClass) {
*/
JNIEXPORT void JNICALL
-Java_java_io_FileOutputStream_open(JNIEnv *env, jobject this, jstring path) {
- fileOpen(env, this, path, fos_fd, O_WRONLY | O_CREAT | O_TRUNC);
-}
-
-JNIEXPORT void JNICALL
-Java_java_io_FileOutputStream_openAppend(JNIEnv *env, jobject this, jstring path) {
- fileOpen(env, this, path, fos_fd, O_WRONLY | O_CREAT | O_APPEND);
+Java_java_io_FileOutputStream_open(JNIEnv *env, jobject this,
+ jstring path, jboolean append) {
+ fileOpen(env, this, path, fos_fd,
+ O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC));
}
JNIEXPORT void JNICALL
diff --git a/jdk/src/windows/native/java/io/FileOutputStream_md.c b/jdk/src/windows/native/java/io/FileOutputStream_md.c
index b5c29abe3e5..97862c5d2d8 100644
--- a/jdk/src/windows/native/java/io/FileOutputStream_md.c
+++ b/jdk/src/windows/native/java/io/FileOutputStream_md.c
@@ -39,8 +39,6 @@
jfieldID fos_fd; /* id for jobject 'fd' in java.io.FileOutputStream */
-jfieldID fos_append;
-
/**************************************************************
* static methods to store field ID's in initializers
*/
@@ -49,7 +47,6 @@ JNIEXPORT void JNICALL
Java_java_io_FileOutputStream_initIDs(JNIEnv *env, jclass fosClass) {
fos_fd =
(*env)->GetFieldID(env, fosClass, "fd", "Ljava/io/FileDescriptor;");
- fos_append = (*env)->GetFieldID(env, fosClass, "append", "Z");
}
/**************************************************************
@@ -57,45 +54,20 @@ Java_java_io_FileOutputStream_initIDs(JNIEnv *env, jclass fosClass) {
*/
JNIEXPORT void JNICALL
-Java_java_io_FileOutputStream_open(JNIEnv *env, jobject this, jstring path) {
- fileOpen(env, this, path, fos_fd, O_WRONLY | O_CREAT | O_TRUNC);
-}
-
-JNIEXPORT void JNICALL
-Java_java_io_FileOutputStream_openAppend(JNIEnv *env, jobject this, jstring path) {
- fileOpen(env, this, path, fos_fd, O_WRONLY | O_CREAT | O_APPEND);
+Java_java_io_FileOutputStream_open(JNIEnv *env, jobject this,
+ jstring path, jboolean append) {
+ fileOpen(env, this, path, fos_fd,
+ O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC));
}
JNIEXPORT void JNICALL
Java_java_io_FileOutputStream_write(JNIEnv *env, jobject this, jint byte) {
- jboolean append = (*env)->GetBooleanField(env, this, fos_append);
- FD fd = GET_FD(this, fos_fd);
- if (fd == -1) {
- JNU_ThrowIOException(env, "Stream Closed");
- return;
- }
- if (append == JNI_TRUE) {
- if (IO_Lseek(fd, 0L, SEEK_END) == -1) {
- JNU_ThrowIOExceptionWithLastError(env, "Append failed");
- }
- }
writeSingle(env, this, byte, fos_fd);
}
JNIEXPORT void JNICALL
Java_java_io_FileOutputStream_writeBytes(JNIEnv *env,
jobject this, jbyteArray bytes, jint off, jint len) {
- jboolean append = (*env)->GetBooleanField(env, this, fos_append);
- FD fd = GET_FD(this, fos_fd);
- if (fd == -1) {
- JNU_ThrowIOException(env, "Stream Closed");
- return;
- }
- if (append == JNI_TRUE) {
- if (IO_Lseek(fd, 0L, SEEK_END) == -1) {
- JNU_ThrowIOExceptionWithLastError(env, "Append failed");
- }
- }
writeBytes(env, this, bytes, off, len, fos_fd);
}
diff --git a/jdk/src/windows/native/java/io/io_util_md.c b/jdk/src/windows/native/java/io/io_util_md.c
index 342e8cdc017..89290c778f7 100644
--- a/jdk/src/windows/native/java/io/io_util_md.c
+++ b/jdk/src/windows/native/java/io/io_util_md.c
@@ -42,7 +42,7 @@
extern jboolean onNT = JNI_FALSE;
-static int MAX_INPUT_EVENTS = 2000;
+static DWORD MAX_INPUT_EVENTS = 2000;
void
initializeWindowsVersion() {
@@ -190,9 +190,16 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) {
jlong
winFileHandleOpen(JNIEnv *env, jstring path, int flags)
{
+ /* To implement O_APPEND, we use the strategy from
+ http://msdn2.microsoft.com/en-us/library/aa363858.aspx
+ "You can get atomic append by opening a file with
+ FILE_APPEND_DATA access and _without_ FILE_WRITE_DATA access.
+ If you do this then all writes will ignore the current file
+ pointer and be done at the end-of file." */
const DWORD access =
- (flags & O_RDWR) ? (GENERIC_WRITE | GENERIC_READ) :
+ (flags & O_APPEND) ? (FILE_GENERIC_WRITE & ~FILE_WRITE_DATA) :
(flags & O_WRONLY) ? GENERIC_WRITE :
+ (flags & O_RDWR) ? (GENERIC_READ | GENERIC_WRITE) :
GENERIC_READ;
const DWORD sharing =
FILE_SHARE_READ | FILE_SHARE_WRITE;
@@ -495,7 +502,7 @@ handleClose(JNIEnv *env, jobject this, jfieldID fid)
FD fd = GET_FD(this, fid);
HANDLE h = (HANDLE)fd;
- if (fd == INVALID_HANDLE_VALUE) {
+ if (h == INVALID_HANDLE_VALUE) {
return 0;
}
diff --git a/jdk/test/java/io/FileOutputStream/AtomicAppend.java b/jdk/test/java/io/FileOutputStream/AtomicAppend.java
new file mode 100644
index 00000000000..f5f0c23606c
--- /dev/null
+++ b/jdk/test/java/io/FileOutputStream/AtomicAppend.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6631352
+ * @summary Check that appends are atomic
+ */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+
+public class AtomicAppend {
+ // Before the fix for
+ // 6631352: Implement atomic append mode using FILE_APPEND_DATA (win)
+ // this would fail intermittently on windows
+ void test(String[] args) throws Throwable {
+ final int nThreads = 10;
+ final int writes = 1000;
+ final File file = new File("foo");
+ file.delete();
+ try {
+ final ExecutorService es = Executors.newFixedThreadPool(nThreads);
+ for (int i = 0; i < nThreads; i++)
+ es.execute(new Runnable() { public void run() {
+ try {
+ FileOutputStream s = new FileOutputStream(file, true);
+ for (int j = 0; j < 1000; j++) {
+ s.write((int) 'x');
+ s.flush();
+ }
+ s.close();
+ } catch (Throwable t) { unexpected(t); }}});
+ es.shutdown();
+ es.awaitTermination(10L, TimeUnit.MINUTES);
+ equal(file.length(), (long) (nThreads * writes));
+ } finally {
+ file.delete();
+ }
+ }
+
+ //--------------------- Infrastructure ---------------------------
+ volatile int passed = 0, failed = 0;
+ void pass() {passed++;}
+ void fail() {failed++; Thread.dumpStack();}
+ void fail(String msg) {System.err.println(msg); fail();}
+ void unexpected(Throwable t) {failed++; t.printStackTrace();}
+ void check(boolean cond) {if (cond) pass(); else fail();}
+ void equal(Object x, Object y) {
+ if (x == null ? y == null : x.equals(y)) pass();
+ else fail(x + " not equal to " + y);}
+ public static void main(String[] args) throws Throwable {
+ new AtomicAppend().instanceMain(args);}
+ void instanceMain(String[] args) throws Throwable {
+ try {test(args);} catch (Throwable t) {unexpected(t);}
+ System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
+ if (failed > 0) throw new AssertionError("Some tests failed");}
+}
From abde1241e187c17a5b9dc344156315469e87b161 Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Mon, 10 Mar 2008 14:32:51 -0700
Subject: [PATCH 059/126] 4960438: (process) Need IO redirection API for
subprocesses
Reviewed-by: alanb, iris
---
jdk/src/share/classes/java/lang/Process.java | 71 +-
.../classes/java/lang/ProcessBuilder.java | 726 +++++++++++++++---
.../sun/misc/JavaIOFileDescriptorAccess.java | 4 +
.../classes/java/io/FileDescriptor.java | 10 +-
.../classes/java/lang/ProcessImpl.java | 59 +-
.../classes/java/lang/UNIXProcess.java.linux | 184 +++--
.../java/lang/UNIXProcess.java.solaris | 364 +++++----
.../solaris/native/java/lang/UNIXProcess_md.c | 51 +-
.../classes/java/io/FileDescriptor.java | 33 +-
.../classes/java/lang/ProcessImpl.java | 150 +++-
.../windows/native/java/lang/ProcessImpl_md.c | 97 ++-
jdk/test/java/lang/ProcessBuilder/Basic.java | 379 ++++++++-
12 files changed, 1666 insertions(+), 462 deletions(-)
diff --git a/jdk/src/share/classes/java/lang/Process.java b/jdk/src/share/classes/java/lang/Process.java
index fe4045ab25f..88010fd555d 100644
--- a/jdk/src/share/classes/java/lang/Process.java
+++ b/jdk/src/share/classes/java/lang/Process.java
@@ -41,18 +41,24 @@ import java.io.*;
* The methods that create processes may not work well for special
* processes on certain native platforms, such as native windowing
* processes, daemon processes, Win16/DOS processes on Microsoft
- * Windows, or shell scripts. The created subprocess does not have
- * its own terminal or console. All its standard I/O (i.e. stdin,
- * stdout, stderr) operations will be redirected to the parent process
- * through three streams
- * ({@link #getOutputStream()},
- * {@link #getInputStream()},
- * {@link #getErrorStream()}).
+ * Windows, or shell scripts.
+ *
+ *
By default, the created subprocess does not have its own terminal
+ * or console. All its standard I/O (i.e. stdin, stdout, stderr)
+ * operations will be redirected to the parent process, where they can
+ * be accessed via the streams obtained using the methods
+ * {@link #getOutputStream()},
+ * {@link #getInputStream()}, and
+ * {@link #getErrorStream()}.
* The parent process uses these streams to feed input to and get output
* from the subprocess. Because some native platforms only provide
* limited buffer size for standard input and output streams, failure
* to promptly write the input stream or read the output stream of
- * the subprocess may cause the subprocess to block, and even deadlock.
+ * the subprocess may cause the subprocess to block, or even deadlock.
+ *
+ *
Where desired,
+ * subprocess I/O can also be redirected
+ * using methods of the {@link ProcessBuilder} class.
*
*
The subprocess is not killed when there are no more references to
* the {@code Process} object, but rather the subprocess
@@ -62,16 +68,22 @@ import java.io.*;
* Process} object execute asynchronously or concurrently with respect
* to the Java process that owns the {@code Process} object.
*
- * @author unascribed
- * @see ProcessBuilder
+ *
As of 1.5, {@link ProcessBuilder#start()} is the preferred way
+ * to create a {@code Process}.
+ *
* @since JDK1.0
*/
public abstract class Process {
/**
* Returns the output stream connected to the normal input of the
* subprocess. Output to the stream is piped into the standard
- * input stream of the process represented by this {@code Process}
- * object.
+ * input of the process represented by this {@code Process} object.
+ *
+ *
If the standard input of the subprocess has been redirected using
+ * {@link ProcessBuilder#redirectInput(Redirect)
+ * ProcessBuilder.redirectInput}
+ * then this method will return a
+ * null output stream.
*
*
Implementation note: It is a good idea for the returned
* output stream to be buffered.
@@ -84,30 +96,47 @@ public abstract class Process {
/**
* Returns the input stream connected to the normal output of the
* subprocess. The stream obtains data piped from the standard
- * output stream of the process represented by this {@code
- * Process} object.
+ * output of the process represented by this {@code Process} object.
+ *
+ *
If the standard output of the subprocess has been redirected using
+ * {@link ProcessBuilder#redirectOutput(Redirect)
+ * ProcessBuilder.redirectOutput}
+ * then this method will return a
+ * null input stream.
+ *
+ *
Otherwise, if the standard error of the subprocess has been
+ * redirected using
+ * {@link ProcessBuilder#redirectErrorStream(boolean)
+ * ProcessBuilder.redirectErrorStream}
+ * then the input stream returned by this method will receive the
+ * merged standard output and the standard error of the subprocess.
*
*
Implementation note: It is a good idea for the returned
* input stream to be buffered.
*
* @return the input stream connected to the normal output of the
* subprocess
- * @see ProcessBuilder#redirectErrorStream()
*/
abstract public InputStream getInputStream();
/**
- * Returns the input stream connected to the error output stream of
- * the subprocess. The stream obtains data piped from the error
- * output stream of the process represented by this {@code Process}
- * object.
+ * Returns the input stream connected to the error output of the
+ * subprocess. The stream obtains data piped from the error output
+ * of the process represented by this {@code Process} object.
+ *
+ *
If the standard error of the subprocess has been redirected using
+ * {@link ProcessBuilder#redirectError(Redirect)
+ * ProcessBuilder.redirectError} or
+ * {@link ProcessBuilder#redirectErrorStream(boolean)
+ * ProcessBuilder.redirectErrorStream}
+ * then this method will return a
+ * null input stream.
*
*
Implementation note: It is a good idea for the returned
* input stream to be buffered.
*
- * @return the input stream connected to the error output stream of
+ * @return the input stream connected to the error output of
* the subprocess
- * @see ProcessBuilder#redirectErrorStream()
*/
abstract public InputStream getErrorStream();
diff --git a/jdk/src/share/classes/java/lang/ProcessBuilder.java b/jdk/src/share/classes/java/lang/ProcessBuilder.java
index 32895a5baab..be24e8d8235 100644
--- a/jdk/src/share/classes/java/lang/ProcessBuilder.java
+++ b/jdk/src/share/classes/java/lang/ProcessBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,10 @@ package java.lang;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -34,7 +38,7 @@ import java.util.Map;
/**
* This class is used to create operating system processes.
*
- *
Each ProcessBuilder instance manages a collection
+ *
Each {@code ProcessBuilder} instance manages a collection
* of process attributes. The {@link #start()} method creates a new
* {@link Process} instance with those attributes. The {@link
* #start()} method can be invoked repeatedly from the same instance
@@ -59,19 +63,64 @@ import java.util.Map;
*
*
a working directory. The default value is the current
* working directory of the current process, usually the directory
- * named by the system property user.dir.
+ * named by the system property {@code user.dir}.
+ *
+ * a source of standard input.
+ * By default, the subprocess reads input from a pipe. Java code
+ * can access this pipe via the output stream returned by
+ * {@link Process#getOutputStream()}. However, standard input may
+ * be redirected to another source using
+ * {@link #redirectInput(Redirect) redirectInput}.
+ * In this case, {@link Process#getOutputStream()} will return a
+ * null output stream, for which:
+ *
+ *
+ * - the {@link OutputStream#write(int) write} methods always
+ * throw {@code IOException}
+ *
- the {@link OutputStream#close() close} method does nothing
+ *
+ *
+ * a destination for standard output
+ * and standard error. By default, the subprocess writes standard
+ * output and standard error to pipes. Java code can access these pipes
+ * via the input streams returned by {@link Process#getInputStream()} and
+ * {@link Process#getErrorStream()}. However, standard output and
+ * standard error may be redirected to other destinations using
+ * {@link #redirectOutput(Redirect) redirectOutput} and
+ * {@link #redirectError(Redirect) redirectError}.
+ * In this case, {@link Process#getInputStream()} and/or
+ * {@link Process#getErrorStream()} will return a null input
+ * stream, for which:
+ *
+ *
+ * - the {@link InputStream#read() read} methods always return
+ * {@code -1}
+ *
- the {@link InputStream#available() available} method always returns
+ * {@code 0}
+ *
- the {@link InputStream#close() close} method does nothing
+ *
*
* a redirectErrorStream property. Initially, this property
- * is false, meaning that the standard output and error
+ * is {@code false}, meaning that the standard output and error
* output of a subprocess are sent to two separate streams, which can
* be accessed using the {@link Process#getInputStream()} and {@link
- * Process#getErrorStream()} methods. If the value is set to
- * true, the standard error is merged with the standard
- * output. This makes it easier to correlate error messages with the
- * corresponding output. In this case, the merged data can be read
- * from the stream returned by {@link Process#getInputStream()}, while
- * reading from the stream returned by {@link
- * Process#getErrorStream()} will get an immediate end of file.
+ * Process#getErrorStream()} methods.
+ *
+ * If the value is set to {@code true}, then:
+ *
+ *
+ * - standard error is merged with the standard output and always sent
+ * to the same destination (this makes it easier to correlate error
+ * messages with the corresponding output)
+ *
- the common destination of standard error and standard output can be
+ * redirected using
+ * {@link #redirectOutput(Redirect) redirectOutput}
+ *
- any redirection set by the
+ * {@link #redirectError(Redirect) redirectError}
+ * method is ignored when creating a subprocess
+ *
- the stream returned from {@link Process#getErrorStream()} will
+ * always be a null input stream
+ *
*
*
*
@@ -87,34 +136,43 @@ import java.util.Map;
* is invoked.
*
* Note that this class is not synchronized.
- * If multiple threads access a ProcessBuilder instance
+ * If multiple threads access a {@code ProcessBuilder} instance
* concurrently, and at least one of the threads modifies one of the
* attributes structurally, it must be synchronized externally.
*
*
Starting a new process which uses the default working directory
* and environment is easy:
*
- *
+ * {@code
* Process p = new ProcessBuilder("myCommand", "myArg").start();
- *
+ * }
*
* Here is an example that starts a process with a modified working
- * directory and environment:
+ * directory and environment, and redirects standard output and error
+ * to be appended to a log file:
*
- *
- * ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
- * Map<String, String> env = pb.environment();
+ * {@code
+ * ProcessBuilder pb =
+ * new ProcessBuilder("myCommand", "myArg1", "myArg2");
+ * Map env = pb.environment();
* env.put("VAR1", "myValue");
* env.remove("OTHERVAR");
* env.put("VAR2", env.get("VAR1") + "suffix");
* pb.directory(new File("myDir"));
+ * File log = new File("log");
+ * pb.redirectErrorStream(true);
+ * pb.redirectOutput(Redirect.appendTo(log));
* Process p = pb.start();
- *
+ * assert pb.redirectInput() == Redirect.PIPE;
+ * assert pb.redirectOutput().file() == log;
+ * assert p.getInputStream().read() == -1;
+ * }
*
* To start a process with an explicit set of environment
* variables, first call {@link java.util.Map#clear() Map.clear()}
* before adding environment variables.
*
+ * @author Martin Buchholz
* @since 1.5
*/
@@ -124,20 +182,19 @@ public final class ProcessBuilder
private File directory;
private Map environment;
private boolean redirectErrorStream;
+ private Redirect[] redirects;
/**
* Constructs a process builder with the specified operating
* system program and arguments. This constructor does not
- * make a copy of the command list. Subsequent
+ * make a copy of the {@code command} list. Subsequent
* updates to the list will be reflected in the state of the
* process builder. It is not checked whether
- * command corresponds to a valid operating system
- * command.
+ * {@code command} corresponds to a valid operating system
+ * command.
*
- * @param command The list containing the program and its arguments
- *
- * @throws NullPointerException
- * If the argument is null
+ * @param command the list containing the program and its arguments
+ * @throws NullPointerException if the argument is null
*/
public ProcessBuilder(List command) {
if (command == null)
@@ -149,12 +206,12 @@ public final class ProcessBuilder
* Constructs a process builder with the specified operating
* system program and arguments. This is a convenience
* constructor that sets the process builder's command to a string
- * list containing the same strings as the command
+ * list containing the same strings as the {@code command}
* array, in the same order. It is not checked whether
- * command corresponds to a valid operating system
- * command.
+ * {@code command} corresponds to a valid operating system
+ * command.
*
- * @param command A string array containing the program and its arguments
+ * @param command a string array containing the program and its arguments
*/
public ProcessBuilder(String... command) {
this.command = new ArrayList(command.length);
@@ -165,16 +222,15 @@ public final class ProcessBuilder
/**
* Sets this process builder's operating system program and
* arguments. This method does not make a copy of the
- * command list. Subsequent updates to the list will
+ * {@code command} list. Subsequent updates to the list will
* be reflected in the state of the process builder. It is not
- * checked whether command corresponds to a valid
- * operating system command.
+ * checked whether {@code command} corresponds to a valid
+ * operating system command.
*
- * @param command The list containing the program and its arguments
- * @return This process builder
+ * @param command the list containing the program and its arguments
+ * @return this process builder
*
- * @throws NullPointerException
- * If the argument is null
+ * @throws NullPointerException if the argument is null
*/
public ProcessBuilder command(List command) {
if (command == null)
@@ -187,12 +243,12 @@ public final class ProcessBuilder
* Sets this process builder's operating system program and
* arguments. This is a convenience method that sets the command
* to a string list containing the same strings as the
- * command array, in the same order. It is not
- * checked whether command corresponds to a valid
- * operating system command.
+ * {@code command} array, in the same order. It is not
+ * checked whether {@code command} corresponds to a valid
+ * operating system command.
*
- * @param command A string array containing the program and its arguments
- * @return This process builder
+ * @param command a string array containing the program and its arguments
+ * @return this process builder
*/
public ProcessBuilder command(String... command) {
this.command = new ArrayList(command.length);
@@ -205,9 +261,9 @@ public final class ProcessBuilder
* Returns this process builder's operating system program and
* arguments. The returned list is not a copy. Subsequent
* updates to the list will be reflected in the state of this
- * process builder.
+ * process builder.
*
- * @return This process builder's program and its arguments
+ * @return this process builder's program and its arguments
*/
public List command() {
return command;
@@ -225,10 +281,10 @@ public final class ProcessBuilder
* The returned object may be modified using ordinary {@link
* java.util.Map Map} operations. These modifications will be
* visible to subprocesses started via the {@link #start()}
- * method. Two ProcessBuilder instances always
+ * method. Two {@code ProcessBuilder} instances always
* contain independent process environments, so changes to the
* returned map will never be reflected in any other
- * ProcessBuilder instance or the values returned by
+ * {@code ProcessBuilder} instance or the values returned by
* {@link System#getenv System.getenv}.
*
*
If the system does not support environment variables, an
@@ -262,25 +318,24 @@ public final class ProcessBuilder
*
The returned map is typically case-sensitive on all platforms.
*
*
If a security manager exists, its
- * {@link SecurityManager#checkPermission checkPermission}
- * method is called with a
- * {@link RuntimePermission}("getenv.*")
- * permission. This may result in a {@link SecurityException} being
- * thrown.
+ * {@link SecurityManager#checkPermission checkPermission} method
+ * is called with a
+ * {@link RuntimePermission}{@code ("getenv.*")} permission.
+ * This may result in a {@link SecurityException} being thrown.
*
*
When passing information to a Java subprocess,
* system properties
- * are generally preferred over environment variables.
+ * are generally preferred over environment variables.
*
- * @return This process builder's environment
+ * @return this process builder's environment
*
- * @throws SecurityException
- * If a security manager exists and its
- * {@link SecurityManager#checkPermission checkPermission}
- * method doesn't allow access to the process environment
+ * @throws SecurityException
+ * if a security manager exists and its
+ * {@link SecurityManager#checkPermission checkPermission}
+ * method doesn't allow access to the process environment
*
- * @see Runtime#exec(String[],String[],java.io.File)
- * @see System#getenv()
+ * @see Runtime#exec(String[],String[],java.io.File)
+ * @see System#getenv()
*/
public Map environment() {
SecurityManager security = System.getSecurityManager();
@@ -328,12 +383,12 @@ public final class ProcessBuilder
*
* Subprocesses subsequently started by this object's {@link
* #start()} method will use this as their working directory.
- * The returned value may be null -- this means to use
+ * The returned value may be {@code null} -- this means to use
* the working directory of the current Java process, usually the
- * directory named by the system property user.dir,
- * as the working directory of the child process.
+ * directory named by the system property {@code user.dir},
+ * as the working directory of the child process.
*
- * @return This process builder's working directory
+ * @return this process builder's working directory
*/
public File directory() {
return directory;
@@ -344,50 +399,522 @@ public final class ProcessBuilder
*
* Subprocesses subsequently started by this object's {@link
* #start()} method will use this as their working directory.
- * The argument may be null -- this means to use the
+ * The argument may be {@code null} -- this means to use the
* working directory of the current Java process, usually the
- * directory named by the system property user.dir,
- * as the working directory of the child process.
+ * directory named by the system property {@code user.dir},
+ * as the working directory of the child process.
*
- * @param directory The new working directory
- * @return This process builder
+ * @param directory the new working directory
+ * @return this process builder
*/
public ProcessBuilder directory(File directory) {
this.directory = directory;
return this;
}
+ // ---------------- I/O Redirection ----------------
+
+ /**
+ * Implements a null input stream.
+ */
+ static class NullInputStream extends InputStream {
+ public int read() { return -1; }
+ public int available() { return 0; }
+ }
+
+ /**
+ * Implements a null output stream.
+ */
+ static class NullOutputStream extends OutputStream {
+ public void write(int b) throws IOException {
+ throw new IOException("Stream closed");
+ }
+ }
+
+ /**
+ * Represents a source of subprocess input or a destination of
+ * subprocess output.
+ *
+ * Each {@code Redirect} instance is one of the following:
+ *
+ *
+ * - the special value {@link #PIPE Redirect.PIPE}
+ *
- the special value {@link #INHERIT Redirect.INHERIT}
+ *
- a redirection to read from a file, created by an invocation of
+ * {@link Redirect#from Redirect.from(File)}
+ *
- a redirection to write to a file, created by an invocation of
+ * {@link Redirect#to Redirect.to(File)}
+ *
- a redirection to append to a file, created by an invocation of
+ * {@link Redirect#appendTo Redirect.appendTo(File)}
+ *
+ *
+ * Each of the above categories has an associated unique
+ * {@link Type Type}.
+ *
+ * @since 1.7
+ */
+ public static abstract class Redirect {
+ /**
+ * The type of a {@link Redirect}.
+ */
+ public enum Type {
+ /**
+ * The type of {@link Redirect#PIPE Redirect.PIPE}.
+ */
+ PIPE,
+
+ /**
+ * The type of {@link Redirect#INHERIT Redirect.INHERIT}.
+ */
+ INHERIT,
+
+ /**
+ * The type of redirects returned from
+ * {@link Redirect#from Redirect.from(File)}.
+ */
+ READ,
+
+ /**
+ * The type of redirects returned from
+ * {@link Redirect#to Redirect.to(File)}.
+ */
+ WRITE,
+
+ /**
+ * The type of redirects returned from
+ * {@link Redirect#appendTo Redirect.appendTo(File)}.
+ */
+ APPEND
+ };
+
+ /**
+ * Returns the type of this {@code Redirect}.
+ * @return the type of this {@code Redirect}
+ */
+ public abstract Type type();
+
+ /**
+ * Indicates that subprocess I/O will be connected to the
+ * current Java process over a pipe.
+ *
+ * This is the default handling of subprocess standard I/O.
+ *
+ *
It will always be true that
+ *
{@code
+ * Redirect.PIPE.file() == null &&
+ * Redirect.PIPE.type() == Redirect.Type.PIPE
+ * }
+ */
+ public static final Redirect PIPE = new Redirect() {
+ public Type type() { return Type.PIPE; }
+ public String toString() { return type().toString(); }};
+
+ /**
+ * Indicates that subprocess I/O source or destination will be the
+ * same as those of the current process. This is the normal
+ * behavior of most operating system command interpreters (shells).
+ *
+ * It will always be true that
+ *
{@code
+ * Redirect.INHERIT.file() == null &&
+ * Redirect.INHERIT.type() == Redirect.Type.INHERIT
+ * }
+ */
+ public static final Redirect INHERIT = new Redirect() {
+ public Type type() { return Type.INHERIT; }
+ public String toString() { return type().toString(); }};
+
+ /**
+ * Returns the {@link File} source or destination associated
+ * with this redirect, or {@code null} if there is no such file.
+ *
+ * @return the file associated with this redirect,
+ * or {@code null} if there is no such file
+ */
+ public File file() { return null; }
+
+ FileOutputStream toFileOutputStream() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Returns a redirect to read from the specified file.
+ *
+ * It will always be true that
+ *
{@code
+ * Redirect.from(file).file() == file &&
+ * Redirect.from(file).type() == Redirect.Type.READ
+ * }
+ *
+ * @throws NullPointerException if the specified file is null
+ * @return a redirect to read from the specified file
+ */
+ public static Redirect from(final File file) {
+ if (file == null)
+ throw new NullPointerException();
+ return new Redirect() {
+ public Type type() { return Type.READ; }
+ public File file() { return file; }
+ public String toString() {
+ return "redirect to read from file \"" + file + "\"";
+ }
+ };
+ }
+
+ /**
+ * Returns a redirect to write to the specified file.
+ * If the specified file exists when the subprocess is started,
+ * its previous contents will be discarded.
+ *
+ * It will always be true that
+ *
{@code
+ * Redirect.to(file).file() == file &&
+ * Redirect.to(file).type() == Redirect.Type.WRITE
+ * }
+ *
+ * @throws NullPointerException if the specified file is null
+ * @return a redirect to write to the specified file
+ */
+ public static Redirect to(final File file) {
+ if (file == null)
+ throw new NullPointerException();
+ return new Redirect() {
+ public Type type() { return Type.WRITE; }
+ public File file() { return file; }
+ public String toString() {
+ return "redirect to write to file \"" + file + "\"";
+ }
+ FileOutputStream toFileOutputStream() throws IOException {
+ return new FileOutputStream(file, false);
+ }
+ };
+ }
+
+ /**
+ * Returns a redirect to append to the specified file.
+ * Each write operation first advances the position to the
+ * end of the file and then writes the requested data.
+ * Whether the advancement of the position and the writing
+ * of the data are done in a single atomic operation is
+ * system-dependent and therefore unspecified.
+ *
+ * It will always be true that
+ *
{@code
+ * Redirect.appendTo(file).file() == file &&
+ * Redirect.appendTo(file).type() == Redirect.Type.APPEND
+ * }
+ *
+ * @throws NullPointerException if the specified file is null
+ * @return a redirect to append to the specified file
+ */
+ public static Redirect appendTo(final File file) {
+ if (file == null)
+ throw new NullPointerException();
+ return new Redirect() {
+ public Type type() { return Type.APPEND; }
+ public File file() { return file; }
+ public String toString() {
+ return "redirect to append to file \"" + file + "\"";
+ }
+ FileOutputStream toFileOutputStream() throws IOException {
+ return new FileOutputStream(file, true);
+ }
+ };
+ }
+
+ /**
+ * Compares the specified object with this {@code Redirect} for
+ * equality. Returns {@code true} if and only if the two
+ * objects are identical or both objects are {@code Redirect}
+ * instances of the same type associated with non-null equal
+ * {@code File} instances.
+ */
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+ if (! (obj instanceof Redirect))
+ return false;
+ Redirect r = (Redirect) obj;
+ if (r.type() != this.type())
+ return false;
+ assert this.file() != null;
+ return this.file().equals(r.file());
+ }
+
+ /**
+ * Returns a hash code value for this {@code Redirect}.
+ * @return a hash code value for this {@code Redirect}
+ */
+ public int hashCode() {
+ File file = file();
+ if (file == null)
+ return super.hashCode();
+ else
+ return file.hashCode();
+ }
+
+ /**
+ * No public constructors. Clients must use predefined
+ * static {@code Redirect} instances or factory methods.
+ */
+ private Redirect() {}
+ }
+
+ private Redirect[] redirects() {
+ if (redirects == null)
+ redirects = new Redirect[] {
+ Redirect.PIPE, Redirect.PIPE, Redirect.PIPE
+ };
+ return redirects;
+ }
+
+ /**
+ * Sets this process builder's standard input source.
+ *
+ * Subprocesses subsequently started by this object's {@link #start()}
+ * method obtain their standard input from this source.
+ *
+ * If the source is {@link Redirect#PIPE Redirect.PIPE}
+ * (the initial value), then the standard input of a
+ * subprocess can be written to using the output stream
+ * returned by {@link Process#getOutputStream()}.
+ * If the source is set to any other value, then
+ * {@link Process#getOutputStream()} will return a
+ * null output stream.
+ *
+ * @param source the new standard input source
+ * @return this process builder
+ * @throws IllegalArgumentException
+ * if the redirect does not correspond to a valid source
+ * of data, that is, has type
+ * {@link Redirect.Type#WRITE WRITE} or
+ * {@link Redirect.Type#APPEND APPEND}
+ * @since 1.7
+ */
+ public ProcessBuilder redirectInput(Redirect source) {
+ if (source.type() == Redirect.Type.WRITE ||
+ source.type() == Redirect.Type.APPEND)
+ throw new IllegalArgumentException(
+ "Redirect invalid for reading: " + source);
+ redirects()[0] = source;
+ return this;
+ }
+
+ /**
+ * Sets this process builder's standard output destination.
+ *
+ * Subprocesses subsequently started by this object's {@link #start()}
+ * method send their standard output to this destination.
+ *
+ *
If the destination is {@link Redirect#PIPE Redirect.PIPE}
+ * (the initial value), then the standard output of a subprocess
+ * can be read using the input stream returned by {@link
+ * Process#getInputStream()}.
+ * If the destination is set to any other value, then
+ * {@link Process#getInputStream()} will return a
+ * null input stream.
+ *
+ * @param destination the new standard output destination
+ * @return this process builder
+ * @throws IllegalArgumentException
+ * if the redirect does not correspond to a valid
+ * destination of data, that is, has type
+ * {@link Redirect.Type#READ READ}
+ * @since 1.7
+ */
+ public ProcessBuilder redirectOutput(Redirect destination) {
+ if (destination.type() == Redirect.Type.READ)
+ throw new IllegalArgumentException(
+ "Redirect invalid for writing: " + destination);
+ redirects()[1] = destination;
+ return this;
+ }
+
+ /**
+ * Sets this process builder's standard error destination.
+ *
+ * Subprocesses subsequently started by this object's {@link #start()}
+ * method send their standard error to this destination.
+ *
+ *
If the destination is {@link Redirect#PIPE Redirect.PIPE}
+ * (the initial value), then the error output of a subprocess
+ * can be read using the input stream returned by {@link
+ * Process#getErrorStream()}.
+ * If the destination is set to any other value, then
+ * {@link Process#getErrorStream()} will return a
+ * null input stream.
+ *
+ *
If the {@link #redirectErrorStream redirectErrorStream}
+ * attribute has been set {@code true}, then the redirection set
+ * by this method has no effect.
+ *
+ * @param destination the new standard error destination
+ * @return this process builder
+ * @throws IllegalArgumentException
+ * if the redirect does not correspond to a valid
+ * destination of data, that is, has type
+ * {@link Redirect.Type#READ READ}
+ * @since 1.7
+ */
+ public ProcessBuilder redirectError(Redirect destination) {
+ if (destination.type() == Redirect.Type.READ)
+ throw new IllegalArgumentException(
+ "Redirect invalid for writing: " + destination);
+ redirects()[2] = destination;
+ return this;
+ }
+
+ /**
+ * Sets this process builder's standard input source to a file.
+ *
+ *
This is a convenience method. An invocation of the form
+ * {@code redirectInput(file)}
+ * behaves in exactly the same way as the invocation
+ * {@link #redirectInput(Redirect) redirectInput}
+ * {@code (Redirect.from(file))}.
+ *
+ * @param file the new standard input source
+ * @return this process builder
+ * @since 1.7
+ */
+ public ProcessBuilder redirectInput(File file) {
+ return redirectInput(Redirect.from(file));
+ }
+
+ /**
+ * Sets this process builder's standard output destination to a file.
+ *
+ *
This is a convenience method. An invocation of the form
+ * {@code redirectOutput(file)}
+ * behaves in exactly the same way as the invocation
+ * {@link #redirectOutput(Redirect) redirectOutput}
+ * {@code (Redirect.to(file))}.
+ *
+ * @param file the new standard output destination
+ * @return this process builder
+ * @since 1.7
+ */
+ public ProcessBuilder redirectOutput(File file) {
+ return redirectOutput(Redirect.to(file));
+ }
+
+ /**
+ * Sets this process builder's standard error destination to a file.
+ *
+ *
This is a convenience method. An invocation of the form
+ * {@code redirectError(file)}
+ * behaves in exactly the same way as the invocation
+ * {@link #redirectError(Redirect) redirectError}
+ * {@code (Redirect.to(file))}.
+ *
+ * @param file the new standard error destination
+ * @return this process builder
+ * @since 1.7
+ */
+ public ProcessBuilder redirectError(File file) {
+ return redirectError(Redirect.to(file));
+ }
+
+ /**
+ * Returns this process builder's standard input source.
+ *
+ * Subprocesses subsequently started by this object's {@link #start()}
+ * method obtain their standard input from this source.
+ * The initial value is {@link Redirect#PIPE Redirect.PIPE}.
+ *
+ * @return this process builder's standard input source
+ * @since 1.7
+ */
+ public Redirect redirectInput() {
+ return (redirects == null) ? Redirect.PIPE : redirects[0];
+ }
+
+ /**
+ * Returns this process builder's standard output destination.
+ *
+ * Subprocesses subsequently started by this object's {@link #start()}
+ * method redirect their standard output to this destination.
+ * The initial value is {@link Redirect#PIPE Redirect.PIPE}.
+ *
+ * @return this process builder's standard output destination
+ * @since 1.7
+ */
+ public Redirect redirectOutput() {
+ return (redirects == null) ? Redirect.PIPE : redirects[1];
+ }
+
+ /**
+ * Returns this process builder's standard error destination.
+ *
+ * Subprocesses subsequently started by this object's {@link #start()}
+ * method redirect their standard error to this destination.
+ * The initial value is {@link Redirect#PIPE Redirect.PIPE}.
+ *
+ * @return this process builder's standard error destination
+ * @since 1.7
+ */
+ public Redirect redirectError() {
+ return (redirects == null) ? Redirect.PIPE : redirects[2];
+ }
+
+ /**
+ * Sets the source and destination for subprocess standard I/O
+ * to be the same as those of the current Java process.
+ *
+ *
This is a convenience method. An invocation of the form
+ *
{@code
+ * pb.inheritIO()
+ * }
+ * behaves in exactly the same way as the invocation
+ * {@code
+ * pb.redirectInput(Redirect.INHERIT)
+ * .redirectOutput(Redirect.INHERIT)
+ * .redirectError(Redirect.INHERIT)
+ * }
+ *
+ * This gives behavior equivalent to most operating system
+ * command interpreters, or the standard C library function
+ * {@code system()}.
+ *
+ * @return this process builder
+ * @since 1.7
+ */
+ public ProcessBuilder inheritIO() {
+ Arrays.fill(redirects(), Redirect.INHERIT);
+ return this;
+ }
+
/**
* Tells whether this process builder merges standard error and
* standard output.
*
- * If this property is true, then any error output
+ *
If this property is {@code true}, then any error output
* generated by subprocesses subsequently started by this object's
* {@link #start()} method will be merged with the standard
* output, so that both can be read using the
* {@link Process#getInputStream()} method. This makes it easier
* to correlate error messages with the corresponding output.
- * The initial value is false.
+ * The initial value is {@code false}.
*
- * @return This process builder's redirectErrorStream property
+ * @return this process builder's {@code redirectErrorStream} property
*/
public boolean redirectErrorStream() {
return redirectErrorStream;
}
/**
- * Sets this process builder's redirectErrorStream property.
+ * Sets this process builder's {@code redirectErrorStream} property.
*
- * If this property is true, then any error output
+ *
If this property is {@code true}, then any error output
* generated by subprocesses subsequently started by this object's
* {@link #start()} method will be merged with the standard
* output, so that both can be read using the
* {@link Process#getInputStream()} method. This makes it easier
* to correlate error messages with the corresponding output.
- * The initial value is false.
+ * The initial value is {@code false}.
*
- * @param redirectErrorStream The new property value
- * @return This process builder
+ * @param redirectErrorStream the new property value
+ * @return this process builder
*/
public ProcessBuilder redirectErrorStream(boolean redirectErrorStream) {
this.redirectErrorStream = redirectErrorStream;
@@ -410,7 +937,7 @@ public final class ProcessBuilder
* If there is a security manager, its
* {@link SecurityManager#checkExec checkExec}
* method is called with the first component of this object's
- * command array as its argument. This may result in
+ * {@code command} array as its argument. This may result in
* a {@link SecurityException} being thrown.
*
*
Starting an operating system process is highly system-dependent.
@@ -426,26 +953,42 @@ public final class ProcessBuilder
* subclass of {@link IOException}.
*
*
Subsequent modifications to this process builder will not
- * affect the returned {@link Process}.
+ * affect the returned {@link Process}.
*
- * @return A new {@link Process} object for managing the subprocess
+ * @return a new {@link Process} object for managing the subprocess
*
- * @throws NullPointerException
- * If an element of the command list is null
+ * @throws NullPointerException
+ * if an element of the command list is null
*
- * @throws IndexOutOfBoundsException
- * If the command is an empty list (has size 0)
+ * @throws IndexOutOfBoundsException
+ * if the command is an empty list (has size {@code 0})
*
- * @throws SecurityException
- * If a security manager exists and its
- * {@link SecurityManager#checkExec checkExec}
- * method doesn't allow creation of the subprocess
+ * @throws SecurityException
+ * if a security manager exists and
+ *
*
- * @throws IOException
- * If an I/O error occurs
+ * - its
+ * {@link SecurityManager#checkExec checkExec}
+ * method doesn't allow creation of the subprocess, or
*
- * @see Runtime#exec(String[], String[], java.io.File)
- * @see SecurityManager#checkExec(String)
+ *
- the standard input to the subprocess was
+ * {@linkplain #redirectInput redirected from a file}
+ * and the security manager's
+ * {@link SecurityManager#checkRead checkRead} method
+ * denies read access to the file, or
+ *
+ *
- the standard output or standard error of the
+ * subprocess was
+ * {@linkplain #redirectOutput redirected to a file}
+ * and the security manager's
+ * {@link SecurityManager#checkWrite checkWrite} method
+ * denies write access to the file
+ *
+ *
+ *
+ * @throws IOException if an I/O error occurs
+ *
+ * @see Runtime#exec(String[], String[], java.io.File)
*/
public Process start() throws IOException {
// Must convert to array first -- a malicious user-supplied
@@ -467,6 +1010,7 @@ public final class ProcessBuilder
return ProcessImpl.start(cmdarray,
environment,
dir,
+ redirects,
redirectErrorStream);
} catch (IOException e) {
// It's much easier for us to create a high-quality error
diff --git a/jdk/src/share/classes/sun/misc/JavaIOFileDescriptorAccess.java b/jdk/src/share/classes/sun/misc/JavaIOFileDescriptorAccess.java
index 874145c6290..42f3ea1ae66 100644
--- a/jdk/src/share/classes/sun/misc/JavaIOFileDescriptorAccess.java
+++ b/jdk/src/share/classes/sun/misc/JavaIOFileDescriptorAccess.java
@@ -33,4 +33,8 @@ import java.io.FileDescriptor;
public interface JavaIOFileDescriptorAccess {
public void set(FileDescriptor obj, int fd);
public int get(FileDescriptor fd);
+
+ // Only valid on Windows
+ public void setHandle(FileDescriptor obj, long handle);
+ public long getHandle(FileDescriptor obj);
}
diff --git a/jdk/src/solaris/classes/java/io/FileDescriptor.java b/jdk/src/solaris/classes/java/io/FileDescriptor.java
index fdd1d143b82..ef8aa1c4602 100644
--- a/jdk/src/solaris/classes/java/io/FileDescriptor.java
+++ b/jdk/src/solaris/classes/java/io/FileDescriptor.java
@@ -152,11 +152,19 @@ public final class FileDescriptor {
public int get(FileDescriptor obj) {
return obj.fd;
}
+
+ public void setHandle(FileDescriptor obj, long handle) {
+ throw new UnsupportedOperationException();
+ }
+
+ public long getHandle(FileDescriptor obj) {
+ throw new UnsupportedOperationException();
+ }
}
);
}
- // pacakge private methods used by FIS,FOS and RAF
+ // package private methods used by FIS, FOS and RAF
int incrementAndGetUseCount() {
return useCount.incrementAndGet();
diff --git a/jdk/src/solaris/classes/java/lang/ProcessImpl.java b/jdk/src/solaris/classes/java/lang/ProcessImpl.java
index d7bdbe19117..b9074349efa 100644
--- a/jdk/src/solaris/classes/java/lang/ProcessImpl.java
+++ b/jdk/src/solaris/classes/java/lang/ProcessImpl.java
@@ -26,7 +26,10 @@
package java.lang;
import java.io.IOException;
-import java.lang.Process;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.lang.ProcessBuilder.Redirect;
+import java.lang.ProcessBuilder.Redirect;
/**
* This class is for the exclusive use of ProcessBuilder.start() to
@@ -36,6 +39,9 @@ import java.lang.Process;
* @since 1.5
*/
final class ProcessImpl {
+ private static final sun.misc.JavaIOFileDescriptorAccess fdAccess
+ = sun.misc.SharedSecrets.getJavaIOFileDescriptorAccess();
+
private ProcessImpl() {} // Not instantiable
private static byte[] toCString(String s) {
@@ -54,6 +60,7 @@ final class ProcessImpl {
static Process start(String[] cmdarray,
java.util.Map environment,
String dir,
+ ProcessBuilder.Redirect[] redirects,
boolean redirectErrorStream)
throws IOException
{
@@ -78,11 +85,61 @@ final class ProcessImpl {
int[] envc = new int[1];
byte[] envBlock = ProcessEnvironment.toEnvironmentBlock(environment, envc);
+ int[] std_fds;
+
+ FileInputStream f0 = null;
+ FileOutputStream f1 = null;
+ FileOutputStream f2 = null;
+
+ try {
+ if (redirects == null) {
+ std_fds = new int[] { -1, -1, -1 };
+ } else {
+ std_fds = new int[3];
+
+ if (redirects[0] == Redirect.PIPE)
+ std_fds[0] = -1;
+ else if (redirects[0] == Redirect.INHERIT)
+ std_fds[0] = 0;
+ else {
+ f0 = new FileInputStream(redirects[0].file());
+ std_fds[0] = fdAccess.get(f0.getFD());
+ }
+
+ if (redirects[1] == Redirect.PIPE)
+ std_fds[1] = -1;
+ else if (redirects[1] == Redirect.INHERIT)
+ std_fds[1] = 1;
+ else {
+ f1 = redirects[1].toFileOutputStream();
+ std_fds[1] = fdAccess.get(f1.getFD());
+ }
+
+ if (redirects[2] == Redirect.PIPE)
+ std_fds[2] = -1;
+ else if (redirects[2] == Redirect.INHERIT)
+ std_fds[2] = 2;
+ else {
+ f2 = redirects[2].toFileOutputStream();
+ std_fds[2] = fdAccess.get(f2.getFD());
+ }
+ }
+
return new UNIXProcess
(toCString(cmdarray[0]),
argBlock, args.length,
envBlock, envc[0],
toCString(dir),
+ std_fds,
redirectErrorStream);
+ } finally {
+ // In theory, close() can throw IOException
+ // (although it is rather unlikely to happen here)
+ try { if (f0 != null) f0.close(); }
+ finally {
+ try { if (f1 != null) f1.close(); }
+ finally { if (f2 != null) f2.close(); }
+ }
+ }
}
}
diff --git a/jdk/src/solaris/classes/java/lang/UNIXProcess.java.linux b/jdk/src/solaris/classes/java/lang/UNIXProcess.java.linux
index ded83065eb7..9fc9e9da645 100644
--- a/jdk/src/solaris/classes/java/lang/UNIXProcess.java.linux
+++ b/jdk/src/solaris/classes/java/lang/UNIXProcess.java.linux
@@ -1,5 +1,5 @@
-/*
- * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
+/*
+ * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -34,9 +34,9 @@ import java.io.*;
*/
final class UNIXProcess extends Process {
- private FileDescriptor stdin_fd;
- private FileDescriptor stdout_fd;
- private FileDescriptor stderr_fd;
+ private static final sun.misc.JavaIOFileDescriptorAccess fdAccess
+ = sun.misc.SharedSecrets.getJavaIOFileDescriptorAccess();
+
private int pid;
private int exitcode;
private boolean hasExited;
@@ -48,15 +48,26 @@ final class UNIXProcess extends Process {
/* this is for the reaping thread */
private native int waitForProcessExit(int pid);
+ /**
+ * Create a process using fork(2) and exec(2).
+ *
+ * @param std_fds array of file descriptors. Indexes 0, 1, and
+ * 2 correspond to standard input, standard output and
+ * standard error, respectively. On input, a value of -1
+ * means to create a pipe to connect child and parent
+ * processes. On output, a value which is not -1 is the
+ * parent pipe fd corresponding to the pipe which has
+ * been created. An element of this array is -1 on input
+ * if and only if it is not -1 on output.
+ * @return the pid of the subprocess
+ */
private native int forkAndExec(byte[] prog,
- byte[] argBlock, int argc,
- byte[] envBlock, int envc,
- byte[] dir,
- boolean redirectErrorStream,
- FileDescriptor stdin_fd,
- FileDescriptor stdout_fd,
- FileDescriptor stderr_fd)
- throws IOException;
+ byte[] argBlock, int argc,
+ byte[] envBlock, int envc,
+ byte[] dir,
+ int[] std_fds,
+ boolean redirectErrorStream)
+ throws IOException;
/* In the process constructor we wait on this gate until the process */
/* has been created. Then we return from the constructor. */
@@ -97,67 +108,82 @@ final class UNIXProcess extends Process {
}
UNIXProcess(final byte[] prog,
- final byte[] argBlock, final int argc,
- final byte[] envBlock, final int envc,
- final byte[] dir,
- final boolean redirectErrorStream)
+ final byte[] argBlock, final int argc,
+ final byte[] envBlock, final int envc,
+ final byte[] dir,
+ final int[] std_fds,
+ final boolean redirectErrorStream)
throws IOException {
- stdin_fd = new FileDescriptor();
- stdout_fd = new FileDescriptor();
- stderr_fd = new FileDescriptor();
final Gate gate = new Gate();
- /*
- * For each subprocess forked a corresponding reaper thread
- * is started. That thread is the only thread which waits
- * for the subprocess to terminate and it doesn't hold any
- * locks while doing so. This design allows waitFor() and
- * exitStatus() to be safely executed in parallel (and they
- * need no native code).
- */
+ /*
+ * For each subprocess forked a corresponding reaper thread
+ * is started. That thread is the only thread which waits
+ * for the subprocess to terminate and it doesn't hold any
+ * locks while doing so. This design allows waitFor() and
+ * exitStatus() to be safely executed in parallel (and they
+ * need no native code).
+ */
- java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction() {
- public Object run() {
- Thread t = new Thread("process reaper") {
- public void run() {
+ java.security.AccessController.doPrivileged(
+ new java.security.PrivilegedAction() {
+ public Void run() {
+ Thread t = new Thread("process reaper") {
+ public void run() {
try {
pid = forkAndExec(prog,
- argBlock, argc,
- envBlock, envc,
- dir,
- redirectErrorStream,
- stdin_fd, stdout_fd, stderr_fd);
+ argBlock, argc,
+ envBlock, envc,
+ dir,
+ std_fds,
+ redirectErrorStream);
} catch (IOException e) {
gate.setException(e); /*remember to rethrow later*/
gate.exit();
return;
}
java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction() {
- public Object run() {
- stdin_stream = new BufferedOutputStream(new
- FileOutputStream(stdin_fd));
- stdout_stream = new BufferedInputStream(new
- FileInputStream(stdout_fd));
- stderr_stream = new FileInputStream(stderr_fd);
- return null;
+ new java.security.PrivilegedAction() {
+ public Void run() {
+ if (std_fds[0] == -1)
+ stdin_stream = new ProcessBuilder.NullOutputStream();
+ else {
+ FileDescriptor stdin_fd = new FileDescriptor();
+ fdAccess.set(stdin_fd, std_fds[0]);
+ stdin_stream = new BufferedOutputStream(
+ new FileOutputStream(stdin_fd));
}
- });
+
+ if (std_fds[1] == -1)
+ stdout_stream = new ProcessBuilder.NullInputStream();
+ else {
+ FileDescriptor stdout_fd = new FileDescriptor();
+ fdAccess.set(stdout_fd, std_fds[1]);
+ stdout_stream = new BufferedInputStream(
+ new FileInputStream(stdout_fd));
+ }
+
+ if (std_fds[2] == -1)
+ stderr_stream = new ProcessBuilder.NullInputStream();
+ else {
+ FileDescriptor stderr_fd = new FileDescriptor();
+ fdAccess.set(stderr_fd, std_fds[2]);
+ stderr_stream = new FileInputStream(stderr_fd);
+ }
+
+ return null; }});
gate.exit(); /* exit from constructor */
- int res = waitForProcessExit(pid);
- synchronized (UNIXProcess.this) {
- hasExited = true;
- exitcode = res;
- UNIXProcess.this.notifyAll();
- }
- }
- };
+ int res = waitForProcessExit(pid);
+ synchronized (UNIXProcess.this) {
+ hasExited = true;
+ exitcode = res;
+ UNIXProcess.this.notifyAll();
+ }
+ }
+ };
t.setDaemon(true);
t.start();
- return null;
- }
- });
+ return null; }});
gate.waitForExit();
IOException e = gate.getException();
if (e != null)
@@ -165,43 +191,43 @@ final class UNIXProcess extends Process {
}
public OutputStream getOutputStream() {
- return stdin_stream;
+ return stdin_stream;
}
public InputStream getInputStream() {
- return stdout_stream;
+ return stdout_stream;
}
public InputStream getErrorStream() {
- return stderr_stream;
+ return stderr_stream;
}
public synchronized int waitFor() throws InterruptedException {
while (!hasExited) {
- wait();
- }
- return exitcode;
+ wait();
+ }
+ return exitcode;
}
public synchronized int exitValue() {
- if (!hasExited) {
- throw new IllegalThreadStateException("process hasn't exited");
- }
- return exitcode;
+ if (!hasExited) {
+ throw new IllegalThreadStateException("process hasn't exited");
+ }
+ return exitcode;
}
private static native void destroyProcess(int pid);
public void destroy() {
- // There is a risk that pid will be recycled, causing us to
- // kill the wrong process! So we only terminate processes
- // that appear to still be running. Even with this check,
- // there is an unavoidable race condition here, but the window
- // is very small, and OSes try hard to not recycle pids too
- // soon, so this is quite safe.
- synchronized (this) {
- if (!hasExited)
- destroyProcess(pid);
- }
+ // There is a risk that pid will be recycled, causing us to
+ // kill the wrong process! So we only terminate processes
+ // that appear to still be running. Even with this check,
+ // there is an unavoidable race condition here, but the window
+ // is very small, and OSes try hard to not recycle pids too
+ // soon, so this is quite safe.
+ synchronized (this) {
+ if (!hasExited)
+ destroyProcess(pid);
+ }
try {
stdin_stream.close();
stdout_stream.close();
@@ -215,6 +241,6 @@ final class UNIXProcess extends Process {
private static native void initIDs();
static {
- initIDs();
+ initIDs();
}
}
diff --git a/jdk/src/solaris/classes/java/lang/UNIXProcess.java.solaris b/jdk/src/solaris/classes/java/lang/UNIXProcess.java.solaris
index ae29a09e562..f47d1043175 100644
--- a/jdk/src/solaris/classes/java/lang/UNIXProcess.java.solaris
+++ b/jdk/src/solaris/classes/java/lang/UNIXProcess.java.solaris
@@ -1,5 +1,5 @@
-/*
- * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
+/*
+ * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -33,129 +33,155 @@ import java.io.*;
*/
final class UNIXProcess extends Process {
- private FileDescriptor stdin_fd;
- private FileDescriptor stdout_fd;
- private FileDescriptor stderr_fd;
- private int pid;
+ private static final sun.misc.JavaIOFileDescriptorAccess fdAccess
+ = sun.misc.SharedSecrets.getJavaIOFileDescriptorAccess();
+
+ private final int pid;
private int exitcode;
private boolean hasExited;
private OutputStream stdin_stream;
- private BufferedInputStream stdout_stream;
+ private InputStream stdout_stream;
private DeferredCloseInputStream stdout_inner_stream;
- private DeferredCloseInputStream stderr_stream;
+ private InputStream stderr_stream;
/* this is for the reaping thread */
private native int waitForProcessExit(int pid);
+ /**
+ * Create a process using fork(2) and exec(2).
+ *
+ * @param std_fds array of file descriptors. Indexes 0, 1, and
+ * 2 correspond to standard input, standard output and
+ * standard error, respectively. On input, a value of -1
+ * means to create a pipe to connect child and parent
+ * processes. On output, a value which is not -1 is the
+ * parent pipe fd corresponding to the pipe which has
+ * been created. An element of this array is -1 on input
+ * if and only if it is not -1 on output.
+ * @return the pid of the subprocess
+ */
private native int forkAndExec(byte[] prog,
- byte[] argBlock, int argc,
- byte[] envBlock, int envc,
- byte[] dir,
- boolean redirectErrorStream,
- FileDescriptor stdin_fd,
- FileDescriptor stdout_fd,
- FileDescriptor stderr_fd)
- throws IOException;
+ byte[] argBlock, int argc,
+ byte[] envBlock, int envc,
+ byte[] dir,
+ int[] std_fds,
+ boolean redirectErrorStream)
+ throws IOException;
UNIXProcess(final byte[] prog,
- final byte[] argBlock, int argc,
- final byte[] envBlock, int envc,
- final byte[] dir,
- final boolean redirectErrorStream)
+ final byte[] argBlock, int argc,
+ final byte[] envBlock, int envc,
+ final byte[] dir,
+ final int[] std_fds,
+ final boolean redirectErrorStream)
throws IOException {
- stdin_fd = new FileDescriptor();
- stdout_fd = new FileDescriptor();
- stderr_fd = new FileDescriptor();
+ pid = forkAndExec(prog,
+ argBlock, argc,
+ envBlock, envc,
+ dir,
+ std_fds,
+ redirectErrorStream);
- pid = forkAndExec(prog,
- argBlock, argc,
- envBlock, envc,
- dir,
- redirectErrorStream,
- stdin_fd, stdout_fd, stderr_fd);
+ java.security.AccessController.doPrivileged(
+ new java.security.PrivilegedAction() { public Void run() {
+ if (std_fds[0] == -1)
+ stdin_stream = new ProcessBuilder.NullOutputStream();
+ else {
+ FileDescriptor stdin_fd = new FileDescriptor();
+ fdAccess.set(stdin_fd, std_fds[0]);
+ stdin_stream = new BufferedOutputStream(
+ new FileOutputStream(stdin_fd));
+ }
- java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction() {
- public Object run() {
- stdin_stream
- = new BufferedOutputStream(new FileOutputStream(stdin_fd));
- stdout_inner_stream = new DeferredCloseInputStream(stdout_fd);
- stdout_stream = new BufferedInputStream(stdout_inner_stream);
- stderr_stream = new DeferredCloseInputStream(stderr_fd);
- return null;
- }
- });
+ if (std_fds[1] == -1)
+ stdout_stream = new ProcessBuilder.NullInputStream();
+ else {
+ FileDescriptor stdout_fd = new FileDescriptor();
+ fdAccess.set(stdout_fd, std_fds[1]);
+ stdout_inner_stream = new DeferredCloseInputStream(stdout_fd);
+ stdout_stream = new BufferedInputStream(stdout_inner_stream);
+ }
- /*
- * For each subprocess forked a corresponding reaper thread
- * is started. That thread is the only thread which waits
- * for the subprocess to terminate and it doesn't hold any
- * locks while doing so. This design allows waitFor() and
- * exitStatus() to be safely executed in parallel (and they
- * need no native code).
- */
+ if (std_fds[2] == -1)
+ stderr_stream = new ProcessBuilder.NullInputStream();
+ else {
+ FileDescriptor stderr_fd = new FileDescriptor();
+ fdAccess.set(stderr_fd, std_fds[2]);
+ stderr_stream = new DeferredCloseInputStream(stderr_fd);
+ }
- java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction() {
- public Object run() {
- Thread t = new Thread("process reaper") {
- public void run() {
- int res = waitForProcessExit(pid);
- synchronized (UNIXProcess.this) {
- hasExited = true;
- exitcode = res;
- UNIXProcess.this.notifyAll();
- }
- }
- };
- t.setDaemon(true);
- t.start();
- return null;
- }
- });
+ return null; }});
+
+ /*
+ * For each subprocess forked a corresponding reaper thread
+ * is started. That thread is the only thread which waits
+ * for the subprocess to terminate and it doesn't hold any
+ * locks while doing so. This design allows waitFor() and
+ * exitStatus() to be safely executed in parallel (and they
+ * need no native code).
+ */
+
+ java.security.AccessController.doPrivileged(
+ new java.security.PrivilegedAction() { public Void run() {
+ Thread t = new Thread("process reaper") {
+ public void run() {
+ int res = waitForProcessExit(pid);
+ synchronized (UNIXProcess.this) {
+ hasExited = true;
+ exitcode = res;
+ UNIXProcess.this.notifyAll();
+ }
+ }
+ };
+ t.setDaemon(true);
+ t.start();
+ return null; }});
}
public OutputStream getOutputStream() {
- return stdin_stream;
+ return stdin_stream;
}
public InputStream getInputStream() {
- return stdout_stream;
+ return stdout_stream;
}
public InputStream getErrorStream() {
- return stderr_stream;
+ return stderr_stream;
}
public synchronized int waitFor() throws InterruptedException {
while (!hasExited) {
- wait();
- }
- return exitcode;
+ wait();
+ }
+ return exitcode;
}
public synchronized int exitValue() {
- if (!hasExited) {
- throw new IllegalThreadStateException("process hasn't exited");
- }
- return exitcode;
+ if (!hasExited) {
+ throw new IllegalThreadStateException("process hasn't exited");
+ }
+ return exitcode;
}
private static native void destroyProcess(int pid);
public synchronized void destroy() {
- // There is a risk that pid will be recycled, causing us to
- // kill the wrong process! So we only terminate processes
- // that appear to still be running. Even with this check,
- // there is an unavoidable race condition here, but the window
- // is very small, and OSes try hard to not recycle pids too
- // soon, so this is quite safe.
- if (!hasExited)
- destroyProcess(pid);
- try {
+ // There is a risk that pid will be recycled, causing us to
+ // kill the wrong process! So we only terminate processes
+ // that appear to still be running. Even with this check,
+ // there is an unavoidable race condition here, but the window
+ // is very small, and OSes try hard to not recycle pids too
+ // soon, so this is quite safe.
+ if (!hasExited)
+ destroyProcess(pid);
+ try {
stdin_stream.close();
- stdout_inner_stream.closeDeferred(stdout_stream);
- stderr_stream.closeDeferred(stderr_stream);
+ if (stdout_inner_stream != null)
+ stdout_inner_stream.closeDeferred(stdout_stream);
+ if (stderr_stream instanceof DeferredCloseInputStream)
+ ((DeferredCloseInputStream) stderr_stream)
+ .closeDeferred(stderr_stream);
} catch (IOException e) {
// ignore
}
@@ -172,99 +198,99 @@ final class UNIXProcess extends Process {
// (EOF) as they did before.
//
private static class DeferredCloseInputStream
- extends FileInputStream
+ extends FileInputStream
{
- private DeferredCloseInputStream(FileDescriptor fd) {
- super(fd);
- }
+ private DeferredCloseInputStream(FileDescriptor fd) {
+ super(fd);
+ }
- private Object lock = new Object(); // For the following fields
- private boolean closePending = false;
- private int useCount = 0;
- private InputStream streamToClose;
+ private Object lock = new Object(); // For the following fields
+ private boolean closePending = false;
+ private int useCount = 0;
+ private InputStream streamToClose;
- private void raise() {
- synchronized (lock) {
- useCount++;
- }
- }
+ private void raise() {
+ synchronized (lock) {
+ useCount++;
+ }
+ }
- private void lower() throws IOException {
- synchronized (lock) {
- useCount--;
- if (useCount == 0 && closePending) {
- streamToClose.close();
- }
- }
- }
+ private void lower() throws IOException {
+ synchronized (lock) {
+ useCount--;
+ if (useCount == 0 && closePending) {
+ streamToClose.close();
+ }
+ }
+ }
- // stc is the actual stream to be closed; it might be this object, or
- // it might be an upstream object for which this object is downstream.
- //
- private void closeDeferred(InputStream stc) throws IOException {
- synchronized (lock) {
- if (useCount == 0) {
- stc.close();
- } else {
- closePending = true;
- streamToClose = stc;
- }
- }
- }
+ // stc is the actual stream to be closed; it might be this object, or
+ // it might be an upstream object for which this object is downstream.
+ //
+ private void closeDeferred(InputStream stc) throws IOException {
+ synchronized (lock) {
+ if (useCount == 0) {
+ stc.close();
+ } else {
+ closePending = true;
+ streamToClose = stc;
+ }
+ }
+ }
- public void close() throws IOException {
- synchronized (lock) {
- useCount = 0;
- closePending = false;
- }
- super.close();
- }
+ public void close() throws IOException {
+ synchronized (lock) {
+ useCount = 0;
+ closePending = false;
+ }
+ super.close();
+ }
- public int read() throws IOException {
- raise();
- try {
- return super.read();
- } finally {
- lower();
- }
- }
+ public int read() throws IOException {
+ raise();
+ try {
+ return super.read();
+ } finally {
+ lower();
+ }
+ }
- public int read(byte[] b) throws IOException {
- raise();
- try {
- return super.read(b);
- } finally {
- lower();
- }
- }
+ public int read(byte[] b) throws IOException {
+ raise();
+ try {
+ return super.read(b);
+ } finally {
+ lower();
+ }
+ }
- public int read(byte[] b, int off, int len) throws IOException {
- raise();
- try {
- return super.read(b, off, len);
- } finally {
- lower();
- }
- }
+ public int read(byte[] b, int off, int len) throws IOException {
+ raise();
+ try {
+ return super.read(b, off, len);
+ } finally {
+ lower();
+ }
+ }
- public long skip(long n) throws IOException {
- raise();
- try {
- return super.skip(n);
- } finally {
- lower();
- }
- }
+ public long skip(long n) throws IOException {
+ raise();
+ try {
+ return super.skip(n);
+ } finally {
+ lower();
+ }
+ }
- public int available() throws IOException {
- raise();
- try {
- return super.available();
- } finally {
- lower();
- }
- }
+ public int available() throws IOException {
+ raise();
+ try {
+ return super.available();
+ } finally {
+ lower();
+ }
+ }
}
@@ -272,6 +298,6 @@ final class UNIXProcess extends Process {
private static native void initIDs();
static {
- initIDs();
+ initIDs();
}
}
diff --git a/jdk/src/solaris/native/java/lang/UNIXProcess_md.c b/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
index a14496e7456..480298cde58 100644
--- a/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
+++ b/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -491,10 +491,8 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
jbyteArray argBlock, jint argc,
jbyteArray envBlock, jint envc,
jbyteArray dir,
- jboolean redirectErrorStream,
- jobject stdin_fd,
- jobject stdout_fd,
- jobject stderr_fd)
+ jintArray std_fds,
+ jboolean redirectErrorStream)
{
int errnum;
int resultPid = -1;
@@ -505,6 +503,7 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
const char *pargBlock = getBytes(env, argBlock);
const char *penvBlock = getBytes(env, envBlock);
const char *pdir = getBytes(env, dir);
+ jint *fds = NULL;
in[0] = in[1] = out[0] = out[1] = err[0] = err[1] = fail[0] = fail[1] = -1;
@@ -527,9 +526,13 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
initVectorFromBlock(envv, penvBlock, envc);
}
- if ((pipe(in) < 0) ||
- (pipe(out) < 0) ||
- (pipe(err) < 0) ||
+ assert(std_fds != NULL);
+ fds = (*env)->GetIntArrayElements(env, std_fds, NULL);
+ if (fds == NULL) goto Catch;
+
+ if ((fds[0] == -1 && pipe(in) < 0) ||
+ (fds[1] == -1 && pipe(out) < 0) ||
+ (fds[2] == -1 && pipe(err) < 0) ||
(pipe(fail) < 0)) {
throwIOException(env, errno, "Bad file descriptor");
goto Catch;
@@ -544,23 +547,26 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
if (resultPid == 0) {
/* Child process */
- /* Close the parent sides of the pipe.
- Give the child sides of the pipes the right fileno's.
+ /* Close the parent sides of the pipes.
Closing pipe fds here is redundant, since closeDescriptors()
would do it anyways, but a little paranoia is a good thing. */
+ closeSafely(in[1]);
+ closeSafely(out[0]);
+ closeSafely(err[0]);
+ closeSafely(fail[0]);
+
+ /* Give the child sides of the pipes the right fileno's. */
/* Note: it is possible for in[0] == 0 */
- close(in[1]);
- moveDescriptor(in[0], STDIN_FILENO);
- close(out[0]);
- moveDescriptor(out[1], STDOUT_FILENO);
- close(err[0]);
+ moveDescriptor(in[0] != -1 ? in[0] : fds[0], STDIN_FILENO);
+ moveDescriptor(out[1]!= -1 ? out[1] : fds[1], STDOUT_FILENO);
+
if (redirectErrorStream) {
- close(err[1]);
+ closeSafely(err[1]);
dup2(STDOUT_FILENO, STDERR_FILENO);
} else {
- moveDescriptor(err[1], STDERR_FILENO);
+ moveDescriptor(err[1] != -1 ? err[1] : fds[2], STDERR_FILENO);
}
- close(fail[0]);
+
moveDescriptor(fail[1], FAIL_FILENO);
/* close everything */
@@ -606,9 +612,9 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
goto Catch;
}
- (*env)->SetIntField(env, stdin_fd, IO_fd_fdID, in [1]);
- (*env)->SetIntField(env, stdout_fd, IO_fd_fdID, out[0]);
- (*env)->SetIntField(env, stderr_fd, IO_fd_fdID, err[0]);
+ fds[0] = (in [1] != -1) ? in [1] : -1;
+ fds[1] = (out[0] != -1) ? out[0] : -1;
+ fds[2] = (err[0] != -1) ? err[0] : -1;
Finally:
/* Always clean up the child's side of the pipes */
@@ -628,6 +634,9 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
releaseBytes(env, envBlock, penvBlock);
releaseBytes(env, dir, pdir);
+ if (fds != NULL)
+ (*env)->ReleaseIntArrayElements(env, std_fds, fds, 0);
+
return resultPid;
Catch:
diff --git a/jdk/src/windows/classes/java/io/FileDescriptor.java b/jdk/src/windows/classes/java/io/FileDescriptor.java
index c02c1619c10..f2036263e8d 100644
--- a/jdk/src/windows/classes/java/io/FileDescriptor.java
+++ b/jdk/src/windows/classes/java/io/FileDescriptor.java
@@ -29,17 +29,14 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
* Instances of the file descriptor class serve as an opaque handle
- * to the underlying machine-specific structure representing an open
- * file, an open socket, or another source or sink of bytes. The
- * main practical use for a file descriptor is to create a
- * FileInputStream or FileOutputStream to
- * contain it.
- *
- * Applications should not create their own file descriptors.
+ * to the underlying machine-specific structure representing an
+ * open file, an open socket, or another source or sink of bytes.
+ * The main practical use for a file descriptor is to create a
+ * {@link FileInputStream} or {@link FileOutputStream} to contain it.
+ *
+ *
Applications should not create their own file descriptors.
*
* @author Pavani Diwanji
- * @see java.io.FileInputStream
- * @see java.io.FileOutputStream
* @since JDK1.0
*/
public final class FileDescriptor {
@@ -81,6 +78,14 @@ public final class FileDescriptor {
public int get(FileDescriptor obj) {
return obj.fd;
}
+
+ public void setHandle(FileDescriptor obj, long handle) {
+ obj.handle = handle;
+ }
+
+ public long getHandle(FileDescriptor obj) {
+ return obj.handle;
+ }
}
);
}
@@ -88,7 +93,7 @@ public final class FileDescriptor {
/**
* A handle to the standard input stream. Usually, this file
* descriptor is not used directly, but rather via the input stream
- * known as System.in.
+ * known as {@code System.in}.
*
* @see java.lang.System#in
*/
@@ -97,7 +102,7 @@ public final class FileDescriptor {
/**
* A handle to the standard output stream. Usually, this file
* descriptor is not used directly, but rather via the output stream
- * known as System.out.
+ * known as {@code System.out}.
* @see java.lang.System#out
*/
public static final FileDescriptor out = standardStream(1);
@@ -105,7 +110,7 @@ public final class FileDescriptor {
/**
* A handle to the standard error stream. Usually, this file
* descriptor is not used directly, but rather via the output stream
- * known as System.err.
+ * known as {@code System.err}.
*
* @see java.lang.System#err
*/
@@ -114,9 +119,9 @@ public final class FileDescriptor {
/**
* Tests if this file descriptor object is valid.
*
- * @return true if the file descriptor object represents a
+ * @return {@code true} if the file descriptor object represents a
* valid, open file, socket, or other active I/O connection;
- * false otherwise.
+ * {@code false} otherwise.
*/
public boolean valid() {
return ((handle != -1) || (fd != -1));
diff --git a/jdk/src/windows/classes/java/lang/ProcessImpl.java b/jdk/src/windows/classes/java/lang/ProcessImpl.java
index 9db29772571..910575c4447 100644
--- a/jdk/src/windows/classes/java/lang/ProcessImpl.java
+++ b/jdk/src/windows/classes/java/lang/ProcessImpl.java
@@ -25,7 +25,16 @@
package java.lang;
-import java.io.*;
+import java.io.IOException;
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileDescriptor;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.lang.ProcessBuilder.Redirect;
/* This class is for the exclusive use of ProcessBuilder.start() to
* create new processes.
@@ -35,30 +44,82 @@ import java.io.*;
*/
final class ProcessImpl extends Process {
+ private static final sun.misc.JavaIOFileDescriptorAccess fdAccess
+ = sun.misc.SharedSecrets.getJavaIOFileDescriptorAccess();
// System-dependent portion of ProcessBuilder.start()
static Process start(String cmdarray[],
java.util.Map environment,
String dir,
+ ProcessBuilder.Redirect[] redirects,
boolean redirectErrorStream)
throws IOException
{
String envblock = ProcessEnvironment.toEnvironmentBlock(environment);
- return new ProcessImpl(cmdarray, envblock, dir, redirectErrorStream);
+
+ FileInputStream f0 = null;
+ FileOutputStream f1 = null;
+ FileOutputStream f2 = null;
+
+ try {
+ long[] stdHandles;
+ if (redirects == null) {
+ stdHandles = new long[] { -1L, -1L, -1L };
+ } else {
+ stdHandles = new long[3];
+
+ if (redirects[0] == Redirect.PIPE)
+ stdHandles[0] = -1L;
+ else if (redirects[0] == Redirect.INHERIT)
+ stdHandles[0] = fdAccess.getHandle(FileDescriptor.in);
+ else {
+ f0 = new FileInputStream(redirects[0].file());
+ stdHandles[0] = fdAccess.getHandle(f0.getFD());
+ }
+
+ if (redirects[1] == Redirect.PIPE)
+ stdHandles[1] = -1L;
+ else if (redirects[1] == Redirect.INHERIT)
+ stdHandles[1] = fdAccess.getHandle(FileDescriptor.out);
+ else {
+ f1 = redirects[1].toFileOutputStream();
+ stdHandles[1] = fdAccess.getHandle(f1.getFD());
+ }
+
+ if (redirects[2] == Redirect.PIPE)
+ stdHandles[2] = -1L;
+ else if (redirects[2] == Redirect.INHERIT)
+ stdHandles[2] = fdAccess.getHandle(FileDescriptor.err);
+ else {
+ f2 = redirects[2].toFileOutputStream();
+ stdHandles[2] = fdAccess.getHandle(f2.getFD());
+ }
+ }
+
+ return new ProcessImpl(cmdarray, envblock, dir,
+ stdHandles, redirectErrorStream);
+ } finally {
+ // In theory, close() can throw IOException
+ // (although it is rather unlikely to happen here)
+ try { if (f0 != null) f0.close(); }
+ finally {
+ try { if (f1 != null) f1.close(); }
+ finally { if (f2 != null) f2.close(); }
+ }
+ }
+
}
private long handle = 0;
- private FileDescriptor stdin_fd;
- private FileDescriptor stdout_fd;
- private FileDescriptor stderr_fd;
private OutputStream stdin_stream;
private InputStream stdout_stream;
private InputStream stderr_stream;
- private ProcessImpl(String cmd[],
- String envblock,
- String path,
- boolean redirectErrorStream)
+ private ProcessImpl(final String cmd[],
+ final String envblock,
+ final String path,
+ final long[] stdHandles,
+ final boolean redirectErrorStream)
throws IOException
{
// Win32 CreateProcess requires cmd[0] to be normalized
@@ -91,25 +152,39 @@ final class ProcessImpl extends Process {
}
String cmdstr = cmdbuf.toString();
- stdin_fd = new FileDescriptor();
- stdout_fd = new FileDescriptor();
- stderr_fd = new FileDescriptor();
-
- handle = create(cmdstr, envblock, path, redirectErrorStream,
- stdin_fd, stdout_fd, stderr_fd);
+ handle = create(cmdstr, envblock, path,
+ stdHandles, redirectErrorStream);
java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction() {
- public Object run() {
- stdin_stream =
- new BufferedOutputStream(new FileOutputStream(stdin_fd));
- stdout_stream =
- new BufferedInputStream(new FileInputStream(stdout_fd));
- stderr_stream =
- new FileInputStream(stderr_fd);
- return null;
+ new java.security.PrivilegedAction() {
+ public Void run() {
+ if (stdHandles[0] == -1L)
+ stdin_stream = new ProcessBuilder.NullOutputStream();
+ else {
+ FileDescriptor stdin_fd = new FileDescriptor();
+ fdAccess.setHandle(stdin_fd, stdHandles[0]);
+ stdin_stream = new BufferedOutputStream(
+ new FileOutputStream(stdin_fd));
}
- });
+
+ if (stdHandles[1] == -1L)
+ stdout_stream = new ProcessBuilder.NullInputStream();
+ else {
+ FileDescriptor stdout_fd = new FileDescriptor();
+ fdAccess.setHandle(stdout_fd, stdHandles[1]);
+ stdout_stream = new BufferedInputStream(
+ new FileInputStream(stdout_fd));
+ }
+
+ if (stdHandles[2] == -1L)
+ stderr_stream = new ProcessBuilder.NullInputStream();
+ else {
+ FileDescriptor stderr_fd = new FileDescriptor();
+ fdAccess.setHandle(stderr_fd, stdHandles[2]);
+ stderr_stream = new FileInputStream(stderr_fd);
+ }
+
+ return null; }});
}
public OutputStream getOutputStream() {
@@ -150,13 +225,30 @@ final class ProcessImpl extends Process {
public void destroy() { terminateProcess(handle); }
private static native void terminateProcess(long handle);
+ /**
+ * Create a process using the win32 function CreateProcess.
+ *
+ * @param cmdstr the Windows commandline
+ * @param envblock NUL-separated, double-NUL-terminated list of
+ * environment strings in VAR=VALUE form
+ * @param dir the working directory of the process, or null if
+ * inheriting the current directory from the parent process
+ * @param stdHandles array of windows HANDLEs. Indexes 0, 1, and
+ * 2 correspond to standard input, standard output and
+ * standard error, respectively. On input, a value of -1
+ * means to create a pipe to connect child and parent
+ * processes. On output, a value which is not -1 is the
+ * parent pipe handle corresponding to the pipe which has
+ * been created. An element of this array is -1 on input
+ * if and only if it is not -1 on output.
+ * @param redirectErrorStream redirectErrorStream attribute
+ * @return the native subprocess HANDLE returned by CreateProcess
+ */
private static native long create(String cmdstr,
String envblock,
String dir,
- boolean redirectErrorStream,
- FileDescriptor in_fd,
- FileDescriptor out_fd,
- FileDescriptor err_fd)
+ long[] stdHandles,
+ boolean redirectErrorStream)
throws IOException;
private static native boolean closeHandle(long handle);
diff --git a/jdk/src/windows/native/java/lang/ProcessImpl_md.c b/jdk/src/windows/native/java/lang/ProcessImpl_md.c
index 71113a7d5b4..f6a8cad4e4b 100644
--- a/jdk/src/windows/native/java/lang/ProcessImpl_md.c
+++ b/jdk/src/windows/native/java/lang/ProcessImpl_md.c
@@ -125,7 +125,7 @@ win32Error(JNIEnv *env, const char *functionName)
static void
closeSafely(HANDLE handle)
{
- if (handle)
+ if (handle != INVALID_HANDLE_VALUE)
CloseHandle(handle);
}
@@ -134,23 +134,22 @@ Java_java_lang_ProcessImpl_create(JNIEnv *env, jclass ignored,
jstring cmd,
jstring envBlock,
jstring dir,
- jboolean redirectErrorStream,
- jobject in_fd,
- jobject out_fd,
- jobject err_fd)
+ jlongArray stdHandles,
+ jboolean redirectErrorStream)
{
- HANDLE inRead = 0;
- HANDLE inWrite = 0;
- HANDLE outRead = 0;
- HANDLE outWrite = 0;
- HANDLE errRead = 0;
- HANDLE errWrite = 0;
+ HANDLE inRead = INVALID_HANDLE_VALUE;
+ HANDLE inWrite = INVALID_HANDLE_VALUE;
+ HANDLE outRead = INVALID_HANDLE_VALUE;
+ HANDLE outWrite = INVALID_HANDLE_VALUE;
+ HANDLE errRead = INVALID_HANDLE_VALUE;
+ HANDLE errWrite = INVALID_HANDLE_VALUE;
SECURITY_ATTRIBUTES sa;
PROCESS_INFORMATION pi;
STARTUPINFO si;
LPTSTR pcmd = NULL;
LPCTSTR pdir = NULL;
LPVOID penvBlock = NULL;
+ jlong *handles = NULL;
jlong ret = 0;
OSVERSIONINFO ver;
jboolean onNT = JNI_FALSE;
@@ -161,17 +160,6 @@ Java_java_lang_ProcessImpl_create(JNIEnv *env, jclass ignored,
if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT)
onNT = JNI_TRUE;
- sa.nLength = sizeof(sa);
- sa.lpSecurityDescriptor = 0;
- sa.bInheritHandle = TRUE;
-
- if (!(CreatePipe(&inRead, &inWrite, &sa, PIPE_SIZE) &&
- CreatePipe(&outRead, &outWrite, &sa, PIPE_SIZE) &&
- CreatePipe(&errRead, &errWrite, &sa, PIPE_SIZE))) {
- win32Error(env, "CreatePipe");
- goto Catch;
- }
-
assert(cmd != NULL);
pcmd = (LPTSTR) JNU_GetStringPlatformChars(env, cmd, NULL);
if (pcmd == NULL) goto Catch;
@@ -189,19 +177,62 @@ Java_java_lang_ProcessImpl_create(JNIEnv *env, jclass ignored,
if (penvBlock == NULL) goto Catch;
}
+ assert(stdHandles != NULL);
+ handles = (*env)->GetLongArrayElements(env, stdHandles, NULL);
+ if (handles == NULL) goto Catch;
+
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
- si.hStdInput = inRead;
- si.hStdOutput = outWrite;
- si.hStdError = redirectErrorStream ? outWrite : errWrite;
- SetHandleInformation(inWrite, HANDLE_FLAG_INHERIT, FALSE);
- SetHandleInformation(outRead, HANDLE_FLAG_INHERIT, FALSE);
- SetHandleInformation(errRead, HANDLE_FLAG_INHERIT, FALSE);
+ sa.nLength = sizeof(sa);
+ sa.lpSecurityDescriptor = 0;
+ sa.bInheritHandle = TRUE;
- if (redirectErrorStream)
- SetHandleInformation(errWrite, HANDLE_FLAG_INHERIT, FALSE);
+ if (handles[0] != (jlong) -1) {
+ si.hStdInput = (HANDLE) handles[0];
+ handles[0] = (jlong) -1;
+ } else {
+ if (! CreatePipe(&inRead, &inWrite, &sa, PIPE_SIZE)) {
+ win32Error(env, "CreatePipe");
+ goto Catch;
+ }
+ si.hStdInput = inRead;
+ SetHandleInformation(inWrite, HANDLE_FLAG_INHERIT, FALSE);
+ handles[0] = (jlong) inWrite;
+ }
+ SetHandleInformation(si.hStdInput, HANDLE_FLAG_INHERIT, TRUE);
+
+ if (handles[1] != (jlong) -1) {
+ si.hStdOutput = (HANDLE) handles[1];
+ handles[1] = (jlong) -1;
+ } else {
+ if (! CreatePipe(&outRead, &outWrite, &sa, PIPE_SIZE)) {
+ win32Error(env, "CreatePipe");
+ goto Catch;
+ }
+ si.hStdOutput = outWrite;
+ SetHandleInformation(outRead, HANDLE_FLAG_INHERIT, FALSE);
+ handles[1] = (jlong) outRead;
+ }
+ SetHandleInformation(si.hStdOutput, HANDLE_FLAG_INHERIT, TRUE);
+
+ if (redirectErrorStream) {
+ si.hStdError = si.hStdOutput;
+ handles[2] = (jlong) -1;
+ } else if (handles[2] != (jlong) -1) {
+ si.hStdError = (HANDLE) handles[2];
+ handles[2] = (jlong) -1;
+ } else {
+ if (! CreatePipe(&errRead, &errWrite, &sa, PIPE_SIZE)) {
+ win32Error(env, "CreatePipe");
+ goto Catch;
+ }
+ si.hStdError = errWrite;
+ SetHandleInformation(errRead, HANDLE_FLAG_INHERIT, FALSE);
+ handles[2] = (jlong) errRead;
+ }
+ SetHandleInformation(si.hStdError, HANDLE_FLAG_INHERIT, TRUE);
if (onNT)
processFlag = CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT;
@@ -237,9 +268,6 @@ Java_java_lang_ProcessImpl_create(JNIEnv *env, jclass ignored,
CloseHandle(pi.hThread);
ret = (jlong)pi.hProcess;
- (*env)->SetLongField(env, in_fd, IO_handle_fdID, (jlong)inWrite);
- (*env)->SetLongField(env, out_fd, IO_handle_fdID, (jlong)outRead);
- (*env)->SetLongField(env, err_fd, IO_handle_fdID, (jlong)errRead);
Finally:
/* Always clean up the child's side of the pipes */
@@ -257,6 +285,9 @@ Java_java_lang_ProcessImpl_create(JNIEnv *env, jclass ignored,
else
JNU_ReleaseStringPlatformChars(env, dir, (char *) penvBlock);
}
+ if (handles != NULL)
+ (*env)->ReleaseLongArrayElements(env, stdHandles, handles, 0);
+
return ret;
Catch:
diff --git a/jdk/test/java/lang/ProcessBuilder/Basic.java b/jdk/test/java/lang/ProcessBuilder/Basic.java
index 4a57ad94ba6..b0bfe12f250 100644
--- a/jdk/test/java/lang/ProcessBuilder/Basic.java
+++ b/jdk/test/java/lang/ProcessBuilder/Basic.java
@@ -25,12 +25,15 @@
* @test
* @bug 4199068 4738465 4937983 4930681 4926230 4931433 4932663 4986689
* 5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
- * 6464154 6523983 6206031
+ * 6464154 6523983 6206031 4960438 6631352 6631966
* @summary Basic tests for Process and Environment Variable code
* @run main/othervm Basic
* @author Martin Buchholz
*/
+import java.lang.ProcessBuilder.Redirect;
+import static java.lang.ProcessBuilder.Redirect.*;
+
import java.io.*;
import java.util.*;
import java.security.*;
@@ -257,7 +260,29 @@ public class Basic {
public static class JavaChild {
public static void main(String args[]) throws Throwable {
String action = args[0];
- if (action.equals("System.getenv(String)")) {
+ if (action.equals("testIO")) {
+ String expected = "standard input";
+ char[] buf = new char[expected.length()+1];
+ int n = new InputStreamReader(System.in).read(buf,0,buf.length);
+ if (n != expected.length())
+ System.exit(5);
+ if (! new String(buf,0,n).equals(expected))
+ System.exit(5);
+ System.err.print("standard error");
+ System.out.print("standard output");
+ } else if (action.equals("testInheritIO")) {
+ List childArgs = new ArrayList(javaChildArgs);
+ childArgs.add("testIO");
+ ProcessBuilder pb = new ProcessBuilder(childArgs);
+ pb.inheritIO();
+ ProcessResults r = run(pb);
+ if (! r.out().equals(""))
+ System.exit(7);
+ if (! r.err().equals(""))
+ System.exit(8);
+ if (r.exitValue() != 0)
+ System.exit(9);
+ } else if (action.equals("System.getenv(String)")) {
String val = System.getenv(args[1]);
printUTF8(val == null ? "null" : val);
} else if (action.equals("System.getenv(\\u1234)")) {
@@ -599,6 +624,333 @@ public class Basic {
} catch (Throwable t) { unexpected(t); }
}
+ static void checkRedirects(ProcessBuilder pb,
+ Redirect in, Redirect out, Redirect err) {
+ equal(pb.redirectInput(), in);
+ equal(pb.redirectOutput(), out);
+ equal(pb.redirectError(), err);
+ }
+
+ static void redirectIO(ProcessBuilder pb,
+ Redirect in, Redirect out, Redirect err) {
+ pb.redirectInput(in);
+ pb.redirectOutput(out);
+ pb.redirectError(err);
+ }
+
+ static void setFileContents(File file, String contents) {
+ try {
+ Writer w = new FileWriter(file);
+ w.write(contents);
+ w.close();
+ } catch (Throwable t) { unexpected(t); }
+ }
+
+ static String fileContents(File file) {
+ try {
+ Reader r = new FileReader(file);
+ StringBuilder sb = new StringBuilder();
+ char[] buffer = new char[1024];
+ int n;
+ while ((n = r.read(buffer)) != -1)
+ sb.append(buffer,0,n);
+ r.close();
+ return new String(sb);
+ } catch (Throwable t) { unexpected(t); return ""; }
+ }
+
+ static void testIORedirection() throws Throwable {
+ final File ifile = new File("ifile");
+ final File ofile = new File("ofile");
+ final File efile = new File("efile");
+ ifile.delete();
+ ofile.delete();
+ efile.delete();
+
+ //----------------------------------------------------------------
+ // Check mutual inequality of different types of Redirect
+ //----------------------------------------------------------------
+ Redirect[] redirects =
+ { PIPE,
+ INHERIT,
+ Redirect.from(ifile),
+ Redirect.to(ifile),
+ Redirect.appendTo(ifile),
+ Redirect.from(ofile),
+ Redirect.to(ofile),
+ Redirect.appendTo(ofile),
+ };
+ for (int i = 0; i < redirects.length; i++)
+ for (int j = 0; j < redirects.length; j++)
+ equal(redirects[i].equals(redirects[j]), (i == j));
+
+ //----------------------------------------------------------------
+ // Check basic properties of different types of Redirect
+ //----------------------------------------------------------------
+ equal(PIPE.type(), Redirect.Type.PIPE);
+ equal(PIPE.toString(), "PIPE");
+ equal(PIPE.file(), null);
+
+ equal(INHERIT.type(), Redirect.Type.INHERIT);
+ equal(INHERIT.toString(), "INHERIT");
+ equal(INHERIT.file(), null);
+
+ equal(Redirect.from(ifile).type(), Redirect.Type.READ);
+ equal(Redirect.from(ifile).toString(),
+ "redirect to read from file \"ifile\"");
+ equal(Redirect.from(ifile).file(), ifile);
+ equal(Redirect.from(ifile),
+ Redirect.from(ifile));
+ equal(Redirect.from(ifile).hashCode(),
+ Redirect.from(ifile).hashCode());
+
+ equal(Redirect.to(ofile).type(), Redirect.Type.WRITE);
+ equal(Redirect.to(ofile).toString(),
+ "redirect to write to file \"ofile\"");
+ equal(Redirect.to(ofile).file(), ofile);
+ equal(Redirect.to(ofile),
+ Redirect.to(ofile));
+ equal(Redirect.to(ofile).hashCode(),
+ Redirect.to(ofile).hashCode());
+
+ equal(Redirect.appendTo(ofile).type(), Redirect.Type.APPEND);
+ equal(Redirect.appendTo(efile).toString(),
+ "redirect to append to file \"efile\"");
+ equal(Redirect.appendTo(efile).file(), efile);
+ equal(Redirect.appendTo(efile),
+ Redirect.appendTo(efile));
+ equal(Redirect.appendTo(efile).hashCode(),
+ Redirect.appendTo(efile).hashCode());
+
+ //----------------------------------------------------------------
+ // Check initial values of redirects
+ //----------------------------------------------------------------
+ List childArgs = new ArrayList(javaChildArgs);
+ childArgs.add("testIO");
+ final ProcessBuilder pb = new ProcessBuilder(childArgs);
+ checkRedirects(pb, PIPE, PIPE, PIPE);
+
+ //----------------------------------------------------------------
+ // Check inheritIO
+ //----------------------------------------------------------------
+ pb.inheritIO();
+ checkRedirects(pb, INHERIT, INHERIT, INHERIT);
+
+ //----------------------------------------------------------------
+ // Check setters and getters agree
+ //----------------------------------------------------------------
+ pb.redirectInput(ifile);
+ equal(pb.redirectInput().file(), ifile);
+ equal(pb.redirectInput(), Redirect.from(ifile));
+
+ pb.redirectOutput(ofile);
+ equal(pb.redirectOutput().file(), ofile);
+ equal(pb.redirectOutput(), Redirect.to(ofile));
+
+ pb.redirectError(efile);
+ equal(pb.redirectError().file(), efile);
+ equal(pb.redirectError(), Redirect.to(efile));
+
+ THROWS(IllegalArgumentException.class,
+ new Fun(){void f() {
+ pb.redirectInput(Redirect.to(ofile)); }},
+ new Fun(){void f() {
+ pb.redirectInput(Redirect.appendTo(ofile)); }},
+ new Fun(){void f() {
+ pb.redirectOutput(Redirect.from(ifile)); }},
+ new Fun(){void f() {
+ pb.redirectError(Redirect.from(ifile)); }});
+
+ THROWS(IOException.class,
+ // Input file does not exist
+ new Fun(){void f() throws Throwable { pb.start(); }});
+ setFileContents(ifile, "standard input");
+
+ //----------------------------------------------------------------
+ // Writing to non-existent files
+ //----------------------------------------------------------------
+ {
+ ProcessResults r = run(pb);
+ equal(r.exitValue(), 0);
+ equal(fileContents(ofile), "standard output");
+ equal(fileContents(efile), "standard error");
+ equal(r.out(), "");
+ equal(r.err(), "");
+ ofile.delete();
+ efile.delete();
+ }
+
+ //----------------------------------------------------------------
+ // Both redirectErrorStream + redirectError
+ //----------------------------------------------------------------
+ {
+ pb.redirectErrorStream(true);
+ ProcessResults r = run(pb);
+ equal(r.exitValue(), 0);
+ equal(fileContents(ofile),
+ "standard error" + "standard output");
+ equal(fileContents(efile), "");
+ equal(r.out(), "");
+ equal(r.err(), "");
+ ofile.delete();
+ efile.delete();
+ }
+
+ //----------------------------------------------------------------
+ // Appending to existing files
+ //----------------------------------------------------------------
+ {
+ setFileContents(ofile, "ofile-contents");
+ setFileContents(efile, "efile-contents");
+ pb.redirectOutput(Redirect.appendTo(ofile));
+ pb.redirectError(Redirect.appendTo(efile));
+ pb.redirectErrorStream(false);
+ ProcessResults r = run(pb);
+ equal(r.exitValue(), 0);
+ equal(fileContents(ofile),
+ "ofile-contents" + "standard output");
+ equal(fileContents(efile),
+ "efile-contents" + "standard error");
+ equal(r.out(), "");
+ equal(r.err(), "");
+ ofile.delete();
+ efile.delete();
+ }
+
+ //----------------------------------------------------------------
+ // Replacing existing files
+ //----------------------------------------------------------------
+ {
+ setFileContents(ofile, "ofile-contents");
+ setFileContents(efile, "efile-contents");
+ pb.redirectOutput(ofile);
+ pb.redirectError(Redirect.to(efile));
+ ProcessResults r = run(pb);
+ equal(r.exitValue(), 0);
+ equal(fileContents(ofile), "standard output");
+ equal(fileContents(efile), "standard error");
+ equal(r.out(), "");
+ equal(r.err(), "");
+ ofile.delete();
+ efile.delete();
+ }
+
+ //----------------------------------------------------------------
+ // Appending twice to the same file?
+ //----------------------------------------------------------------
+ {
+ setFileContents(ofile, "ofile-contents");
+ setFileContents(efile, "efile-contents");
+ Redirect appender = Redirect.appendTo(ofile);
+ pb.redirectOutput(appender);
+ pb.redirectError(appender);
+ ProcessResults r = run(pb);
+ equal(r.exitValue(), 0);
+ equal(fileContents(ofile),
+ "ofile-contents" +
+ "standard error" +
+ "standard output");
+ equal(fileContents(efile), "efile-contents");
+ equal(r.out(), "");
+ equal(r.err(), "");
+ ifile.delete();
+ ofile.delete();
+ efile.delete();
+ }
+
+ //----------------------------------------------------------------
+ // Testing INHERIT is harder.
+ // Note that this requires __FOUR__ nested JVMs involved in one test,
+ // if you count the harness JVM.
+ //----------------------------------------------------------------
+ {
+ redirectIO(pb, PIPE, PIPE, PIPE);
+ List command = pb.command();
+ command.set(command.size() - 1, "testInheritIO");
+ Process p = pb.start();
+ new PrintStream(p.getOutputStream()).print("standard input");
+ p.getOutputStream().close();
+ ProcessResults r = run(p);
+ equal(r.exitValue(), 0);
+ equal(r.out(), "standard output");
+ equal(r.err(), "standard error");
+ }
+
+ //----------------------------------------------------------------
+ // Test security implications of I/O redirection
+ //----------------------------------------------------------------
+
+ // Read access to current directory is always granted;
+ // So create a tmpfile for input instead.
+ final File tmpFile = File.createTempFile("Basic", "tmp");
+ setFileContents(tmpFile, "standard input");
+
+ final Policy policy = new Policy();
+ Policy.setPolicy(policy);
+ System.setSecurityManager(new SecurityManager());
+ try {
+ final Permission xPermission
+ = new FilePermission("<>", "execute");
+ final Permission rxPermission
+ = new FilePermission("<>", "read,execute");
+ final Permission wxPermission
+ = new FilePermission("<>", "write,execute");
+ final Permission rwxPermission
+ = new FilePermission("<>", "read,write,execute");
+
+ THROWS(SecurityException.class,
+ new Fun() { void f() throws IOException {
+ policy.setPermissions(xPermission);
+ redirectIO(pb, from(tmpFile), PIPE, PIPE);
+ pb.start();}},
+ new Fun() { void f() throws IOException {
+ policy.setPermissions(rxPermission);
+ redirectIO(pb, PIPE, to(ofile), PIPE);
+ pb.start();}},
+ new Fun() { void f() throws IOException {
+ policy.setPermissions(rxPermission);
+ redirectIO(pb, PIPE, PIPE, to(efile));
+ pb.start();}});
+
+ {
+ policy.setPermissions(rxPermission);
+ redirectIO(pb, from(tmpFile), PIPE, PIPE);
+ ProcessResults r = run(pb);
+ equal(r.out(), "standard output");
+ equal(r.err(), "standard error");
+ }
+
+ {
+ policy.setPermissions(wxPermission);
+ redirectIO(pb, PIPE, to(ofile), to(efile));
+ Process p = pb.start();
+ new PrintStream(p.getOutputStream()).print("standard input");
+ p.getOutputStream().close();
+ ProcessResults r = run(p);
+ policy.setPermissions(rwxPermission);
+ equal(fileContents(ofile), "standard output");
+ equal(fileContents(efile), "standard error");
+ }
+
+ {
+ policy.setPermissions(rwxPermission);
+ redirectIO(pb, from(tmpFile), to(ofile), to(efile));
+ ProcessResults r = run(pb);
+ policy.setPermissions(rwxPermission);
+ equal(fileContents(ofile), "standard output");
+ equal(fileContents(efile), "standard error");
+ }
+
+ } finally {
+ policy.setPermissions(new RuntimePermission("setSecurityManager"));
+ System.setSecurityManager(null);
+ tmpFile.delete();
+ ifile.delete();
+ ofile.delete();
+ efile.delete();
+ }
+ }
+
private static void realMain(String[] args) throws Throwable {
if (Windows.is())
System.out.println("This appears to be a Windows system.");
@@ -607,6 +959,9 @@ public class Basic {
if (UnicodeOS.is())
System.out.println("This appears to be a Unicode-based OS.");
+ try { testIORedirection(); }
+ catch (Throwable t) { unexpected(t); }
+
//----------------------------------------------------------------
// Basic tests for setting, replacing and deleting envvars
//----------------------------------------------------------------
@@ -1354,7 +1709,8 @@ public class Basic {
execPermission);
ProcessBuilder pb = new ProcessBuilder("env");
pb.environment().put("foo","bar");
- pb.start();
+ Process p = pb.start();
+ closeStreams(p);
} catch (IOException e) { // OK
} catch (Throwable t) { unexpected(t); }
@@ -1378,6 +1734,14 @@ public class Basic {
}
+ static void closeStreams(Process p) {
+ try {
+ p.getOutputStream().close();
+ p.getInputStream().close();
+ p.getErrorStream().close();
+ } catch (Throwable t) { unexpected(t); }
+ }
+
//----------------------------------------------------------------
// A Policy class designed to make permissions fiddling very easy.
//----------------------------------------------------------------
@@ -1432,10 +1796,19 @@ public class Basic {
}
} catch (Throwable t) {
throwable = t;
+ } finally {
+ try { is.close(); }
+ catch (Throwable t) { throwable = t; }
}
}
}
+ static ProcessResults run(ProcessBuilder pb) {
+ try {
+ return run(pb.start());
+ } catch (Throwable t) { unexpected(t); return null; }
+ }
+
private static ProcessResults run(Process p) {
Throwable throwable = null;
int exitValue = -1;
From 4385dbf930a65e17f5fbe41f09421c0de1430f90 Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Mon, 10 Mar 2008 14:32:51 -0700
Subject: [PATCH 060/126] 6642034: System.getProperty("os.name") returns
Windows Vista on Windows Server 2008 (longhorn)
Reviewed-by: iris
---
.../windows/native/java/lang/java_props_md.c | 23 +++++++++++++++----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/jdk/src/windows/native/java/lang/java_props_md.c b/jdk/src/windows/native/java/lang/java_props_md.c
index ec0561c04e1..7c758e5a994 100644
--- a/jdk/src/windows/native/java/lang/java_props_md.c
+++ b/jdk/src/windows/native/java/lang/java_props_md.c
@@ -673,13 +673,13 @@ GetJavaProperties(JNIEnv* env)
/* OS properties */
{
char buf[100];
- OSVERSIONINFO ver;
+ OSVERSIONINFOEX ver;
ver.dwOSVersionInfoSize = sizeof(ver);
- GetVersionEx(&ver);
+ GetVersionEx((OSVERSIONINFO *) &ver);
/*
* From msdn page on OSVERSIONINFOEX, current as of this
- * writing decoding of dwMajorVersion and dwMinorVersion.
+ * writing, decoding of dwMajorVersion and dwMinorVersion.
*
* Operating system dwMajorVersion dwMinorVersion
* ================== ============== ==============
@@ -692,7 +692,7 @@ GetJavaProperties(JNIEnv* env)
* Windows 2000 5 0
* Windows XP 5 1
* Windows Server 2003 family 5 2
- * Windows Vista 6 0
+ * Windows Vista family 6 0
*
* This mapping will presumably be augmented as new Windows
* versions are released.
@@ -724,7 +724,20 @@ GetJavaProperties(JNIEnv* env)
default: sprops.os_name = "Windows NT (unknown)"; break;
}
} else if (ver.dwMajorVersion == 6) {
- sprops.os_name = "Windows Vista";
+ /*
+ * From MSDN OSVERSIONINFOEX documentation:
+ *
+ * "Because the version numbers for Windows Server 2008
+ * and Windows Vista are identical, you must also test
+ * whether the wProductType member is VER_NT_WORKSTATION.
+ * If wProductType is VER_NT_WORKSTATION, the operating
+ * system is Windows Vista; otherwise, it is Windows
+ * Server 2008."
+ */
+ if (ver.wProductType == VER_NT_WORKSTATION)
+ sprops.os_name = "Windows Vista";
+ else
+ sprops.os_name = "Windows Server 2008";
} else {
sprops.os_name = "Windows NT (unknown)";
}
From f3d6a3bd3b1d68a51ad1d27ca91b7d8e53aaf5ba Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Mon, 10 Mar 2008 14:32:51 -0700
Subject: [PATCH 061/126] 6671051: (process) Runtime.exec() hangs if signalled
during fork/exec
Reviewed-by: iris
---
.../solaris/native/java/lang/UNIXProcess_md.c | 39 ++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/jdk/src/solaris/native/java/lang/UNIXProcess_md.c b/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
index 480298cde58..8390a2baad5 100644
--- a/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
+++ b/jdk/src/solaris/native/java/lang/UNIXProcess_md.c
@@ -479,6 +479,37 @@ closeSafely(int fd)
close(fd);
}
+/*
+ * Reads nbyte bytes from file descriptor fd into buf,
+ * The read operation is retried in case of EINTR or partial reads.
+ *
+ * Returns number of bytes read (normally nbyte, but may be less in
+ * case of EOF). In case of read errors, returns -1 and sets errno.
+ */
+static ssize_t
+readFully(int fd, void *buf, size_t nbyte)
+{
+ ssize_t remaining = nbyte;
+ for (;;) {
+ ssize_t n = read(fd, buf, remaining);
+ if (n == 0) {
+ return nbyte - remaining;
+ } else if (n > 0) {
+ remaining -= n;
+ if (remaining <= 0)
+ return nbyte;
+ /* We were interrupted in the middle of reading the bytes.
+ * Unlikely, but possible. */
+ buf = (void *) (((char *)buf) + n);
+ } else if (errno == EINTR) {
+ /* Strange signals like SIGJVM1 are possible at any time.
+ * See http://www.dreamsongs.com/WorseIsBetter.html */
+ } else {
+ return -1;
+ }
+ }
+}
+
#ifndef __solaris__
#undef fork1
#define fork1() fork()
@@ -606,10 +637,16 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
/* parent process */
close(fail[1]); fail[1] = -1; /* See: WhyCantJohnnyExec */
- if (read(fail[0], &errnum, sizeof(errnum)) != 0) {
+
+ switch (readFully(fail[0], &errnum, sizeof(errnum))) {
+ case 0: break; /* Exec succeeded */
+ case sizeof(errnum):
waitpid(resultPid, NULL, 0);
throwIOException(env, errnum, "Exec failed");
goto Catch;
+ default:
+ throwIOException(env, errno, "Read failed");
+ goto Catch;
}
fds[0] = (in [1] != -1) ? in [1] : -1;
From 4341094bebf4ae27ee43ac85a0c87538699ae5ea Mon Sep 17 00:00:00 2001
From: Martin Buchholz
Date: Mon, 10 Mar 2008 15:07:09 -0700
Subject: [PATCH 062/126] 6600143: Remove another 450 unnecessary casts
Reviewed-by: alanb, iris, lmalvent, bristor, peterjones, darcy, wetmore
---
.../src/build/tools/jdwpgen/CommandNode.java | 8 +-
.../build/tools/jdwpgen/ConstantSetNode.java | 2 +-
.../src/build/tools/jdwpgen/RepeatNode.java | 2 +-
.../example/debug/bdi/EventRequestSpec.java | 4 +-
.../debug/bdi/EventRequestSpecList.java | 32 +--
.../example/debug/bdi/ExecutionManager.java | 37 ++--
.../example/debug/bdi/JDIEventSource.java | 4 +-
.../example/debug/bdi/LineBreakpointSpec.java | 4 +-
.../debug/bdi/MethodBreakpointSpec.java | 28 +--
.../debug/bdi/ThreadGroupIterator.java | 10 +-
.../example/debug/bdi/ThreadIterator.java | 8 +-
.../sun/tools/example/debug/expr/LValue.java | 52 +++--
.../example/debug/gui/ClassTreeTool.java | 4 +-
.../example/debug/gui/CommandInterpreter.java | 75 +++----
.../example/debug/gui/JDBFileFilter.java | 6 +-
.../tools/example/debug/gui/LaunchTool.java | 15 +-
.../tools/example/debug/gui/SearchPath.java | 6 +-
.../example/debug/gui/SourceManager.java | 6 +-
.../tools/example/debug/gui/SourceModel.java | 17 +-
.../example/debug/gui/StackTraceTool.java | 2 +-
.../example/debug/gui/ThreadTreeTool.java | 20 +-
.../example/debug/tty/BreakpointSpec.java | 32 ++-
.../sun/tools/example/debug/tty/Commands.java | 202 ++++++------------
.../com/sun/tools/example/debug/tty/Env.java | 37 ++--
.../tools/example/debug/tty/EventHandler.java | 4 +-
.../example/debug/tty/EventRequestSpec.java | 10 +-
.../debug/tty/EventRequestSpecList.java | 22 +-
.../tools/example/debug/tty/SourceMapper.java | 10 +-
.../com/sun/tools/example/debug/tty/TTY.java | 24 +--
.../debug/tty/ThreadGroupIterator.java | 10 +-
.../tools/example/debug/tty/ThreadInfo.java | 17 +-
.../example/debug/tty/ThreadIterator.java | 8 +-
.../tools/example/debug/tty/VMConnection.java | 12 +-
.../tools/hat/internal/server/ClassQuery.java | 3 +-
.../hat/internal/server/PlatformClasses.java | 4 +-
.../com/sun/tools/jdi/AbstractLauncher.java | 2 +-
.../com/sun/tools/jdi/ClassTypeImpl.java | 18 +-
.../com/sun/tools/jdi/ConcreteMethodImpl.java | 8 +-
.../com/sun/tools/jdi/EventSetImpl.java | 10 +-
.../com/sun/tools/jdi/JNITypeParser.java | 4 +-
.../classes/com/sun/tools/jdi/MethodImpl.java | 14 +-
.../sun/tools/jdi/ObjectReferenceImpl.java | 4 +-
.../com/sun/tools/jdi/PacketStream.java | 2 +-
.../com/sun/tools/jdi/ReferenceTypeImpl.java | 36 ++--
.../share/classes/com/sun/tools/jdi/SDE.java | 2 +-
.../com/sun/tools/jdi/StackFrameImpl.java | 4 +-
.../classes/com/sun/tools/jdi/TargetVM.java | 2 +-
.../tools/jdi/ThreadGroupReferenceImpl.java | 24 +--
.../com/sun/tools/jdi/VirtualMachineImpl.java | 5 +-
.../tools/jdi/VirtualMachineManagerImpl.java | 4 +-
.../classes/java/io/ObjectInputStream.java | 13 +-
.../classes/java/io/ObjectStreamClass.java | 79 ++++---
jdk/src/share/classes/java/lang/Class.java | 119 +++++------
.../share/classes/java/lang/ClassLoader.java | 164 +++++++-------
jdk/src/share/classes/java/lang/Compiler.java | 6 +-
jdk/src/share/classes/java/lang/Long.java | 2 +-
jdk/src/share/classes/java/lang/Package.java | 21 +-
.../classes/java/lang/ref/Finalizer.java | 8 +-
.../java/lang/reflect/AccessibleObject.java | 6 +-
.../classes/java/lang/reflect/Modifier.java | 5 +-
.../classes/java/lang/reflect/Proxy.java | 27 +--
.../classes/java/net/DatagramSocket.java | 5 +-
.../share/classes/java/net/ServerSocket.java | 5 +-
jdk/src/share/classes/java/net/Socket.java | 12 +-
.../classes/java/net/SocksSocketImpl.java | 34 +--
.../classes/java/net/URLClassLoader.java | 36 ++--
.../nio/channels/spi/SelectorProvider.java | 6 +-
.../rmi/activation/ActivationGroupDesc.java | 2 +-
jdk/src/share/classes/java/rmi/dgc/VMID.java | 6 +-
.../java/security/cert/TrustAnchor.java | 4 +-
.../java/security/cert/X509CertSelector.java | 18 +-
.../share/classes/java/util/ArrayList.java | 3 +-
jdk/src/share/classes/java/util/Arrays.java | 8 +-
jdk/src/share/classes/java/util/EnumMap.java | 8 +-
.../classes/java/util/IdentityHashMap.java | 8 +-
.../share/classes/java/util/JumboEnumSet.java | 2 +-
jdk/src/share/classes/java/util/Random.java | 2 +-
jdk/src/share/classes/java/util/TreeSet.java | 6 +-
.../java/util/prefs/AbstractPreferences.java | 40 ++--
.../classes/java/util/regex/Matcher.java | 2 +-
.../rmi/ssl/SslRMIClientSocketFactory.java | 4 +-
.../rmi/ssl/SslRMIServerSocketFactory.java | 26 ++-
.../auth/kerberos/KerberosTicket.java | 11 +-
.../javax/security/auth/kerberos/KeyImpl.java | 4 +-
.../sun/misc/ClassFileTransformer.java | 10 +-
jdk/src/share/classes/sun/misc/Cleaner.java | 4 +-
.../classes/sun/misc/ExtensionDependency.java | 24 +--
jdk/src/share/classes/sun/misc/GC.java | 16 +-
jdk/src/share/classes/sun/misc/Launcher.java | 28 +--
.../classes/sun/misc/PerformanceLogger.java | 16 +-
.../classes/sun/misc/ProxyGenerator.java | 31 +--
.../share/classes/sun/misc/URLClassPath.java | 58 ++---
.../share/classes/sun/net/NetProperties.java | 4 +-
.../share/classes/sun/net/NetworkClient.java | 10 +-
.../share/classes/sun/net/ftp/FtpClient.java | 10 +-
.../sun/net/spi/DefaultProxySelector.java | 12 +-
.../classes/sun/net/www/MessageHeader.java | 23 +-
.../share/classes/sun/net/www/MimeTable.java | 41 ++--
.../classes/sun/net/www/http/HttpClient.java | 21 +-
.../sun/net/www/http/KeepAliveCache.java | 43 ++--
.../sun/net/www/http/KeepAliveStream.java | 4 +-
.../net/www/http/KeepAliveStreamCleaner.java | 20 +-
.../www/protocol/ftp/FtpURLConnection.java | 9 +-
.../www/protocol/http/HttpURLConnection.java | 102 ++++-----
.../sun/net/www/protocol/jar/URLJarFile.java | 22 +-
jdk/src/share/classes/sun/nio/ch/Reflect.java | 8 +-
.../classes/sun/nio/ch/SocketAdaptor.java | 12 +-
jdk/src/share/classes/sun/nio/ch/Util.java | 46 ++--
.../classes/sun/reflect/ClassDefiner.java | 6 +-
.../sun/reflect/MethodAccessorGenerator.java | 9 +-
.../sun/reflect/ReflectionFactory.java | 33 +--
.../AnnotationInvocationHandler.java | 4 +-
.../classes/sun/reflect/misc/MethodUtil.java | 36 ++--
.../classes/sun/rmi/log/ReliableLog.java | 8 +-
.../sun/rmi/registry/RegistryImpl.java | 23 +-
.../classes/sun/rmi/rmic/RemoteClass.java | 33 +--
.../rmi/rmic/newrmic/jrmp/RemoteClass.java | 6 +-
.../share/classes/sun/rmi/runtime/Log.java | 15 +-
.../classes/sun/rmi/server/LoaderHandler.java | 39 ++--
.../sun/rmi/server/MarshalInputStream.java | 19 +-
.../sun/rmi/server/MarshalOutputStream.java | 4 +-
.../share/classes/sun/rmi/server/Util.java | 20 +-
.../sun/rmi/server/WeakClassHashMap.java | 2 +-
.../classes/sun/rmi/transport/DGCClient.java | 19 +-
.../classes/sun/rmi/transport/Target.java | 6 +-
.../classes/sun/rmi/transport/Transport.java | 6 +-
.../sun/rmi/transport/proxy/CGIHandler.java | 4 +-
.../rmi/transport/proxy/HttpSendSocket.java | 2 +-
.../proxy/RMIMasterSocketFactory.java | 22 +-
.../transport/tcp/ConnectionMultiplexer.java | 2 +-
.../sun/security/jgss/GSSManagerImpl.java | 2 +-
.../jgss/krb5/InitSecContextToken.java | 3 +-
.../classes/sun/security/ssl/CipherSuite.java | 4 +-
.../classes/sun/security/ssl/DHCrypt.java | 3 +-
.../classes/sun/security/ssl/JsseJce.java | 3 +-
.../sun/security/ssl/ProtocolList.java | 2 +-
.../sun/security/ssl/SSLSessionImpl.java | 6 +-
.../classes/sun/security/ssl/SessionId.java | 2 +-
.../security/ssl/SunX509KeyManagerImpl.java | 6 +-
.../security/x509/CertificatePolicySet.java | 2 +-
.../classes/sun/security/x509/X509Cert.java | 2 +-
.../sun/tools/jar/JarVerifierStream.java | 22 +-
.../sun/tools/native2ascii/N2AFilter.java | 2 +-
.../util/prefs/FileSystemPreferences.java | 88 ++++----
.../sun/nio/ch/DevPollArrayWrapper.java | 3 +-
.../sun/security/provider/NativePRNG.java | 6 +-
.../sun/security/mscapi/SunMSCAPI.java | 4 +-
147 files changed, 1215 insertions(+), 1415 deletions(-)
diff --git a/jdk/make/tools/src/build/tools/jdwpgen/CommandNode.java b/jdk/make/tools/src/build/tools/jdwpgen/CommandNode.java
index 4cdda4249cb..ec8666453ae 100644
--- a/jdk/make/tools/src/build/tools/jdwpgen/CommandNode.java
+++ b/jdk/make/tools/src/build/tools/jdwpgen/CommandNode.java
@@ -32,9 +32,9 @@ class CommandNode extends AbstractCommandNode {
void constrain(Context ctx) {
if (components.size() == 3) {
- Node out = (Node)components.get(0);
- Node reply = (Node)components.get(1);
- Node error = (Node)components.get(2);
+ Node out = components.get(0);
+ Node reply = components.get(1);
+ Node error = components.get(2);
if (!(out instanceof OutNode)) {
error("Expected 'Out' item, got: " + out);
}
@@ -45,7 +45,7 @@ class CommandNode extends AbstractCommandNode {
error("Expected 'ErrorSet' item, got: " + error);
}
} else if (components.size() == 1) {
- Node evt = (Node)components.get(0);
+ Node evt = components.get(0);
if (!(evt instanceof EventNode)) {
error("Expected 'Event' item, got: " + evt);
}
diff --git a/jdk/make/tools/src/build/tools/jdwpgen/ConstantSetNode.java b/jdk/make/tools/src/build/tools/jdwpgen/ConstantSetNode.java
index 6d688dd7f72..325ebc9ef46 100644
--- a/jdk/make/tools/src/build/tools/jdwpgen/ConstantSetNode.java
+++ b/jdk/make/tools/src/build/tools/jdwpgen/ConstantSetNode.java
@@ -98,7 +98,7 @@ class ConstantSetNode extends AbstractNamedNode {
if (constantMap == null) {
return "";
}
- String com = (String) constantMap.get(key);
+ String com = constantMap.get(key);
if(com == null){
return "";
} else {
diff --git a/jdk/make/tools/src/build/tools/jdwpgen/RepeatNode.java b/jdk/make/tools/src/build/tools/jdwpgen/RepeatNode.java
index 40d4e0899bd..4c8f20982f2 100644
--- a/jdk/make/tools/src/build/tools/jdwpgen/RepeatNode.java
+++ b/jdk/make/tools/src/build/tools/jdwpgen/RepeatNode.java
@@ -37,7 +37,7 @@ class RepeatNode extends AbstractTypeNode {
if (components.size() != 1) {
error("Repeat must have exactly one member, use Group for more");
}
- member = (Node)(components.get(0));
+ member = components.get(0);
if (!(member instanceof TypeNode)) {
error("Repeat member must be type specifier");
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/EventRequestSpec.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/EventRequestSpec.java
index 07b38826496..96a9ef5322b 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/EventRequestSpec.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/EventRequestSpec.java
@@ -91,9 +91,7 @@ abstract public class EventRequestSpec {
void attemptImmediateResolve(VirtualMachine vm) {
// try to resolve immediately
- Iterator iter = vm.allClasses().iterator();
- while (iter.hasNext()) {
- ReferenceType refType = (ReferenceType)iter.next();
+ for (ReferenceType refType : vm.allClasses()) {
if (refSpec.matches(refType)) {
try {
resolve(refType);
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/EventRequestSpecList.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/EventRequestSpecList.java
index dcc9b0c3517..e04c851f186 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/EventRequestSpecList.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/EventRequestSpecList.java
@@ -47,9 +47,8 @@ class EventRequestSpecList {
*/
void resolve(ReferenceType refType) {
synchronized(eventRequestSpecs) {
- Iterator iter = eventRequestSpecs.iterator();
- while (iter.hasNext()) {
- ((EventRequestSpec)iter.next()).attemptResolve(refType);
+ for (EventRequestSpec spec : eventRequestSpecs) {
+ spec.attemptResolve(refType);
}
}
}
@@ -79,7 +78,7 @@ class EventRequestSpecList {
BreakpointSpec
createMethodBreakpoint(String classPattern,
- String methodId, List methodArgs) {
+ String methodId, List methodArgs) {
ReferenceTypeSpec refSpec =
new PatternReferenceTypeSpec(classPattern);
return new MethodBreakpointSpec(this, refSpec,
@@ -132,47 +131,48 @@ class EventRequestSpecList {
// -------- notify routines --------------------
- private Vector specListeners() {
- return (Vector)runtime.specListeners.clone();
+ @SuppressWarnings("unchecked")
+ private Vector specListeners() {
+ return (Vector)runtime.specListeners.clone();
}
void notifySet(EventRequestSpec spec) {
- Vector l = specListeners();
+ Vector l = specListeners();
SpecEvent evt = new SpecEvent(spec);
for (int i = 0; i < l.size(); i++) {
- spec.notifySet((SpecListener)l.elementAt(i), evt);
+ spec.notifySet(l.elementAt(i), evt);
}
}
void notifyDeferred(EventRequestSpec spec) {
- Vector l = specListeners();
+ Vector l = specListeners();
SpecEvent evt = new SpecEvent(spec);
for (int i = 0; i < l.size(); i++) {
- spec.notifyDeferred((SpecListener)l.elementAt(i), evt);
+ spec.notifyDeferred(l.elementAt(i), evt);
}
}
void notifyDeleted(EventRequestSpec spec) {
- Vector l = specListeners();
+ Vector l = specListeners();
SpecEvent evt = new SpecEvent(spec);
for (int i = 0; i < l.size(); i++) {
- spec.notifyDeleted((SpecListener)l.elementAt(i), evt);
+ spec.notifyDeleted(l.elementAt(i), evt);
}
}
void notifyResolved(EventRequestSpec spec) {
- Vector l = specListeners();
+ Vector l = specListeners();
SpecEvent evt = new SpecEvent(spec);
for (int i = 0; i < l.size(); i++) {
- spec.notifyResolved((SpecListener)l.elementAt(i), evt);
+ spec.notifyResolved(l.elementAt(i), evt);
}
}
void notifyError(EventRequestSpec spec, Exception exc) {
- Vector l = specListeners();
+ Vector l = specListeners();
SpecErrorEvent evt = new SpecErrorEvent(spec, exc);
for (int i = 0; i < l.size(); i++) {
- spec.notifyError((SpecListener)l.elementAt(i), evt);
+ spec.notifyError(l.elementAt(i), evt);
}
}
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ExecutionManager.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ExecutionManager.java
index e533bb54c83..245590ec7fd 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ExecutionManager.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ExecutionManager.java
@@ -232,10 +232,7 @@ public class ExecutionManager {
if (pattern.startsWith("*.")) {
// Wildcard matches any leading package name.
pattern = pattern.substring(1);
- List classes = vm().allClasses();
- Iterator iter = classes.iterator();
- while (iter.hasNext()) {
- ReferenceType type = ((ReferenceType)iter.next());
+ for (ReferenceType type : vm().allClasses()) {
if (type.name().endsWith(pattern)) {
result.add(type);
}
@@ -278,7 +275,7 @@ public class ExecutionManager {
public ThreadGroupReference systemThreadGroup()
throws NoSessionException {
ensureActiveSession();
- return (ThreadGroupReference)vm().topLevelThreadGroups().get(0);
+ return vm().topLevelThreadGroups().get(0);
}
/*
@@ -349,10 +346,9 @@ public class ExecutionManager {
* attach sessions.
*/
VirtualMachineManager mgr = Bootstrap.virtualMachineManager();
- List connectors = mgr.attachingConnectors();
- AttachingConnector connector = (AttachingConnector)connectors.get(0);
+ AttachingConnector connector = mgr.attachingConnectors().get(0);
Map arguments = connector.defaultArguments();
- ((Connector.Argument)arguments.get("port")).setValue(portName);
+ arguments.get("port").setValue(portName);
Session newSession = internalAttach(connector, arguments);
if (newSession != null) {
@@ -504,10 +500,7 @@ public class ExecutionManager {
* if so, it gets removed here.
*/
EventRequestManager mgr = vm().eventRequestManager();
- List requests = mgr.stepRequests();
- Iterator iter = requests.iterator();
- while (iter.hasNext()) {
- StepRequest request = (StepRequest)iter.next();
+ for (StepRequest request : mgr.stepRequests()) {
if (request.thread().equals(thread)) {
mgr.deleteEventRequest(request);
break;
@@ -591,7 +584,7 @@ public class ExecutionManager {
if (session == null || thread == null) {
return null;
}
- ThreadInfo info = (ThreadInfo)threadInfoMap.get(thread);
+ ThreadInfo info = threadInfoMap.get(thread);
if (info == null) {
//### Should not hardcode initial frame count and prefetch here!
//info = new ThreadInfo(thread, 10, 10);
@@ -607,24 +600,22 @@ public class ExecutionManager {
void validateThreadInfo() {
session.interrupted = true;
- Iterator iter = threadInfoList.iterator();
- while (iter.hasNext()) {
- ((ThreadInfo)iter.next()).validate();
+ for (ThreadInfo threadInfo : threadInfoList) {
+ threadInfo.validate();
}
}
private void invalidateThreadInfo() {
if (session != null) {
session.interrupted = false;
- Iterator iter = threadInfoList.iterator();
- while (iter.hasNext()) {
- ((ThreadInfo)iter.next()).invalidate();
+ for (ThreadInfo threadInfo : threadInfoList) {
+ threadInfo.invalidate();
}
}
}
void removeThreadInfo(ThreadReference thread) {
- ThreadInfo info = (ThreadInfo)threadInfoMap.get(thread);
+ ThreadInfo info = threadInfoMap.get(thread);
if (info != null) {
info.invalidate();
threadInfoMap.remove(thread);
@@ -702,7 +693,7 @@ public class ExecutionManager {
while (inputBuffer.size() < 1) {
inputLock.wait();
}
- line = (String)inputBuffer.removeLast();
+ line = inputBuffer.removeLast();
} catch (InterruptedException e) {}
}
}
@@ -774,7 +765,7 @@ public class ExecutionManager {
public BreakpointSpec
createMethodBreakpoint(String classPattern,
- String methodId, List methodArgs) {
+ String methodId, List methodArgs) {
return specList.createMethodBreakpoint(classPattern,
methodId, methodArgs);
}
@@ -811,7 +802,7 @@ public class ExecutionManager {
specList.install(spec, vm());
}
- public List eventRequestSpecs() {
+ public List eventRequestSpecs() {
return specList.eventRequestSpecs();
}
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/JDIEventSource.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/JDIEventSource.java
index 2bd45c2fc38..97fc6a7f2b0 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/JDIEventSource.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/JDIEventSource.java
@@ -82,9 +82,7 @@ class JDIEventSource extends Thread {
boolean interrupted = es.suspendedAll();
es.notify(firstListener);
boolean wantInterrupt = JDIEventSource.this.wantInterrupt;
- for (Iterator it = session.runtime.jdiListeners.iterator();
- it.hasNext(); ) {
- JDIListener jl = (JDIListener)it.next();
+ for (JDIListener jl : session.runtime.jdiListeners) {
es.notify(jl);
}
if (interrupted && !wantInterrupt) {
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/LineBreakpointSpec.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/LineBreakpointSpec.java
index 0d9c0cc05dd..29f05ced6b7 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/LineBreakpointSpec.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/LineBreakpointSpec.java
@@ -58,12 +58,12 @@ public class LineBreakpointSpec extends BreakpointSpec {
LineNotFoundException {
Location location = null;
try {
- List locs = clazz.locationsOfLine(lineNumber());
+ List locs = clazz.locationsOfLine(lineNumber());
if (locs.size() == 0) {
throw new LineNotFoundException();
}
// TODO handle multiple locations
- location = (Location)locs.get(0);
+ location = locs.get(0);
if (location.method() == null) {
throw new LineNotFoundException();
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/MethodBreakpointSpec.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/MethodBreakpointSpec.java
index 6a4f5e5a263..0732ed9c2c1 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/MethodBreakpointSpec.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/MethodBreakpointSpec.java
@@ -34,11 +34,11 @@ import java.util.Iterator;
public class MethodBreakpointSpec extends BreakpointSpec {
String methodId;
- List methodArgs;
+ List methodArgs;
MethodBreakpointSpec(EventRequestSpecList specs,
ReferenceTypeSpec refSpec,
- String methodId, List methodArgs) {
+ String methodId, List methodArgs) {
super(specs, refSpec);
this.methodId = methodId;
this.methodArgs = methodArgs;
@@ -76,7 +76,7 @@ public class MethodBreakpointSpec extends BreakpointSpec {
return methodId;
}
- public List methodArgs() {
+ public List methodArgs() {
return methodArgs;
}
@@ -120,14 +120,13 @@ public class MethodBreakpointSpec extends BreakpointSpec {
buffer.append('.');
buffer.append(methodId);
if (methodArgs != null) {
- Iterator iter = methodArgs.iterator();
boolean first = true;
buffer.append('(');
- while (iter.hasNext()) {
+ for (String name : methodArgs) {
if (!first) {
buffer.append(',');
}
- buffer.append((String)iter.next());
+ buffer.append(name);
first = false;
}
buffer.append(")");
@@ -151,8 +150,8 @@ public class MethodBreakpointSpec extends BreakpointSpec {
* and if the number of arguments in the method matches the
* number of names passed
*/
- private boolean compareArgTypes(Method method, List nameList) {
- List argTypeNames = method.argumentTypeNames();
+ private boolean compareArgTypes(Method method, List nameList) {
+ List argTypeNames = method.argumentTypeNames();
// If argument counts differ, we can stop here
if (argTypeNames.size() != nameList.size()) {
@@ -162,8 +161,8 @@ public class MethodBreakpointSpec extends BreakpointSpec {
// Compare each argument type's name
int nTypes = argTypeNames.size();
for (int i = 0; i < nTypes; ++i) {
- String comp1 = (String)argTypeNames.get(i);
- String comp2 = (String)nameList.get(i);
+ String comp1 = argTypeNames.get(i);
+ String comp2 = nameList.get(i);
if (! comp1.equals(comp2)) {
/*
* We have to handle varargs. EG, the
@@ -288,22 +287,17 @@ public class MethodBreakpointSpec extends BreakpointSpec {
List argTypeNames = null;
if (methodArgs() != null) {
argTypeNames = new ArrayList(methodArgs().size());
- Iterator iter = methodArgs().iterator();
- while (iter.hasNext()) {
- String name = (String)iter.next();
+ for (String name : methodArgs()) {
name = normalizeArgTypeName(name);
argTypeNames.add(name);
}
}
// Check each method in the class for matches
- Iterator iter = clazz.methods().iterator();
Method firstMatch = null; // first method with matching name
Method exactMatch = null; // (only) method with same name & sig
int matchCount = 0; // > 1 implies overload
- while (iter.hasNext()) {
- Method candidate = (Method)iter.next();
-
+ for (Method candidate : clazz.methods()) {
if (candidate.name().equals(methodName())) {
matchCount++;
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ThreadGroupIterator.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ThreadGroupIterator.java
index d9b375cfde8..d41901320dd 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ThreadGroupIterator.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ThreadGroupIterator.java
@@ -36,7 +36,7 @@ import java.util.Iterator;
* Descend the tree of thread groups.
* @author Robert G. Field
*/
-public class ThreadGroupIterator implements Iterator {
+public class ThreadGroupIterator implements Iterator {
private final Stack> stack
= new Stack>();
@@ -56,8 +56,8 @@ public class ThreadGroupIterator implements Iterator {
}
*/
- private Iterator top() {
- return (Iterator)stack.peek();
+ private Iterator top() {
+ return stack.peek();
}
/**
@@ -77,12 +77,12 @@ public class ThreadGroupIterator implements Iterator {
return !stack.isEmpty();
}
- public Object next() {
+ public ThreadGroupReference next() {
return nextThreadGroup();
}
public ThreadGroupReference nextThreadGroup() {
- ThreadGroupReference tg = (ThreadGroupReference)top().next();
+ ThreadGroupReference tg = top().next();
push(tg.threadGroups());
return tg;
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ThreadIterator.java b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ThreadIterator.java
index 36b71e46023..bfe57d14a92 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ThreadIterator.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/bdi/ThreadIterator.java
@@ -30,8 +30,8 @@ import com.sun.jdi.ThreadReference;
import java.util.List;
import java.util.Iterator;
-public class ThreadIterator implements Iterator {
- Iterator it = null;
+public class ThreadIterator implements Iterator {
+ Iterator it = null;
ThreadGroupIterator tgi;
public ThreadIterator(ThreadGroupReference tg) {
@@ -53,12 +53,12 @@ public class ThreadIterator implements Iterator {
return true;
}
- public Object next() {
+ public ThreadReference next() {
return it.next();
}
public ThreadReference nextThread() {
- return (ThreadReference)next();
+ return next();
}
public void remove() {
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/expr/LValue.java b/jdk/src/share/classes/com/sun/tools/example/debug/expr/LValue.java
index 6b65e0c57a2..ae9711d9f09 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/expr/LValue.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/expr/LValue.java
@@ -191,11 +191,12 @@ abstract class LValue {
return field;
}
- static List methodsByName(ReferenceType refType, String name, int kind) {
- List list = refType.methodsByName(name);
- Iterator iter = list.iterator();
+ static List methodsByName(ReferenceType refType,
+ String name, int kind) {
+ List list = refType.methodsByName(name);
+ Iterator iter = list.iterator();
while (iter.hasNext()) {
- Method method = (Method)iter.next();
+ Method method = iter.next();
boolean isStatic = method.isStatic();
if (((kind == STATIC) && !isStatic) ||
((kind == INSTANCE) && isStatic)) {
@@ -231,21 +232,21 @@ abstract class LValue {
* argType is not assignable from the type of the argument value.
* IE, one is an Apple and the other is an Orange.
*/
- static int argumentsMatch(List argTypes, List arguments) {
+ static int argumentsMatch(List argTypes, List arguments) {
if (argTypes.size() != arguments.size()) {
return DIFFERENT;
}
- Iterator typeIter = argTypes.iterator();
- Iterator valIter = arguments.iterator();
+ Iterator typeIter = argTypes.iterator();
+ Iterator valIter = arguments.iterator();
int result = SAME;
// If any pair aren't the same, change the
// result to ASSIGNABLE. If any pair aren't
// assignable, return DIFFERENT
while (typeIter.hasNext()) {
- Type argType = (Type)typeIter.next();
- Value value = (Value)valIter.next();
+ Type argType = typeIter.next();
+ Value value = valIter.next();
if (value == null) {
// Null values can be passed to any non-primitive argument
if (primitiveTypeNames.contains(argType.name())) {
@@ -333,7 +334,7 @@ abstract class LValue {
if (fromType instanceof ArrayType) {
return isArrayAssignableTo((ArrayType)fromType, toType);
}
- List interfaces;
+ List interfaces;
if (fromType instanceof ClassType) {
ClassType superclazz = ((ClassType)fromType).superclass();
if ((superclazz != null) && isAssignableTo(superclazz, toType)) {
@@ -344,9 +345,7 @@ abstract class LValue {
// fromType must be an InterfaceType
interfaces = ((InterfaceType)fromType).superinterfaces();
}
- Iterator iter = interfaces.iterator();
- while (iter.hasNext()) {
- InterfaceType interfaze = (InterfaceType)iter.next();
+ for (InterfaceType interfaze : interfaces) {
if (isAssignableTo(interfaze, toType)) {
return true;
}
@@ -354,7 +353,8 @@ abstract class LValue {
return false;
}
- static Method resolveOverload(List overloads, List arguments)
+ static Method resolveOverload(List overloads,
+ List arguments)
throws ParseException {
// If there is only one method to call, we'll just choose
@@ -362,7 +362,7 @@ abstract class LValue {
// the invoke will return a better error message than we
// could generate here.
if (overloads.size() == 1) {
- return (Method)overloads.get(0);
+ return overloads.get(0);
}
// Resolving overloads is beyond the scope of this exercise.
@@ -374,12 +374,10 @@ abstract class LValue {
// methods to call. And, since casts aren't implemented,
// the user can't use them to pick a particular overload to call.
// IE, the user is out of luck in this case.
- Iterator iter = overloads.iterator();
Method retVal = null;
int assignableCount = 0;
- while (iter.hasNext()) {
- Method mm = (Method)iter.next();
- List argTypes;
+ for (Method mm : overloads) {
+ List argTypes;
try {
argTypes = mm.argumentTypes();
} catch (ClassNotLoadedException ee) {
@@ -443,7 +441,7 @@ abstract class LValue {
final ObjectReference obj;
final ThreadReference thread;
final Field matchingField;
- final List overloads;
+ final List overloads;
Method matchingMethod = null;
List methodArguments = null;
@@ -510,7 +508,7 @@ abstract class LValue {
final ReferenceType refType;
final ThreadReference thread;
final Field matchingField;
- final List overloads;
+ final List overloads;
Method matchingMethod = null;
List methodArguments = null;
@@ -765,7 +763,7 @@ abstract class LValue {
static LValue makeNewObject(VirtualMachine vm,
ExpressionParser.GetFrame frameGetter,
String className, List arguments) throws ParseException {
- List classes = vm.classesByName(className);
+ List classes = vm.classesByName(className);
if (classes.size() == 0) {
throw new ParseException("No class named: " + className);
}
@@ -774,7 +772,7 @@ abstract class LValue {
throw new ParseException("More than one class named: " +
className);
}
- ReferenceType refType = (ReferenceType)classes.get(0);
+ ReferenceType refType = classes.get(0);
if (!(refType instanceof ClassType)) {
@@ -784,9 +782,9 @@ abstract class LValue {
ClassType classType = (ClassType)refType;
List methods = new ArrayList(classType.methods()); // writable
- Iterator iter = methods.iterator();
+ Iterator iter = methods.iterator();
while (iter.hasNext()) {
- Method method = (Method)iter.next();
+ Method method = iter.next();
if (!method.isConstructor()) {
iter.remove();
}
@@ -858,13 +856,13 @@ abstract class LValue {
}
// check for class name
while (izer.hasMoreTokens()) {
- List classes = vm.classesByName(first);
+ List classes = vm.classesByName(first);
if (classes.size() > 0) {
if (classes.size() > 1) {
throw new ParseException("More than one class named: " +
first);
} else {
- ReferenceType refType = (ReferenceType)classes.get(0);
+ ReferenceType refType = classes.get(0);
LValue lval = new LValueStaticMember(refType,
izer.nextToken(), thread);
return nFields(lval, izer, thread);
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/ClassTreeTool.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/ClassTreeTool.java
index 6ddb558c4f2..bea3a2745e7 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/ClassTreeTool.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/ClassTreeTool.java
@@ -124,9 +124,7 @@ public class ClassTreeTool extends JPanel {
public void sessionStart(EventObject e) {
// Get system classes and any others loaded before attaching.
try {
- Iterator iter = runtime.allClasses().iterator();
- while (iter.hasNext()) {
- ReferenceType type = ((ReferenceType)iter.next());
+ for (ReferenceType type : runtime.allClasses()) {
root.addClass(type);
}
} catch (VMDisconnectedException ee) {
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/CommandInterpreter.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/CommandInterpreter.java
index e0f96e01316..7b6aaf54695 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/CommandInterpreter.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/CommandInterpreter.java
@@ -77,7 +77,7 @@ public class CommandInterpreter {
while (ti.hasNext()) {
tlist.add(ti.nextThread());
}
- threads = (ThreadReference[])tlist.toArray(new ThreadReference[tlist.size()]);
+ threads = tlist.toArray(new ThreadReference[tlist.size()]);
}
return threads;
}
@@ -146,11 +146,9 @@ public class CommandInterpreter {
// Command: classes
private void commandClasses() throws NoSessionException {
- List list = runtime.allClasses();
OutputSink out = env.getOutputSink();
//out.println("** classes list **");
- for (int i = 0 ; i < list.size() ; i++) {
- ReferenceType refType = (ReferenceType)list.get(i);
+ for (ReferenceType refType : runtime.allClasses()) {
out.println(refType.name());
}
out.show();
@@ -167,16 +165,16 @@ public class CommandInterpreter {
String idClass = t.nextToken();
ReferenceType cls = findClass(idClass);
if (cls != null) {
- List methods = cls.allMethods();
+ List methods = cls.allMethods();
OutputSink out = env.getOutputSink();
for (int i = 0; i < methods.size(); i++) {
- Method method = (Method)methods.get(i);
+ Method method = methods.get(i);
out.print(method.declaringType().name() + " " +
method.name() + "(");
- Iterator it = method.argumentTypeNames().iterator();
+ Iterator it = method.argumentTypeNames().iterator();
if (it.hasNext()) {
while (true) {
- out.print((String)it.next());
+ out.print(it.next());
if (!it.hasNext()) {
break;
}
@@ -193,10 +191,10 @@ public class CommandInterpreter {
}
private ReferenceType findClass(String pattern) throws NoSessionException {
- List results = runtime.findClassesMatchingPattern(pattern);
+ List results = runtime.findClassesMatchingPattern(pattern);
if (results.size() > 0) {
//### Should handle multiple results sensibly.
- return (ReferenceType)results.get(0);
+ return results.get(0);
}
return null;
}
@@ -235,11 +233,11 @@ public class CommandInterpreter {
private int printThreadGroup(OutputSink out, ThreadGroupReference tg, int iThread) {
out.println("Group " + tg.name() + ":");
- List tlist = tg.threads();
+ List tlist = tg.threads();
int maxId = 0;
int maxName = 0;
for (int i = 0 ; i < tlist.size() ; i++) {
- ThreadReference thr = (ThreadReference)tlist.get(i);
+ ThreadReference thr = tlist.get(i);
int len = Utils.description(thr).length();
if (len > maxId)
maxId = len;
@@ -254,7 +252,7 @@ public class CommandInterpreter {
String maxNumString = String.valueOf(iThread + tlist.size());
int maxNumDigits = maxNumString.length();
for (int i = 0 ; i < tlist.size() ; i++) {
- ThreadReference thr = (ThreadReference)tlist.get(i);
+ ThreadReference thr = tlist.get(i);
char buf[] = new char[80];
for (int j = 0; j < 79; j++) {
buf[j] = ' ';
@@ -283,9 +281,7 @@ public class CommandInterpreter {
sbOut.setLength(79);
out.println(sbOut.toString());
}
- List tglist = tg.threadGroups();
- for (int ig = 0; ig < tglist.size(); ig++) {
- ThreadGroupReference tg0 = (ThreadGroupReference)tglist.get(ig);
+ for (ThreadGroupReference tg0 : tg.threadGroups()) {
if (!tg.equals(tg0)) { // TODO ref mgt
iThread += printThreadGroup(out, tg0, iThread + tlist.size());
}
@@ -733,7 +729,7 @@ public class CommandInterpreter {
if (token.toLowerCase().equals("all")) {
ThreadIterator it = allThreads();
while (it.hasNext()) {
- ThreadReference thread = (ThreadReference)it.next();
+ ThreadReference thread = it.next();
out.println(thread.name() + ": ");
dumpStack(thread, showPC);
}
@@ -755,7 +751,7 @@ public class CommandInterpreter {
//env.failure("Target VM must be in interrupted state.");
//env.failure("Current thread isn't suspended.");
//### Should handle extremely long stack traces sensibly for user.
- List stack = null;
+ List stack = null;
try {
stack = thread.frames();
} catch (IncompatibleThreadStateException e) {
@@ -772,7 +768,7 @@ public class CommandInterpreter {
OutputSink out = env.getOutputSink();
int nFrames = stack.size();
for (int i = frameIndex; i < nFrames; i++) {
- StackFrame frame = (StackFrame)stack.get(i);
+ StackFrame frame = stack.get(i);
Location loc = frame.location();
Method meth = loc.method();
out.print(" [" + (i + 1) + "] ");
@@ -780,7 +776,7 @@ public class CommandInterpreter {
out.print('.');
out.print(meth.name());
out.print(" (");
- if (meth instanceof Method && ((Method)meth).isNative()) {
+ if (meth.isNative()) {
out.print("native method");
} else if (loc.lineNumber() != -1) {
try {
@@ -806,14 +802,13 @@ public class CommandInterpreter {
private void listEventRequests() throws NoSessionException {
// Print set breakpoints
- Iterator iter = runtime.eventRequestSpecs().iterator();
- if (!iter.hasNext()) {
+ List specs = runtime.eventRequestSpecs();
+ if (specs.isEmpty()) {
env.notice("No breakpoints/watchpoints/exceptions set.");
} else {
OutputSink out = env.getOutputSink();
out.println("Current breakpoints/watchpoints/exceptions set:");
- while (iter.hasNext()) {
- EventRequestSpec bp = (EventRequestSpec)iter.next();
+ for (EventRequestSpec bp : specs) {
out.println("\t" + bp);
}
out.show();
@@ -926,13 +921,13 @@ public class CommandInterpreter {
//### need 'clear all'
BreakpointSpec bpSpec = parseBreakpointSpec(t.nextToken());
if (bpSpec != null) {
- Iterator iter = runtime.eventRequestSpecs().iterator();
- if (!iter.hasNext()) {
+ List specs = runtime.eventRequestSpecs();
+
+ if (specs.isEmpty()) {
env.notice("No breakpoints set.");
} else {
- List toDelete = new ArrayList();
- while (iter.hasNext()) {
- BreakpointSpec spec = (BreakpointSpec)iter.next();
+ List toDelete = new ArrayList();
+ for (EventRequestSpec spec : specs) {
if (spec.equals(bpSpec)) {
toDelete.add(spec);
}
@@ -941,7 +936,7 @@ public class CommandInterpreter {
if (toDelete.size() <= 1) {
env.notice("No matching breakpoint set.");
}
- for (BreakpointSpec spec : toDelete) {
+ for (EventRequestSpec spec : toDelete) {
runtime.delete(spec);
}
}
@@ -988,7 +983,7 @@ public class CommandInterpreter {
lineno = Integer.valueOf(id).intValue();
} catch (NumberFormatException nfe) {
// It isn't -- see if it's a method name.
- List meths = refType.methodsByName(id);
+ List meths = refType.methodsByName(id);
if (meths == null || meths.size() == 0) {
env.failure(id +
" is not a valid line number or " +
@@ -1001,7 +996,7 @@ public class CommandInterpreter {
refType.name());
return;
}
- loc = ((Method)meths.get(0)).location();
+ loc = meths.get(0).location();
lineno = loc.lineNumber();
}
}
@@ -1121,7 +1116,7 @@ public class CommandInterpreter {
return;
}
- List vars;
+ List vars;
try {
vars = frame.visibleVariables();
if (vars == null || vars.size() == 0) {
@@ -1136,15 +1131,13 @@ public class CommandInterpreter {
OutputSink out = env.getOutputSink();
out.println("Method arguments:");
- for (Iterator it = vars.iterator(); it.hasNext(); ) {
- LocalVariable var = (LocalVariable)it.next();
+ for (LocalVariable var : vars) {
if (var.isArgument()) {
printVar(out, var, frame);
}
}
out.println("Local variables:");
- for (Iterator it = vars.iterator(); it.hasNext(); ) {
- LocalVariable var = (LocalVariable)it.next();
+ for (LocalVariable var : vars) {
if (!var.isArgument()) {
printVar(out, var, frame);
}
@@ -1245,8 +1238,7 @@ public class CommandInterpreter {
private void dump(OutputSink out,
ObjectReference obj, ReferenceType refType,
ReferenceType refTypeBase) {
- for (Iterator it = refType.fields().iterator(); it.hasNext(); ) {
- Field field = (Field)it.next();
+ for (Field field : refType.fields()) {
out.print(" ");
if (!refType.equals(refTypeBase)) {
out.print(refType.name() + ".");
@@ -1261,9 +1253,8 @@ public class CommandInterpreter {
dump(out, obj, sup, refTypeBase);
}
} else if (refType instanceof InterfaceType) {
- List sups = ((InterfaceType)refType).superinterfaces();
- for (Iterator it = sups.iterator(); it.hasNext(); ) {
- dump(out, obj, (ReferenceType)it.next(), refTypeBase);
+ for (InterfaceType sup : ((InterfaceType)refType).superinterfaces()) {
+ dump(out, obj, sup, refTypeBase);
}
}
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/JDBFileFilter.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/JDBFileFilter.java
index ddb71921dc1..5963ef2e0df 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/JDBFileFilter.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/JDBFileFilter.java
@@ -201,11 +201,11 @@ public class JDBFileFilter extends FileFilter {
if(description == null || isExtensionListInDescription()) {
fullDescription = description==null ? "(" : description + " (";
// build the description from the extension list
- Enumeration extensions = filters.keys();
+ Enumeration extensions = filters.keys();
if(extensions != null) {
- fullDescription += "." + (String) extensions.nextElement();
+ fullDescription += "." + extensions.nextElement();
while (extensions.hasMoreElements()) {
- fullDescription += ", " + (String) extensions.nextElement();
+ fullDescription += ", " + extensions.nextElement();
}
}
fullDescription += ")";
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/LaunchTool.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/LaunchTool.java
index 7aed53869e1..fc115b9078e 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/LaunchTool.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/LaunchTool.java
@@ -131,14 +131,13 @@ class LaunchTool {
final JPanel radioPanel = new JPanel();
final ButtonGroup radioGroup = new ButtonGroup();
VirtualMachineManager manager = Bootstrap.virtualMachineManager();
- List all = manager.allConnectors();
+ List all = manager.allConnectors();
Map modelToConnector = new HashMap(all.size(), 0.5f);
dialog.setModal(true);
dialog.setTitle("Select Connector Type");
radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));
- for (Iterator it = all.iterator(); it.hasNext(); ) {
- Connector connector = (Connector)it.next();
+ for (Connector connector : all) {
JRadioButton radio = new JRadioButton(connector.description());
modelToConnector.put(radio.getModel(), connector);
radioPanel.add(radio);
@@ -166,7 +165,7 @@ class LaunchTool {
dialog.show();
return oked[0] ?
- (Connector)(modelToConnector.get(radioGroup.getSelection())) :
+ modelToConnector.get(radioGroup.getSelection()) :
null;
}
@@ -188,13 +187,12 @@ class LaunchTool {
// guts.add(new JLabel(connector.description()));
final List argReps = new ArrayList(args.size());
- for (Iterator it = args.values().iterator(); it.hasNext(); ) {
- Object arg = it.next();
+ for (Connector.Argument arg : args.values()) {
ArgRep ar;
if (arg instanceof Connector.BooleanArgument) {
ar = new BooleanArgRep((Connector.BooleanArgument)arg, guts);
} else {
- ar = new StringArgRep((Connector.Argument)arg, guts);
+ ar = new StringArgRep(arg, guts);
}
argReps.add(ar);
}
@@ -202,8 +200,7 @@ class LaunchTool {
JPanel buttonPanel = okCancel( dialog, new ActionListener() {
public void actionPerformed(ActionEvent event) {
- for (Iterator it = argReps.iterator(); it.hasNext(); ) {
- ArgRep ar = (ArgRep)it.next();
+ for (ArgRep ar : argReps) {
if (!ar.isSpecified()) {
JOptionPane.showMessageDialog(dialog,
ar.arg.label() +
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/SearchPath.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/SearchPath.java
index 45f7ac7eb4d..1d61c8fa068 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/SearchPath.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/SearchPath.java
@@ -42,7 +42,7 @@ public class SearchPath {
dlist.add(st.nextToken());
}
pathString = searchPath;
- pathArray = (String[])dlist.toArray(new String[dlist.size()]);
+ pathArray = dlist.toArray(new String[dlist.size()]);
}
public boolean isEmpty() {
@@ -54,7 +54,7 @@ public class SearchPath {
}
public String[] asArray() {
- return (String[])pathArray.clone();
+ return pathArray.clone();
}
public File resolve(String relativeFileName) {
@@ -89,7 +89,7 @@ public class SearchPath {
}
}
}
- return (String[])s.toArray(new String[s.size()]);
+ return s.toArray(new String[s.size()]);
}
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceManager.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceManager.java
index 56667100dd1..7173b5f1014 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceManager.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceManager.java
@@ -113,7 +113,7 @@ public class SourceManager {
* Returns null if not available.
*/
public SourceModel sourceForClass(ReferenceType refType) {
- SourceModel sm = (SourceModel)classToSource.get(refType);
+ SourceModel sm = classToSource.get(refType);
if (sm != null) {
return sm;
}
@@ -140,10 +140,10 @@ public class SourceManager {
*/
//### Use hash table for this?
public SourceModel sourceForFile(File path) {
- Iterator iter = sourceList.iterator();
+ Iterator iter = sourceList.iterator();
SourceModel sm = null;
while (iter.hasNext()) {
- SourceModel candidate = (SourceModel)iter.next();
+ SourceModel candidate = iter.next();
if (candidate.fileName().equals(path)) {
sm = candidate;
iter.remove(); // Will move to start of list.
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceModel.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceModel.java
index 6bb1e551e42..75cdca6857d 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceModel.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/SourceModel.java
@@ -187,22 +187,17 @@ public class SourceModel extends AbstractListModel {
* when sourceLines is set.
*/
private void markClassLines(ReferenceType refType) {
- List methods = refType.methods();
- for (Iterator mit = methods.iterator(); mit.hasNext();) {
- Method meth = (Method)mit.next();
+ for (Method meth : refType.methods()) {
try {
- List lines = meth.allLineLocations();
- for (Iterator lit = lines.iterator(); lit.hasNext();) {
- Location loc = (Location)lit.next();
+ for (Location loc : meth.allLineLocations()) {
showExecutable(loc.lineNumber(), refType);
}
} catch (AbsentInformationException exc) {
// do nothing
}
}
- List bps = env.getExecutionManager().eventRequestManager().breakpointRequests();
- for (Iterator it = bps.iterator(); it.hasNext();) {
- BreakpointRequest bp = (BreakpointRequest)it.next();
+ for (BreakpointRequest bp :
+ env.getExecutionManager().eventRequestManager().breakpointRequests()) {
if (bp.location() != null) {
Location loc = bp.location();
if (loc.declaringType().equals(refType)) {
@@ -224,8 +219,8 @@ public class SourceModel extends AbstractListModel {
} finally {
reader.close();
}
- for (Iterator it = classes.iterator(); it.hasNext();) {
- markClassLines((ClassType)it.next());
+ for (ReferenceType refType : classes) {
+ markClassLines(refType);
}
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/StackTraceTool.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/StackTraceTool.java
index 7f4c857895a..78476f0d98b 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/StackTraceTool.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/StackTraceTool.java
@@ -139,7 +139,7 @@ public class StackTraceTool extends JPanel {
String methName =
meth.declaringType().name() + '.' + meth.name();
String position = "";
- if (meth instanceof Method && ((Method)meth).isNative()) {
+ if (meth.isNative()) {
position = " (native method)";
} else if (loc.lineNumber() != -1) {
position = ":" + loc.lineNumber();
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/gui/ThreadTreeTool.java b/jdk/src/share/classes/com/sun/tools/example/debug/gui/ThreadTreeTool.java
index 3b6d5fc4181..955c5b6cbc1 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/gui/ThreadTreeTool.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/gui/ThreadTreeTool.java
@@ -133,9 +133,7 @@ public class ThreadTreeTool extends JPanel {
public void sessionStart(EventObject e) {
try {
- Iterator iter = runtime.allThreads().iterator();
- while (iter.hasNext()) {
- ThreadReference thread = ((ThreadReference)iter.next());
+ for (ThreadReference thread : runtime.allThreads()) {
root.addThread(thread);
}
} catch (VMDisconnectedException ee) {
@@ -244,16 +242,16 @@ public class ThreadTreeTool extends JPanel {
}
}
- private void addThread(List threadPath, ThreadReference thread) {
+ private void addThread(List threadPath, ThreadReference thread) {
int size = threadPath.size();
if (size == 0) {
return;
} else if (size == 1) {
- String name = (String)threadPath.get(0);
+ String name = threadPath.get(0);
insertNode(name, thread);
} else {
- String head = (String)threadPath.get(0);
- List tail = threadPath.subList(1, size);
+ String head = threadPath.get(0);
+ List tail = threadPath.subList(1, size);
ThreadTreeNode child = insertNode(head, null);
child.addThread(tail, thread);
}
@@ -288,17 +286,17 @@ public class ThreadTreeTool extends JPanel {
}
}
- private void removeThread(List threadPath, ThreadReference thread) {
+ private void removeThread(List threadPath, ThreadReference thread) {
int size = threadPath.size();
if (size == 0) {
return;
} else if (size == 1) {
- String name = (String)threadPath.get(0);
+ String name = threadPath.get(0);
ThreadTreeNode child = findLeafNode(thread, name);
treeModel.removeNodeFromParent(child);
} else {
- String head = (String)threadPath.get(0);
- List tail = threadPath.subList(1, size);
+ String head = threadPath.get(0);
+ List tail = threadPath.subList(1, size);
ThreadTreeNode child = findInternalNode(head);
child.removeThread(tail, thread);
if (child.isThreadGroup() && child.getChildCount() < 1) {
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java
index c79f17e3608..c6d437d29e6 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java
@@ -34,7 +34,7 @@ import java.util.Iterator;
class BreakpointSpec extends EventRequestSpec {
String methodId;
- List methodArgs;
+ List methodArgs;
int lineNumber;
BreakpointSpec(ReferenceTypeSpec refSpec, int lineNumber) {
@@ -45,7 +45,7 @@ class BreakpointSpec extends EventRequestSpec {
}
BreakpointSpec(ReferenceTypeSpec refSpec, String methodId,
- List methodArgs) throws MalformedMemberNameException {
+ List methodArgs) throws MalformedMemberNameException {
super(refSpec);
this.methodId = methodId;
this.methodArgs = methodArgs;
@@ -83,7 +83,7 @@ class BreakpointSpec extends EventRequestSpec {
return lineNumber;
}
- List methodArgs() {
+ List methodArgs() {
return methodArgs;
}
@@ -146,14 +146,13 @@ class BreakpointSpec extends EventRequestSpec {
buffer.append('.');
buffer.append(methodId);
if (methodArgs != null) {
- Iterator iter = methodArgs.iterator();
boolean first = true;
buffer.append('(');
- while (iter.hasNext()) {
+ for (String arg : methodArgs) {
if (!first) {
buffer.append(',');
}
- buffer.append((String)iter.next());
+ buffer.append(arg);
first = false;
}
buffer.append(")");
@@ -176,12 +175,12 @@ class BreakpointSpec extends EventRequestSpec {
location = method.location();
} else {
// let AbsentInformationException be thrown
- List locs = refType.locationsOfLine(lineNumber());
+ List locs = refType.locationsOfLine(lineNumber());
if (locs.size() == 0) {
throw new LineNotFoundException();
}
// TO DO: handle multiple locations
- location = (Location)locs.get(0);
+ location = locs.get(0);
if (location.method() == null) {
throw new LineNotFoundException();
}
@@ -202,8 +201,8 @@ class BreakpointSpec extends EventRequestSpec {
* and if the number of arguments in the method matches the
* number of names passed
*/
- private boolean compareArgTypes(Method method, List nameList) {
- List argTypeNames = method.argumentTypeNames();
+ private boolean compareArgTypes(Method method, List nameList) {
+ List argTypeNames = method.argumentTypeNames();
// If argument counts differ, we can stop here
if (argTypeNames.size() != nameList.size()) {
@@ -213,8 +212,8 @@ class BreakpointSpec extends EventRequestSpec {
// Compare each argument type's name
int nTypes = argTypeNames.size();
for (int i = 0; i < nTypes; ++i) {
- String comp1 = (String)argTypeNames.get(i);
- String comp2 = (String)nameList.get(i);
+ String comp1 = argTypeNames.get(i);
+ String comp2 = nameList.get(i);
if (! comp1.equals(comp2)) {
/*
* We have to handle varargs. EG, the
@@ -331,22 +330,17 @@ class BreakpointSpec extends EventRequestSpec {
List argTypeNames = null;
if (methodArgs() != null) {
argTypeNames = new ArrayList(methodArgs().size());
- Iterator iter = methodArgs().iterator();
- while (iter.hasNext()) {
- String name = (String)iter.next();
+ for (String name : methodArgs()) {
name = normalizeArgTypeName(name);
argTypeNames.add(name);
}
}
// Check each method in the class for matches
- Iterator iter = refType.methods().iterator();
Method firstMatch = null; // first method with matching name
Method exactMatch = null; // (only) method with same name & sig
int matchCount = 0; // > 1 implies overload
- while (iter.hasNext()) {
- Method candidate = (Method)iter.next();
-
+ for (Method candidate : refType.methods()) {
if (candidate.name().equals(methodName())) {
matchCount++;
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java
index 0f913eabaec..e607d7165d4 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java
@@ -157,16 +157,16 @@ class Commands {
buf.append(method.name());
buf.append("(");
- List args = method.argumentTypeNames();
+ List args = method.argumentTypeNames();
int lastParam = args.size() - 1;
// output param types except for the last
for (int ii = 0; ii < lastParam; ii++) {
- buf.append((String)args.get(ii));
+ buf.append(args.get(ii));
buf.append(", ");
}
if (lastParam >= 0) {
// output the last param
- String lastStr = (String)args.get(lastParam);
+ String lastStr = args.get(lastParam);
if (method.isVarArgs()) {
// lastParam is an array. Replace the [] with ...
buf.append(lastStr.substring(0, lastStr.length() - 2));
@@ -180,12 +180,11 @@ class Commands {
}
void commandConnectors(VirtualMachineManager vmm) {
- Iterator iter = vmm.allConnectors().iterator();
- if (iter.hasNext()) {
+ Collection ccs = vmm.allConnectors();
+ if (ccs.isEmpty()) {
MessageOutput.println("Connectors available");
}
- while (iter.hasNext()) {
- Connector cc = (Connector)iter.next();
+ for (Connector cc : ccs) {
String transportName =
cc.transport() == null ? "null" : cc.transport().name();
MessageOutput.println();
@@ -193,10 +192,7 @@ class Commands {
new Object [] {cc.name(), transportName});
MessageOutput.println("Connector description", cc.description());
- Iterator argIter = cc.defaultArguments().values().iterator();
- if (argIter.hasNext()) {
- while (argIter.hasNext()) {
- Connector.Argument aa = (Connector.Argument)argIter.next();
+ for (Connector.Argument aa : cc.defaultArguments().values()) {
MessageOutput.println();
boolean requiredArgument = aa.mustSpecify();
@@ -215,16 +211,12 @@ class Commands {
}
}
- }
}
void commandClasses() {
- List list = Env.vm().allClasses();
-
StringBuffer classList = new StringBuffer();
- for (int i = 0 ; i < list.size() ; i++) {
- ReferenceType refType = (ReferenceType)list.get(i);
+ for (ReferenceType refType : Env.vm().allClasses()) {
classList.append(refType.name());
classList.append("\n");
}
@@ -232,7 +224,7 @@ class Commands {
}
void commandClass(StringTokenizer t) {
- List list = Env.vm().allClasses();
+ List list = Env.vm().allClasses();
if (!t.hasMoreTokens()) {
MessageOutput.println("No class specified.");
@@ -265,51 +257,31 @@ class Commands {
superclass = showAll ? superclass.superclass() : null;
}
- List interfaces = showAll ? clazz.allInterfaces()
- : clazz.interfaces();
- Iterator iter = interfaces.iterator();
- while (iter.hasNext()) {
- InterfaceType interfaze = (InterfaceType)iter.next();
+ List interfaces =
+ showAll ? clazz.allInterfaces() : clazz.interfaces();
+ for (InterfaceType interfaze : interfaces) {
MessageOutput.println("implements:", interfaze.name());
}
- List subs = clazz.subclasses();
- iter = subs.iterator();
- while (iter.hasNext()) {
- ClassType sub = (ClassType)iter.next();
+ for (ClassType sub : clazz.subclasses()) {
MessageOutput.println("subclass:", sub.name());
}
- List nested = clazz.nestedTypes();
- iter = nested.iterator();
- while (iter.hasNext()) {
- ReferenceType nest = (ReferenceType)iter.next();
+ for (ReferenceType nest : clazz.nestedTypes()) {
MessageOutput.println("nested:", nest.name());
}
} else if (type instanceof InterfaceType) {
InterfaceType interfaze = (InterfaceType)type;
MessageOutput.println("Interface:", interfaze.name());
- List supers = interfaze.superinterfaces();
- Iterator iter = supers.iterator();
- while (iter.hasNext()) {
- InterfaceType superinterface = (InterfaceType)iter.next();
+ for (InterfaceType superinterface : interfaze.superinterfaces()) {
MessageOutput.println("extends:", superinterface.name());
}
- List subs = interfaze.subinterfaces();
- iter = subs.iterator();
- while (iter.hasNext()) {
- InterfaceType sub = (InterfaceType)iter.next();
+ for (InterfaceType sub : interfaze.subinterfaces()) {
MessageOutput.println("subinterface:", sub.name());
}
- List implementors = interfaze.implementors();
- iter = implementors.iterator();
- while (iter.hasNext()) {
- ClassType implementor = (ClassType)iter.next();
+ for (ClassType implementor : interfaze.implementors()) {
MessageOutput.println("implementor:", implementor.name());
}
- List nested = interfaze.nestedTypes();
- iter = nested.iterator();
- while (iter.hasNext()) {
- ReferenceType nest = (ReferenceType)iter.next();
+ for (ReferenceType nest : interfaze.nestedTypes()) {
MessageOutput.println("nested:", nest.name());
}
} else { // array type
@@ -327,10 +299,8 @@ class Commands {
String idClass = t.nextToken();
ReferenceType cls = Env.getReferenceTypeFromToken(idClass);
if (cls != null) {
- List methods = cls.allMethods();
StringBuffer methodsList = new StringBuffer();
- for (int i = 0; i < methods.size(); i++) {
- Method method = (Method)methods.get(i);
+ for (Method method : cls.allMethods()) {
methodsList.append(method.declaringType().name());
methodsList.append(" ");
methodsList.append(typedName(method));
@@ -351,11 +321,10 @@ class Commands {
String idClass = t.nextToken();
ReferenceType cls = Env.getReferenceTypeFromToken(idClass);
if (cls != null) {
- List fields = cls.allFields();
- List visible = cls.visibleFields();
+ List fields = cls.allFields();
+ List visible = cls.visibleFields();
StringBuffer fieldsList = new StringBuffer();
- for (int i = 0; i < fields.size(); i++) {
- Field field = (Field)fields.get(i);
+ for (Field field : fields) {
String s;
if (!visible.contains(field)) {
s = MessageOutput.format("list field typename and name hidden",
@@ -386,7 +355,7 @@ class Commands {
int maxIdLength = 0;
int maxNameLength = 0;
while (threadIter.hasNext()) {
- ThreadReference thr = (ThreadReference)threadIter.next();
+ ThreadReference thr = threadIter.next();
maxIdLength = Math.max(maxIdLength,
Env.description(thr).length());
maxNameLength = Math.max(maxNameLength,
@@ -395,7 +364,7 @@ class Commands {
threadIter = new ThreadIterator(tg);
while (threadIter.hasNext()) {
- ThreadReference thr = (ThreadReference)threadIter.next();
+ ThreadReference thr = threadIter.next();
if (thr.threadGroup() == null) {
continue;
}
@@ -588,9 +557,7 @@ class Commands {
private List allThreads(ThreadGroupReference group) {
List list = new ArrayList();
list.addAll(group.threads());
- Iterator iter = group.threadGroups().iterator();
- while (iter.hasNext()) {
- ThreadGroupReference child = (ThreadGroupReference)iter.next();
+ for (ThreadGroupReference child : group.threadGroups()) {
list.addAll(allThreads(child));
}
return list;
@@ -641,10 +608,7 @@ class Commands {
* if so, it gets removed here.
*/
EventRequestManager mgr = Env.vm().eventRequestManager();
- List requests = mgr.stepRequests();
- Iterator iter = requests.iterator();
- while (iter.hasNext()) {
- StepRequest request = (StepRequest)iter.next();
+ for (StepRequest request : mgr.stepRequests()) {
if (request.thread().equals(thread)) {
mgr.deleteEventRequest(request);
break;
@@ -768,9 +732,7 @@ class Commands {
boolean noExceptions = true;
// Print a listing of the catch patterns currently in place
- Iterator iter = Env.specList.eventRequestSpecs().iterator();
- while (iter.hasNext()) {
- EventRequestSpec spec = (EventRequestSpec)iter.next();
+ for (EventRequestSpec spec : Env.specList.eventRequestSpecs()) {
if (spec instanceof ExceptionSpec) {
if (noExceptions) {
noExceptions = false;
@@ -928,7 +890,7 @@ class Commands {
}
private void dumpStack(ThreadInfo threadInfo, boolean showPC) {
- List stack = null;
+ List stack = null;
try {
stack = threadInfo.getStack();
} catch (IncompatibleThreadStateException e) {
@@ -940,7 +902,7 @@ class Commands {
} else {
int nFrames = stack.size();
for (int i = threadInfo.getCurrentFrameIndex(); i < nFrames; i++) {
- StackFrame frame = (StackFrame)stack.get(i);
+ StackFrame frame = stack.get(i);
dumpFrame (i, showPC, frame);
}
}
@@ -956,7 +918,7 @@ class Commands {
long lineNumber = loc.lineNumber();
String methodInfo = null;
- if (meth instanceof Method && ((Method)meth).isNative()) {
+ if (meth.isNative()) {
methodInfo = MessageOutput.format("native method");
} else if (lineNumber != -1) {
try {
@@ -994,9 +956,7 @@ class Commands {
} else {
String token = t.nextToken();
if (token.toLowerCase().equals("all")) {
- Iterator iter = ThreadInfo.threads().iterator();
- while (iter.hasNext()) {
- ThreadInfo threadInfo = (ThreadInfo)iter.next();
+ for (ThreadInfo threadInfo : ThreadInfo.threads()) {
MessageOutput.println("Thread:",
threadInfo.getThread().name());
dumpStack(threadInfo, showPC);
@@ -1051,9 +1011,7 @@ class Commands {
boolean noBreakpoints = true;
// Print set breakpoints
- Iterator iter = Env.specList.eventRequestSpecs().iterator();
- while (iter.hasNext()) {
- EventRequestSpec spec = (EventRequestSpec)iter.next();
+ for (EventRequestSpec spec : Env.specList.eventRequestSpecs()) {
if (spec instanceof BreakpointSpec) {
if (noBreakpoints) {
noBreakpoints = false;
@@ -1075,7 +1033,7 @@ class Commands {
protected BreakpointSpec parseBreakpointSpec(StringTokenizer t,
String atForm, String inForm) {
- EventRequestSpec breakpoint = null;
+ BreakpointSpec breakpoint = null;
try {
String token = t.nextToken(":( \t\n\r");
@@ -1149,7 +1107,7 @@ class Commands {
printBreakpointCommandUsage(atForm, inForm);
return null;
}
- return (BreakpointSpec)breakpoint;
+ return breakpoint;
}
private void resolveNow(EventRequestSpec spec) {
@@ -1209,8 +1167,8 @@ class Commands {
}
}
- private List parseWatchpointSpec(StringTokenizer t) {
- List list = new ArrayList();
+ private List parseWatchpointSpec(StringTokenizer t) {
+ List list = new ArrayList();
boolean access = false;
boolean modification = false;
int suspendPolicy = EventRequest.SUSPEND_ALL;
@@ -1242,7 +1200,7 @@ class Commands {
fieldName = fieldName.substring(dot+1);
try {
- EventRequestSpec spec;
+ WatchpointSpec spec;
if (access) {
spec = Env.specList.createAccessWatchpoint(className,
fieldName);
@@ -1269,9 +1227,8 @@ class Commands {
return;
}
- Iterator iter = parseWatchpointSpec(t).iterator();
- while (iter.hasNext()) {
- resolveNow((WatchpointSpec)iter.next());
+ for (WatchpointSpec spec : parseWatchpointSpec(t)) {
+ resolveNow(spec);
}
}
@@ -1281,9 +1238,7 @@ class Commands {
return;
}
- Iterator iter = parseWatchpointSpec(t).iterator();
- while (iter.hasNext()) {
- WatchpointSpec spec = (WatchpointSpec)iter.next();
+ for (WatchpointSpec spec : parseWatchpointSpec(t)) {
if (Env.specList.delete(spec)) {
MessageOutput.println("Removed:", spec.toString());
} else {
@@ -1482,7 +1437,7 @@ class Commands {
lineno = n.intValue();
} catch (java.text.ParseException jtpe) {
// It isn't -- see if it's a method name.
- List meths = refType.methodsByName(id);
+ List meths = refType.methodsByName(id);
if (meths == null || meths.size() == 0) {
MessageOutput.println("is not a valid line number or method name for",
new Object [] {id, refType.name()});
@@ -1492,7 +1447,7 @@ class Commands {
new Object [] {id, refType.name()});
return;
}
- loc = ((Method)meths.get(0)).location();
+ loc = meths.get(0).location();
lineno = loc.lineNumber();
}
}
@@ -1539,14 +1494,11 @@ class Commands {
try {
ReferenceType refType = Env.getReferenceTypeFromToken(idClass);
if (refType != null) {
- List lines = null;
+ List lines = null;
if (idMethod == null) {
lines = refType.allLineLocations();
} else {
- List methods = refType.allMethods();
- Iterator iter = methods.iterator();
- while (iter.hasNext()) {
- Method method = (Method)iter.next();
+ for (Method method : refType.allMethods()) {
if (method.name().equals(idMethod)) {
lines = method.allLineLocations();
}
@@ -1555,9 +1507,7 @@ class Commands {
MessageOutput.println("is not a valid method name", idMethod);
}
}
- Iterator iter = lines.iterator();
- while (iter.hasNext()) {
- Location line = (Location)iter.next();
+ for (Location line : lines) {
MessageOutput.printDirectln(line.toString());// Special case: use printDirectln()
}
} else {
@@ -1620,21 +1570,19 @@ class Commands {
MessageOutput.println("No local variables");
return;
}
- Map values = frame.getValues(vars);
+ Map values = frame.getValues(vars);
MessageOutput.println("Method arguments:");
- for (Iterator it = vars.iterator(); it.hasNext(); ) {
- LocalVariable var = (LocalVariable)it.next();
+ for (LocalVariable var : vars) {
if (var.isArgument()) {
- Value val = (Value)values.get(var);
+ Value val = values.get(var);
printVar(var, val);
}
}
MessageOutput.println("Local variables:");
- for (Iterator it = vars.iterator(); it.hasNext(); ) {
- LocalVariable var = (LocalVariable)it.next();
+ for (LocalVariable var : vars) {
if (!var.isArgument()) {
- Value val = (Value)values.get(var);
+ Value val = values.get(var);
printVar(var, val);
}
}
@@ -1647,9 +1595,8 @@ class Commands {
private void dump(ObjectReference obj, ReferenceType refType,
ReferenceType refTypeBase) {
- for (Iterator it = refType.fields().iterator(); it.hasNext(); ) {
+ for (Field field : refType.fields()) {
StringBuffer o = new StringBuffer();
- Field field = (Field)it.next();
o.append(" ");
if (!refType.equals(refTypeBase)) {
o.append(refType.name());
@@ -1666,14 +1613,13 @@ class Commands {
dump(obj, sup, refTypeBase);
}
} else if (refType instanceof InterfaceType) {
- List sups = ((InterfaceType)refType).superinterfaces();
- for (Iterator it = sups.iterator(); it.hasNext(); ) {
- dump(obj, (ReferenceType)it.next(), refTypeBase);
+ for (InterfaceType sup : ((InterfaceType)refType).superinterfaces()) {
+ dump(obj, sup, refTypeBase);
}
} else {
/* else refType is an instanceof ArrayType */
if (obj instanceof ArrayReference) {
- for (Iterator it = ((ArrayReference)obj).getValues().iterator();
+ for (Iterator it = ((ArrayReference)obj).getValues().iterator();
it.hasNext(); ) {
MessageOutput.printDirect(it.next().toString());// Special case: use printDirect()
if (it.hasNext()) {
@@ -1770,13 +1716,11 @@ class Commands {
new Object [] {owner.name(),
new Integer (object.entryCount())});
}
- List waiters = object.waitingThreads();
+ List waiters = object.waitingThreads();
if (waiters.size() == 0) {
MessageOutput.println("No waiters");
} else {
- Iterator iter = waiters.iterator();
- while (iter.hasNext()) {
- ThreadReference waiter = (ThreadReference)iter.next();
+ for (ThreadReference waiter : waiters) {
MessageOutput.println("Waiting thread:", waiter.name());
}
}
@@ -1800,13 +1744,11 @@ class Commands {
ThreadReference thread = threadInfo.getThread();
try {
MessageOutput.println("Monitor information for thread", thread.name());
- List owned = thread.ownedMonitors();
+ List owned = thread.ownedMonitors();
if (owned.size() == 0) {
MessageOutput.println("No monitors owned");
} else {
- Iterator iter = owned.iterator();
- while (iter.hasNext()) {
- ObjectReference monitor = (ObjectReference)iter.next();
+ for (ObjectReference monitor : owned) {
MessageOutput.println("Owned monitor:", monitor.toString());
}
}
@@ -1833,9 +1775,7 @@ class Commands {
}
String token = t.nextToken();
if (token.toLowerCase().equals("all")) {
- Iterator iter = ThreadInfo.threads().iterator();
- while (iter.hasNext()) {
- ThreadInfo threadInfo = (ThreadInfo)iter.next();
+ for (ThreadInfo threadInfo : ThreadInfo.threads()) {
printThreadLockInfo(threadInfo);
}
} else {
@@ -1930,14 +1870,12 @@ class Commands {
void commandSave(final StringTokenizer t) { // Undocumented command: useful for testing.
if (!t.hasMoreTokens()) {
- Set keys = Env.getSaveKeys();
- Iterator iter = keys.iterator();
- if (!iter.hasNext()) {
+ Set keys = Env.getSaveKeys();
+ if (keys.isEmpty()) {
MessageOutput.println("No saved values");
return;
}
- while (iter.hasNext()) {
- String key = (String)iter.next();
+ for (String key : keys) {
Value value = Env.getSavedValue(key);
if ((value instanceof ObjectReference) &&
((ObjectReference)value).isCollected()) {
@@ -1976,7 +1914,7 @@ class Commands {
// Overloading is not handled here.
String methodName = t.nextToken();
- List classes = Env.vm().classesByName(className);
+ List classes = Env.vm().classesByName(className);
// TO DO: handle multiple classes found
if (classes.size() == 0) {
if (className.indexOf('.') < 0) {
@@ -1987,17 +1925,14 @@ class Commands {
return;
}
- ReferenceType rt = (ReferenceType)classes.get(0);
+ ReferenceType rt = classes.get(0);
if (!(rt instanceof ClassType)) {
MessageOutput.println("not a class", className);
return;
}
byte[] bytecodes = null;
- List list = rt.methodsByName(methodName);
- Iterator iter = list.iterator();
- while (iter.hasNext()) {
- Method method = (Method)iter.next();
+ for (Method method : rt.methodsByName(methodName)) {
if (!method.isAbstract()) {
bytecodes = method.bytecodes();
break;
@@ -2047,7 +1982,7 @@ class Commands {
MessageOutput.println("Specify classes to redefine");
} else {
String className = t.nextToken();
- List classes = Env.vm().classesByName(className);
+ List classes = Env.vm().classesByName(className);
if (classes.size() == 0) {
MessageOutput.println("No class named", className);
return;
@@ -2057,7 +1992,7 @@ class Commands {
return;
}
Env.setSourcePath(Env.getSourcePath());
- ReferenceType refType = (ReferenceType)classes.get(0);
+ ReferenceType refType = classes.get(0);
if (!t.hasMoreTokens()) {
MessageOutput.println("Specify file name for class", className);
return;
@@ -2074,7 +2009,8 @@ class Commands {
new Object [] {fileName, exc.toString()});
return;
}
- Map map = new HashMap();
+ Map map
+ = new HashMap();
map.put(refType, bytes);
try {
Env.vm().redefineClasses(map);
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/Env.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/Env.java
index be3fb306a57..9d848a0205b 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/Env.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/Env.java
@@ -89,7 +89,7 @@ class Env {
sourceCache.clear();
}
- static void setSourcePath(List srcList) {
+ static void setSourcePath(List srcList) {
sourceMapper = new SourceMapper(srcList);
sourceCache.clear();
}
@@ -106,10 +106,8 @@ class Env {
}
static String excludesString() {
- Iterator iter = excludes().iterator();
StringBuffer buffer = new StringBuffer();
- while (iter.hasNext()) {
- String pattern = (String)iter.next();
+ for (String pattern : excludes()) {
buffer.append(pattern);
buffer.append(",");
}
@@ -117,25 +115,19 @@ class Env {
}
static void addExcludes(StepRequest request) {
- Iterator iter = excludes().iterator();
- while (iter.hasNext()) {
- String pattern = (String)iter.next();
+ for (String pattern : excludes()) {
request.addClassExclusionFilter(pattern);
}
}
static void addExcludes(MethodEntryRequest request) {
- Iterator iter = excludes().iterator();
- while (iter.hasNext()) {
- String pattern = (String)iter.next();
+ for (String pattern : excludes()) {
request.addClassExclusionFilter(pattern);
}
}
static void addExcludes(MethodExitRequest request) {
- Iterator iter = excludes().iterator();
- while (iter.hasNext()) {
- String pattern = (String)iter.next();
+ for (String pattern : excludes()) {
request.addClassExclusionFilter(pattern);
}
}
@@ -175,10 +167,10 @@ class Env {
try {
String fileName = location.sourceName();
- Iterator iter = sourceCache.iterator();
+ Iterator iter = sourceCache.iterator();
SourceCode code = null;
while (iter.hasNext()) {
- SourceCode candidate = (SourceCode)iter.next();
+ SourceCode candidate = iter.next();
if (candidate.fileName().equals(fileName)) {
code = candidate;
iter.remove();
@@ -269,10 +261,7 @@ class Env {
// loaded class whose name matches this limited regular
// expression is selected.
idToken = idToken.substring(1);
- List classes = Env.vm().allClasses();
- Iterator iter = classes.iterator();
- while (iter.hasNext()) {
- ReferenceType type = ((ReferenceType)iter.next());
+ for (ReferenceType type : Env.vm().allClasses()) {
if (type.name().endsWith(idToken)) {
cls = type;
break;
@@ -280,21 +269,21 @@ class Env {
}
} else {
// It's a class name
- List classes = Env.vm().classesByName(idToken);
+ List classes = Env.vm().classesByName(idToken);
if (classes.size() > 0) {
// TO DO: handle multiples
- cls = (ReferenceType)classes.get(0);
+ cls = classes.get(0);
}
}
return cls;
}
- static Set getSaveKeys() {
+ static Set getSaveKeys() {
return savedValues.keySet();
}
static Value getSavedValue(String key) {
- return (Value)savedValues.get(key);
+ return savedValues.get(key);
}
static void setSavedValue(String key, Value value) {
@@ -327,7 +316,7 @@ class Env {
if (index >= sourceLines.size()) {
return null;
} else {
- return (String)sourceLines.get(index);
+ return sourceLines.get(index);
}
}
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventHandler.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventHandler.java
index 27ef3913ece..ee80f9df538 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventHandler.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventHandler.java
@@ -150,7 +150,7 @@ public class EventHandler implements Runnable {
EventSet eventSet = queue.remove();
EventIterator iter = eventSet.eventIterator();
while (iter.hasNext()) {
- handleExitEvent((Event)iter.next());
+ handleExitEvent(iter.next());
}
} catch (InterruptedException exc) {
// ignore
@@ -183,7 +183,7 @@ public class EventHandler implements Runnable {
* If any event in the set has a thread associated with it,
* they all will, so just grab the first one.
*/
- Event event = (Event)set.iterator().next(); // Is there a better way?
+ Event event = set.iterator().next(); // Is there a better way?
thread = eventThread(event);
} else {
thread = null;
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventRequestSpec.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventRequestSpec.java
index bb86c2f3af0..7169e33f6f0 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventRequestSpec.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventRequestSpec.java
@@ -101,10 +101,8 @@ abstract class EventRequestSpec {
* so that is all we need to examine.
*/
ArrayList deleteList = new ArrayList();
- Iterator iter =
- Env.vm().eventRequestManager().exceptionRequests().iterator();
- while (iter.hasNext()) {
- ExceptionRequest er = (ExceptionRequest)iter.next();
+ for (ExceptionRequest er :
+ Env.vm().eventRequestManager().exceptionRequests()) {
if (prs.matches(er.exception())) {
deleteList.add (er);
}
@@ -115,9 +113,7 @@ abstract class EventRequestSpec {
}
private EventRequest resolveAgainstPreparedClasses() throws Exception {
- Iterator iter = Env.vm().allClasses().iterator();
- while (iter.hasNext()) {
- ReferenceType refType = (ReferenceType)iter.next();
+ for (ReferenceType refType : Env.vm().allClasses()) {
if (refType.isPrepared() && refSpec.matches(refType)) {
resolved = resolveEventRequest(refType);
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventRequestSpecList.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventRequestSpecList.java
index 2f3286d1a7e..e5741efc706 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventRequestSpecList.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/EventRequestSpecList.java
@@ -55,9 +55,7 @@ class EventRequestSpecList {
boolean resolve(ClassPrepareEvent event) {
boolean failure = false;
synchronized(eventRequestSpecs) {
- Iterator iter = eventRequestSpecs.iterator();
- while (iter.hasNext()) {
- EventRequestSpec spec = (EventRequestSpec)iter.next();
+ for (EventRequestSpec spec : eventRequestSpecs) {
if (!spec.isResolved()) {
try {
EventRequest eventRequest = spec.resolve(event);
@@ -77,9 +75,7 @@ class EventRequestSpecList {
}
void resolveAll() {
- Iterator iter = eventRequestSpecs.iterator();
- while (iter.hasNext()) {
- EventRequestSpec spec = (EventRequestSpec)iter.next();
+ for (EventRequestSpec spec : eventRequestSpecs) {
try {
EventRequest eventRequest = spec.resolveEagerly();
if (eventRequest != null) {
@@ -106,16 +102,16 @@ class EventRequestSpecList {
}
}
- EventRequestSpec createBreakpoint(String classPattern,
- int line) throws ClassNotFoundException {
+ BreakpointSpec createBreakpoint(String classPattern, int line)
+ throws ClassNotFoundException {
ReferenceTypeSpec refSpec =
new PatternReferenceTypeSpec(classPattern);
return new BreakpointSpec(refSpec, line);
}
- EventRequestSpec createBreakpoint(String classPattern,
+ BreakpointSpec createBreakpoint(String classPattern,
String methodId,
- List methodArgs)
+ List methodArgs)
throws MalformedMemberNameException,
ClassNotFoundException {
ReferenceTypeSpec refSpec =
@@ -132,7 +128,7 @@ class EventRequestSpecList {
return new ExceptionSpec(refSpec, notifyCaught, notifyUncaught);
}
- EventRequestSpec createAccessWatchpoint(String classPattern,
+ WatchpointSpec createAccessWatchpoint(String classPattern,
String fieldId)
throws MalformedMemberNameException,
ClassNotFoundException {
@@ -141,7 +137,7 @@ class EventRequestSpecList {
return new AccessWatchpointSpec(refSpec, fieldId);
}
- EventRequestSpec createModificationWatchpoint(String classPattern,
+ WatchpointSpec createModificationWatchpoint(String classPattern,
String fieldId)
throws MalformedMemberNameException,
ClassNotFoundException {
@@ -154,7 +150,7 @@ class EventRequestSpecList {
synchronized (eventRequestSpecs) {
int inx = eventRequestSpecs.indexOf(proto);
if (inx != -1) {
- EventRequestSpec spec = (EventRequestSpec)eventRequestSpecs.get(inx);
+ EventRequestSpec spec = eventRequestSpecs.get(inx);
spec.remove();
eventRequestSpecs.remove(inx);
return true;
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/SourceMapper.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/SourceMapper.java
index da8af944890..618f41a622c 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/SourceMapper.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/SourceMapper.java
@@ -39,15 +39,13 @@ class SourceMapper {
private final String[] dirs;
- SourceMapper(List sourcepath) {
+ SourceMapper(List sourcepath) {
/*
* sourcepath can arrive from the debugee as a List.
* (via PathSearchingVirtualMachine.classPath())
*/
List dirList = new ArrayList();
- Iterator iter = sourcepath.iterator();
- while (iter.hasNext()) {
- String element = (String)iter.next();
+ for (String element : sourcepath) {
//XXX remove .jar and .zip files; we want only directories on
//the source path. (Bug ID 4186582)
if ( ! (element.endsWith(".jar") ||
@@ -55,7 +53,7 @@ class SourceMapper {
dirList.add(element);
}
}
- dirs = (String[])dirList.toArray(new String[0]);
+ dirs = dirList.toArray(new String[0]);
}
SourceMapper(String sourcepath) {
@@ -79,7 +77,7 @@ class SourceMapper {
dirList.add(s);
}
}
- dirs = (String[])dirList.toArray(new String[0]);
+ dirs = dirList.toArray(new String[0]);
}
/*
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/TTY.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/TTY.java
index 620891af757..ec1dc51c6da 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/TTY.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/TTY.java
@@ -160,9 +160,7 @@ public class TTY implements EventNotifier {
// here the next time.
Env.setAtExitMethod(null);
EventRequestManager erm = Env.vm().eventRequestManager();
- Iterator it = erm.methodExitRequests().iterator();
- while (it.hasNext()) {
- EventRequest eReq = (EventRequest)it.next();
+ for (EventRequest eReq : erm.methodExitRequests()) {
if (eReq.equals(me.request())) {
eReq.disable();
}
@@ -178,9 +176,8 @@ public class TTY implements EventNotifier {
public void vmInterrupted() {
Thread.yield(); // fetch output
printCurrentLocation();
- Iterator it = monitorCommands.iterator();
- while (it.hasNext()) {
- StringTokenizer t = new StringTokenizer((String)it.next());
+ for (String cmd : monitorCommands) {
+ StringTokenizer t = new StringTokenizer(cmd);
t.nextToken(); // get rid of monitor number
executeCommand(t);
}
@@ -563,9 +560,8 @@ public class TTY implements EventNotifier {
++monitorCount;
monitorCommands.add(monitorCount + ": " + t.nextToken(""));
} else {
- Iterator it = monitorCommands.iterator();
- while (it.hasNext()) {
- MessageOutput.printDirectln((String)it.next());// Special case: use printDirectln()
+ for (String cmd : monitorCommands) {
+ MessageOutput.printDirectln(cmd);// Special case: use printDirectln()
}
}
}
@@ -581,9 +577,7 @@ public class TTY implements EventNotifier {
return;
}
String monStr = monTok + ":";
- Iterator it = monitorCommands.iterator();
- while (it.hasNext()) {
- String cmd = (String)it.next();
+ for (String cmd : monitorCommands) {
StringTokenizer ct = new StringTokenizer(cmd);
if (ct.nextToken().equals(monStr)) {
monitorCommands.remove(cmd);
@@ -768,10 +762,8 @@ public class TTY implements EventNotifier {
}
private static boolean supportsSharedMemory() {
- List connectors = Bootstrap.virtualMachineManager().allConnectors();
- Iterator iter = connectors.iterator();
- while (iter.hasNext()) {
- Connector connector = (Connector)iter.next();
+ for (Connector connector :
+ Bootstrap.virtualMachineManager().allConnectors()) {
if (connector.transport() == null) {
continue;
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadGroupIterator.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadGroupIterator.java
index c62a8822003..dc2dc118074 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadGroupIterator.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadGroupIterator.java
@@ -36,7 +36,7 @@ import java.util.Iterator;
* Descend the tree of thread groups.
* @author Robert G. Field
*/
-class ThreadGroupIterator implements Iterator {
+class ThreadGroupIterator implements Iterator {
private final Stack> stack = new Stack>();
ThreadGroupIterator(List tgl) {
@@ -53,8 +53,8 @@ class ThreadGroupIterator implements Iterator {
this(Env.vm().topLevelThreadGroups());
}
- private Iterator top() {
- return (Iterator)stack.peek();
+ private Iterator top() {
+ return stack.peek();
}
/**
@@ -74,12 +74,12 @@ class ThreadGroupIterator implements Iterator {
return !stack.isEmpty();
}
- public Object next() {
+ public ThreadGroupReference next() {
return nextThreadGroup();
}
public ThreadGroupReference nextThreadGroup() {
- ThreadGroupReference tg = (ThreadGroupReference)top().next();
+ ThreadGroupReference tg = top().next();
push(tg.threadGroups());
return tg;
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadInfo.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadInfo.java
index 97c6a880828..e823821c04c 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadInfo.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadInfo.java
@@ -56,9 +56,7 @@ class ThreadInfo {
private static void initThreads() {
if (!gotInitialThreads) {
- Iterator iter = Env.vm().allThreads().iterator();
- while (iter.hasNext()) {
- ThreadReference thread = (ThreadReference)iter.next();
+ for (ThreadReference thread : Env.vm().allThreads()) {
threads.add(new ThreadInfo(thread));
}
gotInitialThreads = true;
@@ -113,9 +111,7 @@ class ThreadInfo {
current = null;
group = null;
synchronized (threads) {
- Iterator iter = threads().iterator();
- while (iter.hasNext()) {
- ThreadInfo ti = (ThreadInfo)iter.next();
+ for (ThreadInfo ti : threads()) {
ti.invalidate();
}
}
@@ -163,8 +159,7 @@ class ThreadInfo {
if (group == null) {
// Current thread group defaults to the first top level
// thread group.
- setThreadGroup((ThreadGroupReference)
- Env.vm().topLevelThreadGroups().get(0));
+ setThreadGroup(Env.vm().topLevelThreadGroups().get(0));
}
return group;
}
@@ -173,9 +168,7 @@ class ThreadInfo {
ThreadInfo retInfo = null;
synchronized (threads) {
- Iterator iter = threads().iterator();
- while (iter.hasNext()) {
- ThreadInfo ti = (ThreadInfo)iter.next();
+ for (ThreadInfo ti : threads()) {
if (ti.thread.uniqueID() == id) {
retInfo = ti;
break;
@@ -208,7 +201,7 @@ class ThreadInfo {
*
* @return a List of the stack frames.
*/
- List getStack() throws IncompatibleThreadStateException {
+ List getStack() throws IncompatibleThreadStateException {
return thread.frames();
}
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadIterator.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadIterator.java
index b753cf742a3..8baff8ebd48 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadIterator.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadIterator.java
@@ -30,8 +30,8 @@ import com.sun.jdi.ThreadReference;
import java.util.List;
import java.util.Iterator;
-class ThreadIterator implements Iterator {
- Iterator it = null;
+class ThreadIterator implements Iterator {
+ Iterator it = null;
ThreadGroupIterator tgi;
ThreadIterator(ThreadGroupReference tg) {
@@ -56,12 +56,12 @@ class ThreadIterator implements Iterator {
return true;
}
- public Object next() {
+ public ThreadReference next() {
return it.next();
}
public ThreadReference nextThread() {
- return (ThreadReference)next();
+ return next();
}
public void remove() {
diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/VMConnection.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/VMConnection.java
index 6d3c3be20f8..7ab34280f89 100644
--- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/VMConnection.java
+++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/VMConnection.java
@@ -61,10 +61,8 @@ class VMConnection {
}
private Connector findConnector(String name) {
- List connectors = Bootstrap.virtualMachineManager().allConnectors();
- Iterator iter = connectors.iterator();
- while (iter.hasNext()) {
- Connector connector = (Connector)iter.next();
+ for (Connector connector :
+ Bootstrap.virtualMachineManager().allConnectors()) {
if (connector.name().equals(name)) {
return connector;
}
@@ -108,7 +106,7 @@ class VMConnection {
String value = token.substring(index + 1,
token.length() - 1); // Remove comma delimiter
- Connector.Argument argument = (Connector.Argument)arguments.get(name);
+ Connector.Argument argument = arguments.get(name);
if (argument == null) {
throw new IllegalArgumentException
(MessageOutput.format("Argument is not defined for connector:",
@@ -195,7 +193,7 @@ class VMConnection {
return false;
}
- Connector.Argument argument = (Connector.Argument)connectorArgs.get(name);
+ Connector.Argument argument = connectorArgs.get(name);
if (argument == null) {
return false;
}
@@ -204,7 +202,7 @@ class VMConnection {
}
String connectorArg(String name) {
- Connector.Argument argument = (Connector.Argument)connectorArgs.get(name);
+ Connector.Argument argument = connectorArgs.get(name);
if (argument == null) {
return "";
}
diff --git a/jdk/src/share/classes/com/sun/tools/hat/internal/server/ClassQuery.java b/jdk/src/share/classes/com/sun/tools/hat/internal/server/ClassQuery.java
index 60c48f1bce4..4fc235f7e2a 100644
--- a/jdk/src/share/classes/com/sun/tools/hat/internal/server/ClassQuery.java
+++ b/jdk/src/share/classes/com/sun/tools/hat/internal/server/ClassQuery.java
@@ -99,8 +99,7 @@ class ClassQuery extends QueryHandler {
}
out.println("Instance Data Members:
");
- JavaField[] ff = clazz.getFields();
- ff = (JavaField[]) ff.clone();
+ JavaField[] ff = clazz.getFields().clone();
ArraySorter.sort(ff, new Comparer() {
public int compare(Object lhs, Object rhs) {
JavaField left = (JavaField) lhs;
diff --git a/jdk/src/share/classes/com/sun/tools/hat/internal/server/PlatformClasses.java b/jdk/src/share/classes/com/sun/tools/hat/internal/server/PlatformClasses.java
index 1f6d3bf9d8f..24db65e2fe7 100644
--- a/jdk/src/share/classes/com/sun/tools/hat/internal/server/PlatformClasses.java
+++ b/jdk/src/share/classes/com/sun/tools/hat/internal/server/PlatformClasses.java
@@ -90,9 +90,7 @@ public class PlatformClasses {
// is the right thing to do anyway.
}
}
- int num = list.size();
- names = new String[num];
- names = (String[]) list.toArray(names);
+ names = list.toArray(new String[list.size()]);
}
return names;
}
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/AbstractLauncher.java b/jdk/src/share/classes/com/sun/tools/jdi/AbstractLauncher.java
index 23e9369050d..48d60f9d8b9 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/AbstractLauncher.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/AbstractLauncher.java
@@ -119,7 +119,7 @@ abstract class AbstractLauncher extends ConnectorImpl implements LaunchingConnec
String[] tokenArray = new String[tokenList.size()];
for (int i = 0; i < tokenList.size(); i++) {
- tokenArray[i] = (String)tokenList.get(i);
+ tokenArray[i] = tokenList.get(i);
}
return tokenArray;
}
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/ClassTypeImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/ClassTypeImpl.java
index fbb613b119a..3e68aa72746 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/ClassTypeImpl.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/ClassTypeImpl.java
@@ -95,11 +95,8 @@ public class ClassTypeImpl extends ReferenceTypeImpl
}
public List subclasses() {
- List all = vm.allClasses();
List subs = new ArrayList();
- Iterator iter = all.iterator();
- while (iter.hasNext()) {
- ReferenceType refType = (ReferenceType)iter.next();
+ for (ReferenceType refType : vm.allClasses()) {
if (refType instanceof ClassType) {
ClassType clazz = (ClassType)refType;
ClassType superclass = clazz.superclass();
@@ -223,7 +220,7 @@ public class ClassTypeImpl extends ReferenceTypeImpl
List extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
- ValueImpl[] args = (ValueImpl[])arguments.toArray(new ValueImpl[0]);
+ ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
JDWP.ClassType.InvokeMethod ret;
try {
PacketStream stream =
@@ -271,7 +268,7 @@ public class ClassTypeImpl extends ReferenceTypeImpl
List arguments = method.validateAndPrepareArgumentsForInvoke(
origArguments);
- ValueImpl[] args = (ValueImpl[])arguments.toArray(new ValueImpl[0]);
+ ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
JDWP.ClassType.NewInstance ret = null;
try {
PacketStream stream =
@@ -301,11 +298,8 @@ public class ClassTypeImpl extends ReferenceTypeImpl
}
public Method concreteMethodByName(String name, String signature) {
- List methods = visibleMethods();
Method method = null;
- Iterator iter = methods.iterator();
- while (iter.hasNext()) {
- Method candidate = (Method)iter.next();
+ for (Method candidate : visibleMethods()) {
if (candidate.name().equals(name) &&
candidate.signature().equals(signature) &&
!candidate.isAbstract()) {
@@ -330,9 +324,7 @@ public class ClassTypeImpl extends ReferenceTypeImpl
* Avoid duplicate checking on each method by iterating through
* duplicate-free allInterfaces() rather than recursing
*/
- Iterator iter = allInterfaces().iterator();
- while (iter.hasNext()) {
- InterfaceType interfaze = (InterfaceType)iter.next();
+ for (InterfaceType interfaze : allInterfaces()) {
list.addAll(interfaze.methods());
}
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/ConcreteMethodImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/ConcreteMethodImpl.java
index b5d52e6c3e8..6e44338cdfd 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/ConcreteMethodImpl.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/ConcreteMethodImpl.java
@@ -247,7 +247,7 @@ public class ConcreteMethodImpl extends MethodImpl {
public byte[] bytecodes() {
byte[] bytecodes = (bytecodesRef == null) ? null :
- (byte[])bytecodesRef.get();
+ bytecodesRef.get();
if (bytecodes == null) {
try {
bytecodes = JDWP.Method.Bytecodes.
@@ -262,7 +262,7 @@ public class ConcreteMethodImpl extends MethodImpl {
* to return the cached bytecodes directly; instead, we
* make a clone at the cost of using more memory.
*/
- return (byte[])bytecodes.clone();
+ return bytecodes.clone();
}
int argSlotCount() throws AbsentInformationException {
@@ -279,7 +279,7 @@ public class ConcreteMethodImpl extends MethodImpl {
String stratumID = stratum.id();
SoftLocationXRefs info =
(softOtherLocationXRefsRef == null) ? null :
- (SoftLocationXRefs)softOtherLocationXRefsRef.get();
+ softOtherLocationXRefsRef.get();
if (info != null && info.stratumID.equals(stratumID)) {
return info;
}
@@ -348,7 +348,7 @@ public class ConcreteMethodImpl extends MethodImpl {
private SoftLocationXRefs getBaseLocations() {
SoftLocationXRefs info = (softBaseLocationXRefsRef == null) ? null :
- (SoftLocationXRefs)softBaseLocationXRefsRef.get();
+ softBaseLocationXRefsRef.get();
if (info != null) {
return info;
}
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/EventSetImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/EventSetImpl.java
index da96ad494ce..1a2c61c7bc9 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/EventSetImpl.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/EventSetImpl.java
@@ -56,10 +56,8 @@ public class EventSetImpl extends ArrayList implements EventSet {
public String toString() {
String string = "event set, policy:" + suspendPolicy +
", count:" + this.size() + " = {";
- Iterator iter = this.iterator();
boolean first = true;
- while (iter.hasNext()) {
- Event event = (Event)iter.next();
+ for (Event event : this) {
if (!first) {
string += ", ";
}
@@ -787,9 +785,7 @@ public class EventSetImpl extends ArrayList implements EventSet {
}
private ThreadReference eventThread() {
- Iterator iter = this.iterator();
- while (iter.hasNext()) {
- Event event = (Event)iter.next();
+ for (Event event : this) {
if (event instanceof ThreadedEventImpl) {
return ((ThreadedEventImpl)event).thread();
}
@@ -846,7 +842,7 @@ public class EventSetImpl extends ArrayList implements EventSet {
}
public Event nextEvent() {
- return (Event)next();
+ return next();
}
public void remove() {
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/JNITypeParser.java b/jdk/src/share/classes/com/sun/tools/jdi/JNITypeParser.java
index 6151d5293e2..6add99fa6eb 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/JNITypeParser.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/JNITypeParser.java
@@ -82,7 +82,7 @@ public class JNITypeParser {
}
String typeName() {
- return (String)typeNameList().get(typeNameList().size()-1);
+ return typeNameList().get(typeNameList().size()-1);
}
List argumentTypeNames() {
@@ -90,7 +90,7 @@ public class JNITypeParser {
}
String signature() {
- return (String)signatureList().get(signatureList().size()-1);
+ return signatureList().get(signatureList().size()-1);
}
List argumentSignatures() {
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/MethodImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/MethodImpl.java
index 39664935521..4ad9da94882 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/MethodImpl.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/MethodImpl.java
@@ -158,7 +158,7 @@ public abstract class MethodImpl extends TypeComponentImpl
Type argumentType(int index) throws ClassNotLoadedException {
ReferenceTypeImpl enclosing = (ReferenceTypeImpl)declaringType();
- String signature = (String)argumentSignatures().get(index);
+ String signature = argumentSignatures().get(index);
return enclosing.findType(signature);
}
@@ -263,10 +263,10 @@ public abstract class MethodImpl extends TypeComponentImpl
return argumentType(index);
}
public String typeName(){
- return (String)argumentTypeNames().get(index);
+ return argumentTypeNames().get(index);
}
public String signature() {
- return (String)argumentSignatures().get(index);
+ return argumentSignatures().get(index);
}
public Type findType(String signature) throws ClassNotLoadedException {
return MethodImpl.this.findType(signature);
@@ -307,7 +307,7 @@ public abstract class MethodImpl extends TypeComponentImpl
arguments.add(argArray);
return;
}
- Value nthArgValue = (Value)arguments.get(paramCount - 1);
+ Value nthArgValue = arguments.get(paramCount - 1);
if (nthArgValue == null) {
return;
}
@@ -371,7 +371,7 @@ public abstract class MethodImpl extends TypeComponentImpl
}
for (int i = 0; i < argSize; i++) {
- Value value = (Value)arguments.get(i);
+ Value value = arguments.get(i);
value = ValueImpl.prepareForAssignment(value,
new ArgumentContainer(i));
arguments.set(i, value);
@@ -386,11 +386,11 @@ public abstract class MethodImpl extends TypeComponentImpl
sb.append(name());
sb.append("(");
boolean first = true;
- for (Iterator it = argumentTypeNames().iterator(); it.hasNext();) {
+ for (String name : argumentTypeNames()) {
if (!first) {
sb.append(", ");
}
- sb.append((String)it.next());
+ sb.append(name);
first = false;
}
sb.append(")");
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/ObjectReferenceImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/ObjectReferenceImpl.java
index 82aed8e96be..79f84cdb2b4 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/ObjectReferenceImpl.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/ObjectReferenceImpl.java
@@ -383,7 +383,7 @@ public class ObjectReferenceImpl extends ValueImpl
List arguments = method.validateAndPrepareArgumentsForInvoke(
origArguments);
- ValueImpl[] args = (ValueImpl[])arguments.toArray(new ValueImpl[0]);
+ ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
JDWP.ObjectReference.InvokeMethod ret;
try {
PacketStream stream =
@@ -583,7 +583,7 @@ public class ObjectReferenceImpl extends ValueImpl
// Validate assignment
ReferenceType destType = (ReferenceTypeImpl)destination.type();
ReferenceTypeImpl myType = (ReferenceTypeImpl)referenceType();
- if (!myType.isAssignableTo((ReferenceType)destType)) {
+ if (!myType.isAssignableTo(destType)) {
JNITypeParser parser = new JNITypeParser(destType.signature());
String destTypeName = parser.typeName();
throw new InvalidTypeException("Can't assign " +
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/PacketStream.java b/jdk/src/share/classes/com/sun/tools/jdi/PacketStream.java
index 5ad2fd1b451..65db8b31740 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/PacketStream.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/PacketStream.java
@@ -485,7 +485,7 @@ class PacketStream {
* Read field represented as vm specific byte sequence.
*/
Field readField() {
- ReferenceTypeImpl refType = (ReferenceTypeImpl)readReferenceType();
+ ReferenceTypeImpl refType = readReferenceType();
long fieldRef = readFieldRef();
return refType.getFieldMirror(fieldRef);
}
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java
index 4af0e8e8a45..f66c202f744 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java
@@ -59,7 +59,7 @@ implements ReferenceType {
private boolean constantPoolInfoGotten = false;
private int constanPoolCount;
private byte[] constantPoolBytes;
- private SoftReference constantPoolBytesRef = null;
+ private SoftReference constantPoolBytesRef = null;
/* to mark a SourceFile request that returned a genuine JDWP.Error.ABSENT_INFORMATION */
private static final String ABSENT_BASE_SOURCE_NAME = "**ABSENT_BASE_SOURCE_NAME**";
@@ -352,13 +352,10 @@ implements ReferenceType {
abstract List extends ReferenceType> inheritedTypes();
void addVisibleFields(List visibleList, Map visibleTable, List ambiguousNames) {
- List list = visibleFields();
- Iterator iter = list.iterator();
- while (iter.hasNext()) {
- Field field = (Field)iter.next();
+ for (Field field : visibleFields()) {
String name = field.name();
if (!ambiguousNames.contains(name)) {
- Field duplicate = (Field)visibleTable.get(name);
+ Field duplicate = visibleTable.get(name);
if (duplicate == null) {
visibleList.add(field);
visibleTable.put(name, field);
@@ -402,10 +399,8 @@ implements ReferenceType {
* hide.
*/
List retList = new ArrayList(fields());
- iter = retList.iterator();
- while (iter.hasNext()) {
- Field field = (Field)iter.next();
- Field hidden = (Field)visibleTable.get(field.name());
+ for (Field field : retList) {
+ Field hidden = visibleTable.get(field.name());
if (hidden != null) {
visibleList.remove(hidden);
}
@@ -515,12 +510,9 @@ implements ReferenceType {
* methods.
*/
void addToMethodMap(Map methodMap, List methodList) {
- Iterator iter = methodList.iterator();
- while (iter.hasNext()) {
- Method method = (Method)iter.next();
+ for (Method method : methodList)
methodMap.put(method.name().concat(method.signature()), method);
}
- }
abstract void addVisibleMethods(Map methodMap);
@@ -549,9 +541,7 @@ implements ReferenceType {
public List methodsByName(String name) {
List methods = visibleMethods();
ArrayList retList = new ArrayList(methods.size());
- Iterator iter = methods.iterator();
- while (iter.hasNext()) {
- Method candidate = (Method)iter.next();
+ for (Method candidate : methods) {
if (candidate.name().equals(name)) {
retList.add(candidate);
}
@@ -563,9 +553,7 @@ implements ReferenceType {
public List methodsByName(String name, String signature) {
List methods = visibleMethods();
ArrayList retList = new ArrayList(methods.size());
- Iterator iter = methods.iterator();
- while (iter.hasNext()) {
- Method candidate = (Method)iter.next();
+ for (Method candidate : methods) {
if (candidate.name().equals(name) &&
candidate.signature().equals(signature)) {
retList.add(candidate);
@@ -706,7 +694,7 @@ implements ReferenceType {
}
public String sourceName() throws AbsentInformationException {
- return (String)(sourceNames(vm.getDefaultStratum()).get(0));
+ return sourceNames(vm.getDefaultStratum()).get(0);
}
public List sourceNames(String stratumID)
@@ -796,7 +784,7 @@ implements ReferenceType {
if (!vm.canGetSourceDebugExtension()) {
return NO_SDE_INFO_MARK;
}
- SDE sde = (sdeRef == null) ? null : (SDE)sdeRef.get();
+ SDE sde = (sdeRef == null) ? null : sdeRef.get();
if (sde == null) {
String extension = null;
try {
@@ -1034,13 +1022,13 @@ implements ReferenceType {
throw exc;
}
if (constantPoolBytesRef != null) {
- byte[] cpbytes = (byte[])constantPoolBytesRef.get();
+ byte[] cpbytes = constantPoolBytesRef.get();
/*
* Arrays are always modifiable, so it is a little unsafe
* to return the cached bytecodes directly; instead, we
* make a clone at the cost of using more memory.
*/
- return (byte[])cpbytes.clone();
+ return cpbytes.clone();
} else {
return null;
}
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/SDE.java b/jdk/src/share/classes/com/sun/tools/jdi/SDE.java
index dd054c1ba0c..6f46c81f811 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/SDE.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/SDE.java
@@ -327,7 +327,7 @@ class SDE {
ignoreWhite();
while (((ch = sdeRead()) != '\n') && (ch != '\r')) {
- sb.append((char)ch);
+ sb.append(ch);
}
// check for CR LF
if ((ch == '\r') && (sdePeek() == '\n')) {
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/StackFrameImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/StackFrameImpl.java
index 5cfd2cbc901..a6f867379a0 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/StackFrameImpl.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/StackFrameImpl.java
@@ -162,7 +162,7 @@ public class StackFrameImpl extends MirrorImpl
for (LocalVariable variable : allVariables) {
String name = variable.name();
if (variable.isVisible(this)) {
- LocalVariable existing = (LocalVariable)map.get(name);
+ LocalVariable existing = map.get(name);
if ((existing == null) ||
((LocalVariableImpl)variable).hides(existing)) {
map.put(name, variable);
@@ -330,7 +330,7 @@ public class StackFrameImpl extends MirrorImpl
slot = 1;
}
for (int ii = 0; ii < count; ++ii) {
- char sigChar = (char)argSigs.get(ii).charAt(0);
+ char sigChar = argSigs.get(ii).charAt(0);
slots[ii] = new JDWP.StackFrame.GetValues.SlotInfo(slot++,(byte)sigChar);
if (sigChar == 'J' || sigChar == 'D') {
slot++;
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/TargetVM.java b/jdk/src/share/classes/com/sun/tools/jdi/TargetVM.java
index 2ff9bb1d126..54ae6af0de4 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/TargetVM.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/TargetVM.java
@@ -148,7 +148,7 @@ public class TargetVM implements Runnable {
idString = String.valueOf(p.id);
synchronized(waitingQueue) {
- p2 = (Packet)waitingQueue.get(idString);
+ p2 = waitingQueue.get(idString);
if (p2 != null)
waitingQueue.remove(idString);
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/ThreadGroupReferenceImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/ThreadGroupReferenceImpl.java
index 4e1286ba2e4..8dac1f3a330 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/ThreadGroupReferenceImpl.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/ThreadGroupReferenceImpl.java
@@ -86,30 +86,22 @@ public class ThreadGroupReferenceImpl extends ObjectReferenceImpl
}
public void suspend() {
- List threads = threads();
- Iterator iter = threads.iterator();
- while (iter.hasNext()) {
- ((ThreadReference)iter.next()).suspend();
+ for (ThreadReference thread : threads()) {
+ thread.suspend();
}
- List groups = threadGroups();
- iter = groups.iterator();
- while (iter.hasNext()) {
- ((ThreadGroupReference)iter.next()).suspend();
+ for (ThreadGroupReference threadGroup : threadGroups()) {
+ threadGroup.suspend();
}
}
public void resume() {
- List threads = threads();
- Iterator iter = threads.iterator();
- while (iter.hasNext()) {
- ((ThreadReference)iter.next()).resume();
+ for (ThreadReference thread : threads()) {
+ thread.resume();
}
- List groups = threadGroups();
- iter = groups.iterator();
- while (iter.hasNext()) {
- ((ThreadGroupReference)iter.next()).resume();
+ for (ThreadGroupReference threadGroup : threadGroups()) {
+ threadGroup.resume();
}
}
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java
index 54cb8974b72..e6dd311e152 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java
@@ -1191,8 +1191,7 @@ class VirtualMachineImpl extends MirrorImpl
}
requests = new JDWP.VirtualMachine.DisposeObjects.Request[size];
for (int i = 0; i < requests.length; i++) {
- SoftObjectReference ref =
- (SoftObjectReference)batchedDisposeRequests.get(i);
+ SoftObjectReference ref = batchedDisposeRequests.get(i);
if ((traceFlags & TRACE_OBJREFS) != 0) {
printTrace("Disposing object " + ref.key().longValue() +
" (ref count = " + ref.count() + ")");
@@ -1436,7 +1435,7 @@ class VirtualMachineImpl extends MirrorImpl
}
ObjectReferenceImpl object() {
- return (ObjectReferenceImpl)get();
+ return get();
}
}
}
diff --git a/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineManagerImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineManagerImpl.java
index 97131841074..2efcdd65154 100644
--- a/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineManagerImpl.java
+++ b/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineManagerImpl.java
@@ -92,7 +92,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManagerService {
Connector connector;
try {
- connector = (Connector)connectors.next();
+ connector = connectors.next();
} catch (ThreadDeath x) {
throw x;
} catch (Exception x) {
@@ -121,7 +121,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManagerService {
TransportService transportService;
try {
- transportService = (TransportService)transportServices.next();
+ transportService = transportServices.next();
} catch (ThreadDeath x) {
throw x;
} catch (Exception x) {
diff --git a/jdk/src/share/classes/java/io/ObjectInputStream.java b/jdk/src/share/classes/java/io/ObjectInputStream.java
index 9acc30cf7c1..d4dd289a3b3 100644
--- a/jdk/src/share/classes/java/io/ObjectInputStream.java
+++ b/jdk/src/share/classes/java/io/ObjectInputStream.java
@@ -212,7 +212,8 @@ public class ObjectInputStream
private static final Object unsharedMarker = new Object();
/** table mapping primitive type names to corresponding class objects */
- private static final HashMap primClasses = new HashMap(8, 1.0F);
+ private static final HashMap> primClasses
+ = new HashMap>(8, 1.0F);
static {
primClasses.put("boolean", boolean.class);
primClasses.put("byte", byte.class);
@@ -620,7 +621,7 @@ public class ObjectInputStream
try {
return Class.forName(name, false, latestUserDefinedLoader());
} catch (ClassNotFoundException ex) {
- Class cl = (Class) primClasses.get(name);
+ Class> cl = primClasses.get(name);
if (cl != null) {
return cl;
} else {
@@ -1254,11 +1255,11 @@ public class ObjectInputStream
* override security-sensitive non-final methods. Returns true if subclass
* is "safe", false otherwise.
*/
- private static boolean auditSubclass(final Class subcl) {
+ private static boolean auditSubclass(final Class> subcl) {
Boolean result = AccessController.doPrivileged(
new PrivilegedAction() {
public Boolean run() {
- for (Class cl = subcl;
+ for (Class> cl = subcl;
cl != ObjectInputStream.class;
cl = cl.getSuperclass())
{
@@ -2217,9 +2218,9 @@ public class ObjectInputStream
try {
while (list != null) {
AccessController.doPrivileged(
- new PrivilegedExceptionAction()
+ new PrivilegedExceptionAction()
{
- public Object run() throws InvalidObjectException {
+ public Void run() throws InvalidObjectException {
list.obj.validateObject();
return null;
}
diff --git a/jdk/src/share/classes/java/io/ObjectStreamClass.java b/jdk/src/share/classes/java/io/ObjectStreamClass.java
index 2a4553b11e9..af6da35458b 100644
--- a/jdk/src/share/classes/java/io/ObjectStreamClass.java
+++ b/jdk/src/share/classes/java/io/ObjectStreamClass.java
@@ -77,7 +77,7 @@ public class ObjectStreamClass implements Serializable {
NO_FIELDS;
/** reflection factory for obtaining serialization constructors */
- private static final ReflectionFactory reflFactory = (ReflectionFactory)
+ private static final ReflectionFactory reflFactory =
AccessController.doPrivileged(
new ReflectionFactory.GetReflectionFactoryAction());
@@ -216,10 +216,10 @@ public class ObjectStreamClass implements Serializable {
public long getSerialVersionUID() {
// REMIND: synchronize instead of relying on volatile?
if (suid == null) {
- suid = (Long) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return Long.valueOf(computeDefaultSUID(cl));
+ suid = AccessController.doPrivileged(
+ new PrivilegedAction() {
+ public Long run() {
+ return computeDefaultSUID(cl);
}
}
);
@@ -392,8 +392,8 @@ public class ObjectStreamClass implements Serializable {
}
if (interrupted) {
AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
+ new PrivilegedAction() {
+ public Void run() {
Thread.currentThread().interrupt();
return null;
}
@@ -427,8 +427,8 @@ public class ObjectStreamClass implements Serializable {
localDesc = this;
if (serializable) {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Void run() {
if (isEnum) {
suid = Long.valueOf(0);
fields = NO_FIELDS;
@@ -802,7 +802,7 @@ public class ObjectStreamClass implements Serializable {
* non-primitive types, and any other non-null type matches assignable
* types only. Returns matching field, or null if no match found.
*/
- ObjectStreamField getField(String name, Class type) {
+ ObjectStreamField getField(String name, Class> type) {
for (int i = 0; i < fields.length; i++) {
ObjectStreamField f = fields[i];
if (f.getName().equals(name)) {
@@ -811,7 +811,7 @@ public class ObjectStreamClass implements Serializable {
{
return f;
}
- Class ftype = f.getType();
+ Class> ftype = f.getType();
if (ftype != null && type.isAssignableFrom(ftype)) {
return f;
}
@@ -1130,7 +1130,7 @@ public class ObjectStreamClass implements Serializable {
private ClassDataSlot[] getClassDataLayout0()
throws InvalidClassException
{
- ArrayList slots = new ArrayList();
+ ArrayList slots = new ArrayList();
Class start = cl, end = cl;
// locate closest non-serializable superclass
@@ -1171,8 +1171,7 @@ public class ObjectStreamClass implements Serializable {
// order slots from superclass -> subclass
Collections.reverse(slots);
- return (ClassDataSlot[])
- slots.toArray(new ClassDataSlot[slots.size()]);
+ return slots.toArray(new ClassDataSlot[slots.size()]);
}
/**
@@ -1309,9 +1308,9 @@ public class ObjectStreamClass implements Serializable {
* Access checks are disabled on the returned constructor (if any), since
* the defining class may still be non-public.
*/
- private static Constructor getExternalizableConstructor(Class cl) {
+ private static Constructor getExternalizableConstructor(Class> cl) {
try {
- Constructor cons = cl.getDeclaredConstructor((Class[]) null);
+ Constructor cons = cl.getDeclaredConstructor((Class>[]) null);
cons.setAccessible(true);
return ((cons.getModifiers() & Modifier.PUBLIC) != 0) ?
cons : null;
@@ -1325,15 +1324,15 @@ public class ObjectStreamClass implements Serializable {
* superclass, or null if none found. Access checks are disabled on the
* returned constructor (if any).
*/
- private static Constructor getSerializableConstructor(Class cl) {
- Class initCl = cl;
+ private static Constructor getSerializableConstructor(Class> cl) {
+ Class> initCl = cl;
while (Serializable.class.isAssignableFrom(initCl)) {
if ((initCl = initCl.getSuperclass()) == null) {
return null;
}
}
try {
- Constructor cons = initCl.getDeclaredConstructor((Class[]) null);
+ Constructor cons = initCl.getDeclaredConstructor((Class>[]) null);
int mods = cons.getModifiers();
if ((mods & Modifier.PRIVATE) != 0 ||
((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
@@ -1355,12 +1354,12 @@ public class ObjectStreamClass implements Serializable {
* null if no match found. Access checks are disabled on the returned
* method (if any).
*/
- private static Method getInheritableMethod(Class cl, String name,
+ private static Method getInheritableMethod(Class> cl, String name,
Class[] argTypes,
Class returnType)
{
Method meth = null;
- Class defCl = cl;
+ Class> defCl = cl;
while (defCl != null) {
try {
meth = defCl.getDeclaredMethod(name, argTypes);
@@ -1391,9 +1390,9 @@ public class ObjectStreamClass implements Serializable {
* class, or null if none found. Access checks are disabled on the
* returned method (if any).
*/
- private static Method getPrivateMethod(Class cl, String name,
- Class[] argTypes,
- Class returnType)
+ private static Method getPrivateMethod(Class> cl, String name,
+ Class>[] argTypes,
+ Class> returnType)
{
try {
Method meth = cl.getDeclaredMethod(name, argTypes);
@@ -1567,7 +1566,7 @@ public class ObjectStreamClass implements Serializable {
ObjectStreamField[] boundFields =
new ObjectStreamField[serialPersistentFields.length];
- Set fieldNames = new HashSet(serialPersistentFields.length);
+ Set fieldNames = new HashSet(serialPersistentFields.length);
for (int i = 0; i < serialPersistentFields.length; i++) {
ObjectStreamField spf = serialPersistentFields[i];
@@ -1605,7 +1604,7 @@ public class ObjectStreamClass implements Serializable {
*/
private static ObjectStreamField[] getDefaultSerialFields(Class cl) {
Field[] clFields = cl.getDeclaredFields();
- ArrayList list = new ArrayList();
+ ArrayList list = new ArrayList();
int mask = Modifier.STATIC | Modifier.TRANSIENT;
for (int i = 0; i < clFields.length; i++) {
@@ -1615,7 +1614,7 @@ public class ObjectStreamClass implements Serializable {
}
int size = list.size();
return (size == 0) ? NO_FIELDS :
- (ObjectStreamField[]) list.toArray(new ObjectStreamField[size]);
+ list.toArray(new ObjectStreamField[size]);
}
/**
@@ -1688,11 +1687,9 @@ public class ObjectStreamClass implements Serializable {
for (int i = 0; i < fields.length; i++) {
fieldSigs[i] = new MemberSignature(fields[i]);
}
- Arrays.sort(fieldSigs, new Comparator() {
- public int compare(Object o1, Object o2) {
- String name1 = ((MemberSignature) o1).name;
- String name2 = ((MemberSignature) o2).name;
- return name1.compareTo(name2);
+ Arrays.sort(fieldSigs, new Comparator() {
+ public int compare(MemberSignature ms1, MemberSignature ms2) {
+ return ms1.name.compareTo(ms2.name);
}
});
for (int i = 0; i < fieldSigs.length; i++) {
@@ -1721,11 +1718,9 @@ public class ObjectStreamClass implements Serializable {
for (int i = 0; i < cons.length; i++) {
consSigs[i] = new MemberSignature(cons[i]);
}
- Arrays.sort(consSigs, new Comparator() {
- public int compare(Object o1, Object o2) {
- String sig1 = ((MemberSignature) o1).signature;
- String sig2 = ((MemberSignature) o2).signature;
- return sig1.compareTo(sig2);
+ Arrays.sort(consSigs, new Comparator() {
+ public int compare(MemberSignature ms1, MemberSignature ms2) {
+ return ms1.signature.compareTo(ms2.signature);
}
});
for (int i = 0; i < consSigs.length; i++) {
@@ -1746,10 +1741,8 @@ public class ObjectStreamClass implements Serializable {
for (int i = 0; i < methods.length; i++) {
methSigs[i] = new MemberSignature(methods[i]);
}
- Arrays.sort(methSigs, new Comparator() {
- public int compare(Object o1, Object o2) {
- MemberSignature ms1 = (MemberSignature) o1;
- MemberSignature ms2 = (MemberSignature) o2;
+ Arrays.sort(methSigs, new Comparator() {
+ public int compare(MemberSignature ms1, MemberSignature ms2) {
int comp = ms1.name.compareTo(ms2.name);
if (comp == 0) {
comp = ms1.signature.compareTo(ms2.signature);
@@ -1859,7 +1852,7 @@ public class ObjectStreamClass implements Serializable {
keys = new long[nfields];
offsets = new int[nfields];
typeCodes = new char[nfields];
- ArrayList typeList = new ArrayList();
+ ArrayList> typeList = new ArrayList>();
for (int i = 0; i < nfields; i++) {
ObjectStreamField f = fields[i];
@@ -1873,7 +1866,7 @@ public class ObjectStreamClass implements Serializable {
}
}
- types = (Class[]) typeList.toArray(new Class[typeList.size()]);
+ types = typeList.toArray(new Class>[typeList.size()]);
numPrimFields = nfields - types.length;
}
diff --git a/jdk/src/share/classes/java/lang/Class.java b/jdk/src/share/classes/java/lang/Class.java
index 6d878c56e78..632ddb6ed0e 100644
--- a/jdk/src/share/classes/java/lang/Class.java
+++ b/jdk/src/share/classes/java/lang/Class.java
@@ -345,9 +345,9 @@ public final
// since we have to do the security check here anyway
// (the stack depth is wrong for the Constructor's
// security check to work)
- java.security.AccessController.doPrivileged
- (new java.security.PrivilegedAction() {
- public Object run() {
+ java.security.AccessController.doPrivileged(
+ new java.security.PrivilegedAction() {
+ public Void run() {
c.setAccessible(true);
return null;
}
@@ -1302,10 +1302,10 @@ public final
// out anything other than public members and (2) public member access
// has already been ok'd by the SecurityManager.
- Class[] result = (Class[]) java.security.AccessController.doPrivileged
- (new java.security.PrivilegedAction() {
- public Object run() {
- java.util.List list = new java.util.ArrayList();
+ return java.security.AccessController.doPrivileged(
+ new java.security.PrivilegedAction() {
+ public Class[] run() {
+ List list = new ArrayList();
Class currentClass = Class.this;
while (currentClass != null) {
Class[] members = currentClass.getDeclaredClasses();
@@ -1316,12 +1316,9 @@ public final
}
currentClass = currentClass.getSuperclass();
}
- Class[] empty = {};
- return list.toArray(empty);
+ return list.toArray(new Class[0]);
}
});
-
- return result;
}
@@ -2215,15 +2212,15 @@ public final
// Caches for certain reflective results
private static boolean useCaches = true;
- private volatile transient SoftReference declaredFields;
- private volatile transient SoftReference publicFields;
- private volatile transient SoftReference declaredMethods;
- private volatile transient SoftReference publicMethods;
- private volatile transient SoftReference declaredConstructors;
- private volatile transient SoftReference publicConstructors;
+ private volatile transient SoftReference declaredFields;
+ private volatile transient SoftReference publicFields;
+ private volatile transient SoftReference declaredMethods;
+ private volatile transient SoftReference publicMethods;
+ private volatile transient SoftReference[]> declaredConstructors;
+ private volatile transient SoftReference[]> publicConstructors;
// Intermediate results for getFields and getMethods
- private volatile transient SoftReference declaredPublicFields;
- private volatile transient SoftReference declaredPublicMethods;
+ private volatile transient SoftReference declaredPublicFields;
+ private volatile transient SoftReference declaredPublicMethods;
// Incremented by the VM on each call to JVM TI RedefineClasses()
// that redefines this class or a superclass.
@@ -2295,11 +2292,11 @@ public final
clearCachesOnClassRedefinition();
if (publicOnly) {
if (declaredPublicFields != null) {
- res = (Field[]) declaredPublicFields.get();
+ res = declaredPublicFields.get();
}
} else {
if (declaredFields != null) {
- res = (Field[]) declaredFields.get();
+ res = declaredFields.get();
}
}
if (res != null) return res;
@@ -2308,9 +2305,9 @@ public final
res = Reflection.filterFields(this, getDeclaredFields0(publicOnly));
if (useCaches) {
if (publicOnly) {
- declaredPublicFields = new SoftReference(res);
+ declaredPublicFields = new SoftReference(res);
} else {
- declaredFields = new SoftReference(res);
+ declaredFields = new SoftReference(res);
}
}
return res;
@@ -2319,22 +2316,22 @@ public final
// Returns an array of "root" fields. These Field objects must NOT
// be propagated to the outside world, but must instead be copied
// via ReflectionFactory.copyField.
- private Field[] privateGetPublicFields(Set traversedInterfaces) {
+ private Field[] privateGetPublicFields(Set> traversedInterfaces) {
checkInitted();
Field[] res = null;
if (useCaches) {
clearCachesOnClassRedefinition();
if (publicFields != null) {
- res = (Field[]) publicFields.get();
+ res = publicFields.get();
}
if (res != null) return res;
}
// No cached value available; compute value recursively.
// Traverse in correct order for getField().
- List fields = new ArrayList();
+ List fields = new ArrayList();
if (traversedInterfaces == null) {
- traversedInterfaces = new HashSet();
+ traversedInterfaces = new HashSet>();
}
// Local fields
@@ -2342,9 +2339,7 @@ public final
addAll(fields, tmp);
// Direct superinterfaces, recursively
- Class[] interfaces = getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- Class c = interfaces[i];
+ for (Class> c : getInterfaces()) {
if (!traversedInterfaces.contains(c)) {
traversedInterfaces.add(c);
addAll(fields, c.privateGetPublicFields(traversedInterfaces));
@@ -2353,7 +2348,7 @@ public final
// Direct superclass, recursively
if (!isInterface()) {
- Class c = getSuperclass();
+ Class> c = getSuperclass();
if (c != null) {
addAll(fields, c.privateGetPublicFields(traversedInterfaces));
}
@@ -2362,12 +2357,12 @@ public final
res = new Field[fields.size()];
fields.toArray(res);
if (useCaches) {
- publicFields = new SoftReference(res);
+ publicFields = new SoftReference(res);
}
return res;
}
- private static void addAll(Collection c, Field[] o) {
+ private static void addAll(Collection c, Field[] o) {
for (int i = 0; i < o.length; i++) {
c.add(o[i]);
}
@@ -2383,18 +2378,18 @@ public final
// Returns an array of "root" constructors. These Constructor
// objects must NOT be propagated to the outside world, but must
// instead be copied via ReflectionFactory.copyConstructor.
- private Constructor[] privateGetDeclaredConstructors(boolean publicOnly) {
+ private Constructor[] privateGetDeclaredConstructors(boolean publicOnly) {
checkInitted();
- Constructor[] res = null;
+ Constructor[] res = null;
if (useCaches) {
clearCachesOnClassRedefinition();
if (publicOnly) {
if (publicConstructors != null) {
- res = (Constructor[]) publicConstructors.get();
+ res = publicConstructors.get();
}
} else {
if (declaredConstructors != null) {
- res = (Constructor[]) declaredConstructors.get();
+ res = declaredConstructors.get();
}
}
if (res != null) return res;
@@ -2407,9 +2402,9 @@ public final
}
if (useCaches) {
if (publicOnly) {
- publicConstructors = new SoftReference(res);
+ publicConstructors = new SoftReference[]>(res);
} else {
- declaredConstructors = new SoftReference(res);
+ declaredConstructors = new SoftReference[]>(res);
}
}
return res;
@@ -2431,11 +2426,11 @@ public final
clearCachesOnClassRedefinition();
if (publicOnly) {
if (declaredPublicMethods != null) {
- res = (Method[]) declaredPublicMethods.get();
+ res = declaredPublicMethods.get();
}
} else {
if (declaredMethods != null) {
- res = (Method[]) declaredMethods.get();
+ res = declaredMethods.get();
}
}
if (res != null) return res;
@@ -2444,9 +2439,9 @@ public final
res = Reflection.filterMethods(this, getDeclaredMethods0(publicOnly));
if (useCaches) {
if (publicOnly) {
- declaredPublicMethods = new SoftReference(res);
+ declaredPublicMethods = new SoftReference(res);
} else {
- declaredMethods = new SoftReference(res);
+ declaredMethods = new SoftReference(res);
}
}
return res;
@@ -2552,7 +2547,7 @@ public final
if (useCaches) {
clearCachesOnClassRedefinition();
if (publicMethods != null) {
- res = (Method[]) publicMethods.get();
+ res = publicMethods.get();
}
if (res != null) return res;
}
@@ -2602,7 +2597,7 @@ public final
methods.compactAndTrim();
res = methods.getArray();
if (useCaches) {
- publicMethods = new SoftReference(res);
+ publicMethods = new SoftReference(res);
}
return res;
}
@@ -2713,11 +2708,11 @@ public final
private Constructor getConstructor0(Class[] parameterTypes,
int which) throws NoSuchMethodException
{
- Constructor[] constructors = privateGetDeclaredConstructors((which == Member.PUBLIC));
- for (int i = 0; i < constructors.length; i++) {
+ Constructor[] constructors = privateGetDeclaredConstructors((which == Member.PUBLIC));
+ for (Constructor constructor : constructors) {
if (arrayContentsEq(parameterTypes,
- constructors[i].getParameterTypes())) {
- return getReflectionFactory().copyConstructor(constructors[i]);
+ constructor.getParameterTypes())) {
+ return getReflectionFactory().copyConstructor(constructor);
}
}
throw new NoSuchMethodException(getName() + "." + argumentTypesToString(parameterTypes));
@@ -2767,18 +2762,18 @@ public final
return out;
}
- private static Constructor[] copyConstructors(Constructor[] arg) {
- Constructor[] out = new Constructor[arg.length];
+ private static Constructor[] copyConstructors(Constructor[] arg) {
+ Constructor[] out = arg.clone();
ReflectionFactory fact = getReflectionFactory();
- for (int i = 0; i < arg.length; i++) {
- out[i] = fact.copyConstructor(arg[i]);
+ for (int i = 0; i < out.length; i++) {
+ out[i] = fact.copyConstructor(out[i]);
}
return out;
}
private native Field[] getDeclaredFields0(boolean publicOnly);
private native Method[] getDeclaredMethods0(boolean publicOnly);
- private native Constructor[] getDeclaredConstructors0(boolean publicOnly);
+ private native Constructor[] getDeclaredConstructors0(boolean publicOnly);
private native Class[] getDeclaredClasses0();
private static String argumentTypesToString(Class[] argTypes) {
@@ -2883,7 +2878,7 @@ public final
// Fetches the factory for reflective objects
private static ReflectionFactory getReflectionFactory() {
if (reflectionFactory == null) {
- reflectionFactory = (ReflectionFactory)
+ reflectionFactory =
java.security.AccessController.doPrivileged
(new sun.reflect.ReflectionFactory.GetReflectionFactoryAction());
}
@@ -2895,8 +2890,8 @@ public final
private static boolean initted = false;
private static void checkInitted() {
if (initted) return;
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Void run() {
// Tests to ensure the system properties table is fully
// initialized. This is needed because reflection code is
// called very early in the initialization process (before
@@ -2941,17 +2936,17 @@ public final
/**
* Returns the elements of this enum class or null if this
* Class object does not represent an enum type;
- * identical to getEnumConstantsShared except that
- * the result is uncloned, cached, and shared by all callers.
+ * identical to getEnumConstants except that the result is
+ * uncloned, cached, and shared by all callers.
*/
T[] getEnumConstantsShared() {
if (enumConstants == null) {
if (!isEnum()) return null;
try {
final Method values = getMethod("values");
- java.security.AccessController.doPrivileged
- (new java.security.PrivilegedAction() {
- public Object run() {
+ java.security.AccessController.doPrivileged(
+ new java.security.PrivilegedAction() {
+ public Void run() {
values.setAccessible(true);
return null;
}
diff --git a/jdk/src/share/classes/java/lang/ClassLoader.java b/jdk/src/share/classes/java/lang/ClassLoader.java
index 391354ec38b..1b188e23f7c 100644
--- a/jdk/src/share/classes/java/lang/ClassLoader.java
+++ b/jdk/src/share/classes/java/lang/ClassLoader.java
@@ -39,6 +39,7 @@ import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
+import java.security.cert.Certificate;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.HashMap;
@@ -172,17 +173,18 @@ public abstract class ClassLoader {
private ClassLoader parent;
// Hashtable that maps packages to certs
- private Hashtable package2certs = new Hashtable(11);
+ private Hashtable package2certs
+ = new Hashtable(11);
// Shared among all packages with unsigned classes
- java.security.cert.Certificate[] nocerts;
+ Certificate[] nocerts;
// The classes loaded by this class loader. The only purpose of this table
// is to keep the classes from being GC'ed until the loader is GC'ed.
- private Vector classes = new Vector();
+ private Vector> classes = new Vector>();
// The initiating protection domains for all classes loaded by this loader
- private Set domains = new HashSet();
+ private Set domains = new HashSet();
// Invoked by the VM to record every loaded class with this loader.
void addClass(Class c) {
@@ -191,7 +193,7 @@ public abstract class ClassLoader {
// The packages defined in this class loader. Each package name is mapped
// to its corresponding Package object.
- private HashMap packages = new HashMap();
+ private HashMap packages = new HashMap();
/**
* Creates a new class loader using the specified parent class loader for
@@ -342,8 +344,8 @@ public abstract class ClassLoader {
final String name = cls.getName();
final int i = name.lastIndexOf('.');
if (i != -1) {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Void run() {
sm.checkPackageAccess(name.substring(0, i));
return null;
}
@@ -524,17 +526,20 @@ public abstract class ClassLoader {
// Class format error - try to transform the bytecode and
// define the class again
//
- Object[] transformers = ClassFileTransformer.getTransformers();
+ ClassFileTransformer[] transformers = ClassFileTransformer.getTransformers();
Class c = null;
- for (int i = 0; transformers != null && i < transformers.length; i++) {
- try {
- // Transform byte code using transformer
- byte[] tb = ((ClassFileTransformer) transformers[i]).transform(b, off, len);
- c = defineClass1(name, tb, 0, tb.length, protectionDomain, source);
- break;
- } catch (ClassFormatError cfe2) {
- // If ClassFormatError occurs, try next transformer
+ if (transformers != null) {
+ for (ClassFileTransformer transformer : transformers) {
+ try {
+ // Transform byte code using transformer
+ byte[] tb = transformer.transform(b, off, len);
+ c = defineClass1(name, tb, 0, tb.length,
+ protectionDomain, source);
+ break;
+ } catch (ClassFormatError cfe2) {
+ // If ClassFormatError occurs, try next transformer
+ }
}
}
@@ -550,7 +555,7 @@ public abstract class ClassLoader {
private void postDefineClass(Class c, ProtectionDomain protectionDomain)
{
if (protectionDomain.getCodeSource() != null) {
- java.security.cert.Certificate certs[] =
+ Certificate certs[] =
protectionDomain.getCodeSource().getCertificates();
if (certs != null)
setSigners(c, certs);
@@ -767,8 +772,7 @@ public abstract class ClassLoader {
private synchronized void checkCerts(String name, CodeSource cs) {
int i = name.lastIndexOf('.');
String pname = (i == -1) ? "" : name.substring(0, i);
- java.security.cert.Certificate[] pcerts =
- (java.security.cert.Certificate[]) package2certs.get(pname);
+ Certificate[] pcerts = package2certs.get(pname);
if (pcerts == null) {
// first class in this package gets to define which
// certificates must be the same for all other classes
@@ -778,12 +782,12 @@ public abstract class ClassLoader {
}
if (pcerts == null) {
if (nocerts == null)
- nocerts = new java.security.cert.Certificate[0];
+ nocerts = new Certificate[0];
pcerts = nocerts;
}
package2certs.put(pname, pcerts);
} else {
- java.security.cert.Certificate[] certs = null;
+ Certificate[] certs = null;
if (cs != null) {
certs = cs.getCertificates();
}
@@ -799,8 +803,8 @@ public abstract class ClassLoader {
* check to make sure the certs for the new class (certs) are the same as
* the certs for the first class inserted in the package (pcerts)
*/
- private boolean compareCerts(java.security.cert.Certificate[] pcerts,
- java.security.cert.Certificate[] certs)
+ private boolean compareCerts(Certificate[] pcerts,
+ Certificate[] certs)
{
// certs can be null, indicating no certs.
if ((certs == null) || (certs.length == 0)) {
@@ -1031,7 +1035,7 @@ public abstract class ClassLoader {
}
tmp[1] = findResources(name);
- return new CompoundEnumeration(tmp);
+ return new CompoundEnumeration(tmp);
}
/**
@@ -1068,7 +1072,7 @@ public abstract class ClassLoader {
* @since 1.2
*/
protected Enumeration findResources(String name) throws IOException {
- return new CompoundEnumeration(new Enumeration[0]);
+ return java.util.Collections.emptyEnumeration();
}
/**
@@ -1134,13 +1138,13 @@ public abstract class ClassLoader {
/**
* Find resources from the VM's built-in classloader.
*/
- private static Enumeration getBootstrapResources(String name)
+ private static Enumeration getBootstrapResources(String name)
throws IOException
{
- final Enumeration e = getBootstrapClassPath().getResources(name);
- return new Enumeration () {
- public Object nextElement() {
- return ((Resource)e.nextElement()).getURL();
+ final Enumeration e = getBootstrapClassPath().getResources(name);
+ return new Enumeration () {
+ public URL nextElement() {
+ return e.nextElement().getURL();
}
public boolean hasMoreElements() {
return e.hasMoreElements();
@@ -1323,9 +1327,8 @@ public abstract class ClassLoader {
Throwable oops = null;
scl = l.getClassLoader();
try {
- PrivilegedExceptionAction a;
- a = new SystemClassLoaderAction(scl);
- scl = (ClassLoader) AccessController.doPrivileged(a);
+ scl = AccessController.doPrivileged(
+ new SystemClassLoaderAction(scl));
} catch (PrivilegedActionException pae) {
oops = pae.getCause();
if (oops instanceof InvocationTargetException) {
@@ -1456,7 +1459,7 @@ public abstract class ClassLoader {
*/
protected Package getPackage(String name) {
synchronized (packages) {
- Package pkg = (Package)packages.get(name);
+ Package pkg = packages.get(name);
if (pkg == null) {
if (parent != null) {
pkg = parent.getPackage(name);
@@ -1481,9 +1484,9 @@ public abstract class ClassLoader {
* @since 1.2
*/
protected Package[] getPackages() {
- Map map;
+ Map map;
synchronized (packages) {
- map = (Map)packages.clone();
+ map = new HashMap(packages);
}
Package[] pkgs;
if (parent != null) {
@@ -1499,7 +1502,7 @@ public abstract class ClassLoader {
}
}
}
- return (Package[])map.values().toArray(new Package[map.size()]);
+ return map.values().toArray(new Package[map.size()]);
}
@@ -1585,8 +1588,7 @@ public abstract class ClassLoader {
// Invoked in the VM to determine the context class in
// JNI_Load/JNI_Unload
static Class getFromClass() {
- return ((NativeLibrary)
- (ClassLoader.nativeLibraryContext.peek())).fromClass;
+ return ClassLoader.nativeLibraryContext.peek().fromClass;
}
}
@@ -1597,22 +1599,27 @@ public abstract class ClassLoader {
// Returns (and initializes) the default domain.
private synchronized ProtectionDomain getDefaultDomain() {
if (defaultDomain == null) {
- CodeSource cs =
- new CodeSource(null, (java.security.cert.Certificate[]) null);
+ CodeSource cs = new CodeSource(null, (Certificate[]) null);
defaultDomain = new ProtectionDomain(cs, null, this, null);
}
return defaultDomain;
}
// All native library names we've loaded.
- private static Vector loadedLibraryNames = new Vector();
+ private static Vector loadedLibraryNames
+ = new Vector();
+
// Native libraries belonging to system classes.
- private static Vector systemNativeLibraries = new Vector();
+ private static Vector