diff --git a/make/docs/CORE_PKGS.gmk b/make/docs/CORE_PKGS.gmk index cdef9ebbc97ea9968218a776884b2d188739a244..2c2b1774f3269689655c87eae04a513c9364531a 100644 --- a/make/docs/CORE_PKGS.gmk +++ b/make/docs/CORE_PKGS.gmk @@ -131,6 +131,7 @@ CORE_PKGS = \ java.util.concurrent \ java.util.concurrent.atomic \ java.util.concurrent.locks \ + java.util.function \ java.util.jar \ java.util.logging \ java.util.prefs \ diff --git a/make/java/java/FILES_java.gmk b/make/java/java/FILES_java.gmk index c35bb29989c8d62cdcceeb972ed2696e3f00b4b9..33d35caeef5d7884b12059ec4f401c3338872702 100644 --- a/make/java/java/FILES_java.gmk +++ b/make/java/java/FILES_java.gmk @@ -147,6 +147,7 @@ JAVA_JAVA_java = \ java/lang/ref/PhantomReference.java \ java/lang/ref/ReferenceQueue.java \ java/lang/ref/Finalizer.java \ + java/util/Base64.java \ java/util/BitSet.java \ java/util/Calendar.java \ java/util/GregorianCalendar.java \ diff --git a/make/java/java/Makefile b/make/java/java/Makefile index b2d1c5ab09137b06e5f047b9db7b019ad84a2f37..54f4dbdebfabee931ac63a158adc03a5f9567e73 100644 --- a/make/java/java/Makefile +++ b/make/java/java/Makefile @@ -37,6 +37,8 @@ SUBDIRS_MAKEFLAGS += JAVAC_WARNINGS_FATAL=true JAVAC_MAX_WARNINGS=true include $(BUILDDIR)/common/Defs.gmk +AUTO_FILES_JAVA_DIRS = java/util/function + # windows compiler flags ifeq ($(PLATFORM),windows) OTHER_CFLAGS = diff --git a/src/share/classes/com/sun/jmx/snmp/EnumRowStatus.java b/src/share/classes/com/sun/jmx/snmp/EnumRowStatus.java index d92dd968f286307705064746e1ff4ee6be6b4b7b..74a05ae1b96f4ca22d05edadee2fd797b5b3e460 100644 --- a/src/share/classes/com/sun/jmx/snmp/EnumRowStatus.java +++ b/src/share/classes/com/sun/jmx/snmp/EnumRowStatus.java @@ -28,10 +28,6 @@ package com.sun.jmx.snmp; import java.io.Serializable; import java.util.Hashtable; -import com.sun.jmx.snmp.SnmpValue; -import com.sun.jmx.snmp.SnmpInt; - -import com.sun.jmx.snmp.Enumerated; /** * This class is an internal class which is used to represent RowStatus @@ -263,30 +259,30 @@ public class EnumRowStatus extends Enumerated implements Serializable { // Documented in Enumerated // - protected Hashtable getIntTable() { + @Override + protected Hashtable getIntTable() { return EnumRowStatus.getRSIntTable(); } // Documented in Enumerated // - protected Hashtable getStringTable() { + @Override + protected Hashtable getStringTable() { return EnumRowStatus.getRSStringTable(); } - static final Hashtable getRSIntTable() { + static Hashtable getRSIntTable() { return intTable ; } - static final Hashtable getRSStringTable() { + static Hashtable getRSStringTable() { return stringTable ; } // Initialize the mapping tables. // - final static Hashtable intTable = - new Hashtable(); - final static Hashtable stringTable = - new Hashtable(); + final static Hashtable intTable = new Hashtable<>(); + final static Hashtable stringTable = new Hashtable<>(); static { intTable.put(new Integer(0), "unspecified"); intTable.put(new Integer(3), "notReady"); diff --git a/src/share/classes/com/sun/jmx/snmp/Enumerated.java b/src/share/classes/com/sun/jmx/snmp/Enumerated.java index a4bca4e7053f02f5716923c21f8cd11ba8e68419..7cde19bc20bf424266bdf4e2345790f4c602f1ee 100644 --- a/src/share/classes/com/sun/jmx/snmp/Enumerated.java +++ b/src/share/classes/com/sun/jmx/snmp/Enumerated.java @@ -54,9 +54,9 @@ abstract public class Enumerated implements Serializable { * @exception IllegalArgumentException One of the arguments passed to the method is illegal or inappropriate. */ public Enumerated() throws IllegalArgumentException { - Enumeration e =getIntTable().keys() ; + Enumeration e =getIntTable().keys(); if (e.hasMoreElements()) { - value = ((Integer)e.nextElement()).intValue() ; + value = e.nextElement().intValue() ; } else { throw new IllegalArgumentException() ; @@ -100,7 +100,7 @@ abstract public class Enumerated implements Serializable { * to the method is illegal or inappropriate. */ public Enumerated(String valueString) throws IllegalArgumentException { - Integer index = (Integer)getStringTable().get(valueString) ; + Integer index = getStringTable().get(valueString) ; if (index == null) { throw new IllegalArgumentException() ; } @@ -127,7 +127,7 @@ abstract public class Enumerated implements Serializable { * @return An enumeration of Integer instances */ - public Enumeration valueIndexes() { + public Enumeration valueIndexes() { return getIntTable().keys() ; } @@ -138,7 +138,7 @@ abstract public class Enumerated implements Serializable { * @return An enumeration of String instances */ - public Enumeration valueStrings() { + public Enumeration valueStrings() { return getStringTable().keys() ; } @@ -153,6 +153,7 @@ abstract public class Enumerated implements Serializable { * * @return True if this and obj are the same; false otherwise */ + @Override public boolean equals(Object obj) { return ((obj != null) && @@ -166,6 +167,7 @@ abstract public class Enumerated implements Serializable { * * @return A hash code value for this object. */ + @Override public int hashCode() { String hashString = getClass().getName() + String.valueOf(value) ; return hashString.hashCode() ; @@ -177,9 +179,9 @@ abstract public class Enumerated implements Serializable { * * @return The string for for this object. */ - + @Override public String toString() { - return (String)getIntTable().get(new Integer(value)) ; + return getIntTable().get(new Integer(value)) ; } @@ -193,7 +195,7 @@ abstract public class Enumerated implements Serializable { * @return An hashtable for read-only purpose */ - protected abstract Hashtable getIntTable() ; + protected abstract Hashtable getIntTable() ; @@ -207,12 +209,12 @@ abstract public class Enumerated implements Serializable { * @return An hashtable for read-only purpose */ - protected abstract Hashtable getStringTable() ; + protected abstract Hashtable getStringTable() ; /** * This variable keeps the integer form of the enumerated. - * The string form is retreived using getIntTable(). + * The string form is retrieved using getIntTable(). */ protected int value ; diff --git a/src/share/classes/com/sun/jmx/snmp/IPAcl/AclImpl.java b/src/share/classes/com/sun/jmx/snmp/IPAcl/AclImpl.java index 353514c689e986701e6d3283b7c57d0e978484a0..b78c9ff7c037a529f124a83426ebbb0591b204eb 100644 --- a/src/share/classes/com/sun/jmx/snmp/IPAcl/AclImpl.java +++ b/src/share/classes/com/sun/jmx/snmp/IPAcl/AclImpl.java @@ -66,7 +66,7 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { */ public AclImpl (PrincipalImpl owner, String name) { super(owner); - entryList = new Vector(); + entryList = new Vector<>(); aclName = name; } @@ -81,6 +81,7 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { * of this ACL. * @see java.security.Principal */ + @Override public void setName(Principal caller, String name) throws NotOwnerException { if (!isOwner(caller)) @@ -93,6 +94,7 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { * * @return the name of this ACL. */ + @Override public String getName(){ return aclName; } @@ -113,6 +115,7 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { * this ACL. * @see java.security.Principal */ + @Override public boolean addEntry(Principal caller, AclEntry entry) throws NotOwnerException { if (!isOwner(caller)) @@ -144,6 +147,7 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { * @see java.security.Principal * @see java.security.acl.AclEntry */ + @Override public boolean removeEntry(Principal caller, AclEntry entry) throws NotOwnerException { if (!isOwner(caller)) @@ -185,8 +189,9 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { * is allowed. * @see java.security.Principal */ + @Override public Enumeration getPermissions(Principal user){ - Vector empty = new Vector(); + Vector empty = new Vector<>(); for (Enumeration e = entryList.elements();e.hasMoreElements();){ AclEntry ent = e.nextElement(); if (ent.getPrincipal().equals(user)) @@ -201,6 +206,7 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { * * @return an enumeration of the entries in this ACL. */ + @Override public Enumeration entries(){ return entryList.elements(); } @@ -221,10 +227,11 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { * @see java.security.Principal * @see java.security.Permission */ + @Override public boolean checkPermission(Principal user, java.security.acl.Permission perm) { - for (Enumeration e = entryList.elements();e.hasMoreElements();){ - AclEntry ent = (AclEntry) e.nextElement(); + for (Enumeration e = entryList.elements();e.hasMoreElements();){ + AclEntry ent = e.nextElement(); if (ent.getPrincipal().equals(user)) if (ent.checkPermission(perm)) return true; } @@ -250,7 +257,7 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { */ public boolean checkPermission(Principal user, String community, java.security.acl.Permission perm) { - for (Enumeration e = entryList.elements();e.hasMoreElements();){ + for (Enumeration e = entryList.elements();e.hasMoreElements();){ AclEntryImpl ent = (AclEntryImpl) e.nextElement(); if (ent.getPrincipal().equals(user)) if (ent.checkPermission(perm) && ent.checkCommunity(community)) return true; @@ -269,7 +276,7 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { * @see java.security.Permission */ public boolean checkCommunity(String community) { - for (Enumeration e = entryList.elements();e.hasMoreElements();){ + for (Enumeration e = entryList.elements();e.hasMoreElements();){ AclEntryImpl ent = (AclEntryImpl) e.nextElement(); if (ent.checkCommunity(community)) return true; } @@ -281,6 +288,7 @@ class AclImpl extends OwnerImpl implements Acl, Serializable { * * @return a string representation of the ACL contents. */ + @Override public String toString(){ return ("AclImpl: "+ getName()); } diff --git a/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMAclBlock.java b/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMAclBlock.java index a48039fabd4ae7b62989959050503bb1b1c09789..ca5720ef9a04d613dd84b6f33d08f66885c29a98 100644 --- a/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMAclBlock.java +++ b/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMAclBlock.java @@ -28,7 +28,9 @@ package com.sun.jmx.snmp.IPAcl; +import java.net.InetAddress; import java.util.Hashtable; +import java.util.Vector; class JDMAclBlock extends SimpleNode { JDMAclBlock(int id) { @@ -51,11 +53,13 @@ class JDMAclBlock extends SimpleNode { * Do no need to go through this part of the tree for * building TrapEntry. */ - public void buildTrapEntries(Hashtable dest) {} + @Override + public void buildTrapEntries(Hashtable> dest) {} /** * Do no need to go through this part of the tree for * building InformEntry. */ - public void buildInformEntries(Hashtable dest) {} + @Override + public void buildInformEntries(Hashtable> dest) {} } diff --git a/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMInformBlock.java b/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMInformBlock.java index 6f54a6178d946e5911fb005fda4b2b733850e31c..02a4550f1cec234876f928d2cdc17ecbb39a8c81 100644 --- a/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMInformBlock.java +++ b/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMInformBlock.java @@ -27,7 +27,9 @@ package com.sun.jmx.snmp.IPAcl; +import java.net.InetAddress; import java.util.Hashtable; +import java.util.Vector; class JDMInformBlock extends SimpleNode { JDMInformBlock(int id) { @@ -50,11 +52,13 @@ class JDMInformBlock extends SimpleNode { * Do no need to go through this part of the tree for * building AclEntry. */ + @Override public void buildAclEntries(PrincipalImpl owner, AclImpl acl) {} /** * Do no need to go through this part of the tree for * building TrapEntry. */ - public void buildTrapEntries(Hashtable dest) {} + @Override + public void buildTrapEntries(Hashtable> dest) {} } diff --git a/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMTrapBlock.java b/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMTrapBlock.java index d14d3d76fe7b0c3257e3ad51f136470554e00f1c..ab3c5295865a0d749b4c3cb1d88f6f88ea63ef04 100644 --- a/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMTrapBlock.java +++ b/src/share/classes/com/sun/jmx/snmp/IPAcl/JDMTrapBlock.java @@ -28,7 +28,9 @@ package com.sun.jmx.snmp.IPAcl; +import java.net.InetAddress; import java.util.Hashtable; +import java.util.Vector; class JDMTrapBlock extends SimpleNode { JDMTrapBlock(int id) { @@ -51,11 +53,13 @@ class JDMTrapBlock extends SimpleNode { * Do no need to go through this part of the tree for * building AclEntry. */ + @Override public void buildAclEntries(PrincipalImpl owner, AclImpl acl) {} /** * Do no need to go through this part of the tree for * building InformEntry. */ - public void buildInformEntries(Hashtable dest) {} + @Override + public void buildInformEntries(Hashtable> dest) {} } diff --git a/src/share/classes/com/sun/jmx/snmp/IPAcl/JJTParserState.java b/src/share/classes/com/sun/jmx/snmp/IPAcl/JJTParserState.java index 83adecd97554026c69e860b884f326328af40a01..f68c13cf2606910dc75950741e99a22cb6567674 100644 --- a/src/share/classes/com/sun/jmx/snmp/IPAcl/JJTParserState.java +++ b/src/share/classes/com/sun/jmx/snmp/IPAcl/JJTParserState.java @@ -27,18 +27,17 @@ package com.sun.jmx.snmp.IPAcl; -@SuppressWarnings("unchecked") // generated code, not worth fixing class JJTParserState { - private java.util.Stack nodes; - private java.util.Stack marks; + private java.util.Stack nodes; + private java.util.Stack marks; private int sp; // number of nodes on stack private int mk; // current mark private boolean node_created; JJTParserState() { - nodes = new java.util.Stack(); - marks = new java.util.Stack(); + nodes = new java.util.Stack<>(); + marks = new java.util.Stack<>(); sp = 0; mk = 0; } @@ -62,7 +61,7 @@ class JJTParserState { /* Returns the root node of the AST. It only makes sense to call this after a successful parse. */ Node rootNode() { - return (Node)nodes.elementAt(0); + return nodes.elementAt(0); } /* Pushes a node on to the stack. */ @@ -75,14 +74,14 @@ class JJTParserState { stack. */ Node popNode() { if (--sp < mk) { - mk = ((Integer)marks.pop()).intValue(); + mk = marks.pop().intValue(); } - return (Node)nodes.pop(); + return nodes.pop(); } /* Returns the node currently on the top of the stack. */ Node peekNode() { - return (Node)nodes.peek(); + return nodes.peek(); } /* Returns the number of children on the stack in the current node @@ -96,7 +95,7 @@ class JJTParserState { while (sp > mk) { popNode(); } - mk = ((Integer)marks.pop()).intValue(); + mk = marks.pop().intValue(); } @@ -112,7 +111,7 @@ class JJTParserState { made the children of the definite node. Then the definite node is pushed on to the stack. */ void closeNodeScope(Node n, int num) { - mk = ((Integer)marks.pop()).intValue(); + mk = marks.pop().intValue(); while (num-- > 0) { Node c = popNode(); c.jjtSetParent(n); @@ -132,7 +131,7 @@ class JJTParserState { void closeNodeScope(Node n, boolean condition) { if (condition) { int a = nodeArity(); - mk = ((Integer)marks.pop()).intValue(); + mk = marks.pop().intValue(); while (a-- > 0) { Node c = popNode(); c.jjtSetParent(n); @@ -142,7 +141,7 @@ class JJTParserState { pushNode(n); node_created = true; } else { - mk = ((Integer)marks.pop()).intValue(); + mk = marks.pop().intValue(); node_created = false; } } diff --git a/src/share/classes/com/sun/jmx/snmp/IPAcl/Parser.java b/src/share/classes/com/sun/jmx/snmp/IPAcl/Parser.java index b2fe5f5d15786830d009d17d50575e4bfa11496b..f6ba9e029e109a3d60b70ec34d4b0504ca1f5f2d 100644 --- a/src/share/classes/com/sun/jmx/snmp/IPAcl/Parser.java +++ b/src/share/classes/com/sun/jmx/snmp/IPAcl/Parser.java @@ -1168,7 +1168,7 @@ jjtree.openNodeScope(jjtn000);Token t; return (jj_ntk = jj_nt.kind); } - private java.util.Vector jj_expentries = new java.util.Vector(); + private java.util.Vector jj_expentries = new java.util.Vector<>(); private int[] jj_expentry; private int jj_kind = -1; private int[] jj_lasttokens = new int[100]; @@ -1184,8 +1184,8 @@ jjtree.openNodeScope(jjtn000);Token t; jj_expentry[i] = jj_lasttokens[i]; } boolean exists = false; - for (java.util.Enumeration enumv = jj_expentries.elements(); enumv.hasMoreElements();) { - int[] oldentry = (int[])(enumv.nextElement()); + for (java.util.Enumeration enumv = jj_expentries.elements(); enumv.hasMoreElements();) { + int[] oldentry = enumv.nextElement(); if (oldentry.length == jj_expentry.length) { exists = true; for (int i = 0; i < jj_expentry.length; i++) { @@ -1236,7 +1236,7 @@ jjtree.openNodeScope(jjtn000);Token t; jj_add_error_token(0, 0); int[][] exptokseq = new int[jj_expentries.size()][]; for (int i = 0; i < jj_expentries.size(); i++) { - exptokseq[i] = (int[])jj_expentries.elementAt(i); + exptokseq[i] = jj_expentries.elementAt(i); } return new ParseException(token, exptokseq, tokenImage); } diff --git a/src/share/classes/com/sun/jmx/snmp/IPAcl/SnmpAcl.java b/src/share/classes/com/sun/jmx/snmp/IPAcl/SnmpAcl.java index 59f399693386dea9ba61147f69fbe0fb2230e288..ae5b7cf938618dede2d2a8912057b0067341e222 100644 --- a/src/share/classes/com/sun/jmx/snmp/IPAcl/SnmpAcl.java +++ b/src/share/classes/com/sun/jmx/snmp/IPAcl/SnmpAcl.java @@ -126,7 +126,7 @@ public class SnmpAcl implements InetAddressAcl, Serializable { * * @return An enumeration of the entries in this ACL. */ - public Enumeration entries() { + public Enumeration entries() { return acl.entries(); } @@ -137,11 +137,11 @@ public class SnmpAcl implements InetAddressAcl, Serializable { public Enumeration communities() { HashSet set = new HashSet(); Vector res = new Vector(); - for (Enumeration e = acl.entries() ; e.hasMoreElements() ;) { + for (Enumeration e = acl.entries() ; e.hasMoreElements() ;) { AclEntryImpl entry = (AclEntryImpl) e.nextElement(); - for (Enumeration cs = entry.communities(); + for (Enumeration cs = entry.communities(); cs.hasMoreElements() ;) { - set.add((String) cs.nextElement()); + set.add(cs.nextElement()); } } String[] objs = set.toArray(new String[0]); @@ -316,7 +316,7 @@ public class SnmpAcl implements InetAddressAcl, Serializable { * * @return An enumeration of the trap destinations (enumeration of InetAddress). */ - public Enumeration getTrapDestinations() { + public Enumeration getTrapDestinations() { return trapDestList.keys(); } @@ -327,16 +327,16 @@ public class SnmpAcl implements InetAddressAcl, Serializable { * * @return An enumeration of trap communities for a given host (enumeration of String). */ - public Enumeration getTrapCommunities(InetAddress i) { - Vector list = null; - if ((list = (Vector)trapDestList.get(i)) != null ) { + public Enumeration getTrapCommunities(InetAddress i) { + Vector list = null; + if ((list = trapDestList.get(i)) != null ) { if (SNMP_LOGGER.isLoggable(Level.FINER)) { SNMP_LOGGER.logp(Level.FINER, SnmpAcl.class.getName(), "getTrapCommunities", "["+i.toString()+"] is in list"); } return list.elements(); } else { - list = new Vector(); + list = new Vector<>(); if (SNMP_LOGGER.isLoggable(Level.FINER)) { SNMP_LOGGER.logp(Level.FINER, SnmpAcl.class.getName(), "getTrapCommunities", "["+i.toString()+"] is not in list"); @@ -350,7 +350,7 @@ public class SnmpAcl implements InetAddressAcl, Serializable { * * @return An enumeration of the inform destinations (enumeration of InetAddress). */ - public Enumeration getInformDestinations() { + public Enumeration getInformDestinations() { return informDestList.keys(); } @@ -361,16 +361,16 @@ public class SnmpAcl implements InetAddressAcl, Serializable { * * @return An enumeration of inform communities for a given host (enumeration of String). */ - public Enumeration getInformCommunities(InetAddress i) { - Vector list = null; - if ((list = (Vector)informDestList.get(i)) != null ) { + public Enumeration getInformCommunities(InetAddress i) { + Vector list = null; + if ((list = informDestList.get(i)) != null ) { if (SNMP_LOGGER.isLoggable(Level.FINER)) { SNMP_LOGGER.logp(Level.FINER, SnmpAcl.class.getName(), "getInformCommunities", "["+i.toString()+"] is in list"); } return list.elements(); } else { - list = new Vector(); + list = new Vector<>(); if (SNMP_LOGGER.isLoggable(Level.FINER)) { SNMP_LOGGER.logp(Level.FINER, SnmpAcl.class.getName(), "getInformCommunities", "["+i.toString()+"] is not in list"); @@ -426,15 +426,15 @@ public class SnmpAcl implements InetAddressAcl, Serializable { throw new IllegalArgumentException(err.getMessage()); } - for(Enumeration e = acl.entries(); e.hasMoreElements();) { + for(Enumeration e = acl.entries(); e.hasMoreElements();) { AclEntryImpl aa = (AclEntryImpl) e.nextElement(); if (SNMP_LOGGER.isLoggable(Level.FINER)) { SNMP_LOGGER.logp(Level.FINER, SnmpAcl.class.getName(), "readAuthorizedListFile", "===> " + aa.getPrincipal().toString()); } - for (Enumeration eee = aa.permissions();eee.hasMoreElements();) { - java.security.acl.Permission perm = (java.security.acl.Permission)eee.nextElement(); + for (Enumeration eee = aa.permissions();eee.hasMoreElements();) { + java.security.acl.Permission perm = eee.nextElement(); if (SNMP_LOGGER.isLoggable(Level.FINER)) { SNMP_LOGGER.logp(Level.FINER, SnmpAcl.class.getName(), "readAuthorizedListFile", "perm = " + perm); diff --git a/src/share/classes/com/sun/jmx/snmp/InetAddressAcl.java b/src/share/classes/com/sun/jmx/snmp/InetAddressAcl.java index 99800e1ba892a76de542e2d4c7ba396f34280493..690b933829ade5f38aef0993a4d51d2807b33639 100644 --- a/src/share/classes/com/sun/jmx/snmp/InetAddressAcl.java +++ b/src/share/classes/com/sun/jmx/snmp/InetAddressAcl.java @@ -99,7 +99,7 @@ public interface InetAddressAcl { * * @return An enumeration of the trap destinations (enumeration of InetAddress). */ - public Enumeration getTrapDestinations(); + public Enumeration getTrapDestinations(); /** * Returns an enumeration of trap communities for a given host. @@ -108,14 +108,14 @@ public interface InetAddressAcl { * * @return An enumeration of trap communities for a given host (enumeration of String). */ - public Enumeration getTrapCommunities(InetAddress address); + public Enumeration getTrapCommunities(InetAddress address); /** * Returns an enumeration of inform destinations. * * @return An enumeration of the inform destinations (enumeration of InetAddress). */ - public Enumeration getInformDestinations(); + public Enumeration getInformDestinations(); /** * Returns an enumeration of inform communities for a given host. @@ -124,5 +124,5 @@ public interface InetAddressAcl { * * @return An enumeration of inform communities for a given host (enumeration of String). */ - public Enumeration getInformCommunities(InetAddress address); + public Enumeration getInformCommunities(InetAddress address); } diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpErrorHandlerAgent.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpErrorHandlerAgent.java index 35c2fb8d986694664834fbbf7a330ed651c46bdf..ffa64b2f5249520825aeec62eea782ea0aeb7896 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpErrorHandlerAgent.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpErrorHandlerAgent.java @@ -59,6 +59,7 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent * @exception IllegalAccessException The MIB cannot be initialized. */ + @Override public void init() throws IllegalAccessException { } @@ -74,6 +75,7 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent * @exception java.lang.Exception */ + @Override public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { return name; @@ -87,6 +89,7 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent * @return The returned oid is null. */ + @Override public long[] getRootOid() { return null; } @@ -99,6 +102,7 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent * @exception SnmpStatusException An error occured during the operation. */ + @Override public void get(SnmpMibRequest inRequest) throws SnmpStatusException { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, @@ -108,9 +112,9 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) throw new SnmpStatusException(SnmpStatusException.noSuchName); - Enumeration l = inRequest.getElements(); + Enumeration l = inRequest.getElements(); while(l.hasMoreElements()) { - SnmpVarBind varbind = (SnmpVarBind) l.nextElement(); + SnmpVarBind varbind = l.nextElement(); varbind.setNoSuchObject(); } } @@ -128,6 +132,7 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent * cannot be performed. */ + @Override public void check(SnmpMibRequest inRequest) throws SnmpStatusException { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, @@ -145,6 +150,7 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent * @exception SnmpStatusException An error occured during the operation. */ + @Override public void set(SnmpMibRequest inRequest) throws SnmpStatusException { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, @@ -162,6 +168,7 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent * @exception SnmpStatusException An error occured during the operation. */ + @Override public void getNext(SnmpMibRequest inRequest) throws SnmpStatusException { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, @@ -171,9 +178,9 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) throw new SnmpStatusException(SnmpStatusException.noSuchName); - Enumeration l = inRequest.getElements(); + Enumeration l = inRequest.getElements(); while(l.hasMoreElements()) { - SnmpVarBind varbind = (SnmpVarBind) l.nextElement(); + SnmpVarBind varbind = l.nextElement(); varbind.setEndOfMibView(); } } @@ -186,6 +193,7 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent * @exception SnmpStatusException An error occured during the operation. */ + @Override public void getBulk(SnmpMibRequest inRequest, int nonRepeat, int maxRepeat) throws SnmpStatusException { @@ -196,9 +204,9 @@ public class SnmpErrorHandlerAgent extends SnmpMibAgent if(inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) throw new SnmpStatusException(SnmpDefinitions.snmpRspGenErr, 0); - Enumeration l = inRequest.getElements(); + Enumeration l = inRequest.getElements(); while(l.hasMoreElements()) { - SnmpVarBind varbind = (SnmpVarBind) l.nextElement(); + SnmpVarBind varbind = l.nextElement(); varbind.setEndOfMibView(); } } diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpGenericObjectServer.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpGenericObjectServer.java index 547c8ca21bcf598e29fdec995ed6ab0338ea38d7..689e08505a221dc1e598d27df4c1b803198cd697 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpGenericObjectServer.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpGenericObjectServer.java @@ -28,7 +28,6 @@ package com.sun.jmx.snmp.agent; // java imports // -import java.util.Vector; import java.util.Enumeration; import java.util.Iterator; @@ -149,8 +148,8 @@ public class SnmpGenericObjectServer { final long[] idList = new long[size]; int i = 0; - for (Enumeration e=req.getElements(); e.hasMoreElements();) { - final SnmpVarBind var= (SnmpVarBind) e.nextElement(); + for (Enumeration e=req.getElements(); e.hasMoreElements();) { + final SnmpVarBind var= e.nextElement(); try { final long id = var.oid.getOidArc(depth); nameList[i] = meta.getAttributeName(id); @@ -190,7 +189,7 @@ public class SnmpGenericObjectServer { } - final Iterator it = result.iterator(); + final Iterator it = result.iterator(); for (int j=0; j < i; j++) { if (!it.hasNext()) { @@ -312,8 +311,8 @@ public class SnmpGenericObjectServer { final long[] idList = new long[size]; int i = 0; - for (Enumeration e=req.getElements(); e.hasMoreElements();) { - final SnmpVarBind var= (SnmpVarBind) e.nextElement(); + for (Enumeration e=req.getElements(); e.hasMoreElements();) { + final SnmpVarBind var= e.nextElement(); try { final long id = var.oid.getOidArc(depth); final String attname = meta.getAttributeName(id); @@ -330,7 +329,7 @@ public class SnmpGenericObjectServer { } } - AttributeList result = null; + AttributeList result; int errorCode = SnmpStatusException.noAccess; try { @@ -345,7 +344,7 @@ public class SnmpGenericObjectServer { result = new AttributeList(); } - final Iterator it = result.iterator(); + final Iterator it = result.iterator(); for (int j=0; j < i; j++) { if (!it.hasNext()) { @@ -469,8 +468,8 @@ public class SnmpGenericObjectServer { final Object data = req.getUserData(); - for (Enumeration e=req.getElements(); e.hasMoreElements();) { - final SnmpVarBind var= (SnmpVarBind) e.nextElement(); + for (Enumeration e=req.getElements(); e.hasMoreElements();) { + final SnmpVarBind var= e.nextElement(); try { final long id = var.oid.getOidArc(depth); // call meta.check() here, and meta.check will call check() diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpIndex.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpIndex.java index d41e2e358651a7dfee966491e11b76bd8ed5681d..483a79618a8056063b9c3fd75b3ff4e4047ba20f 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpIndex.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpIndex.java @@ -164,11 +164,12 @@ public class SnmpIndex implements Serializable { * * @return A string representation of the index. */ + @Override public String toString() { - StringBuffer msg= new StringBuffer(); - for(Enumeration e= oids.elements(); e.hasMoreElements(); ) { - SnmpOid val= (SnmpOid) e.nextElement(); - msg.append( "//" + val.toString()); + final StringBuilder msg= new StringBuilder(); + for(Enumeration e= oids.elements(); e.hasMoreElements(); ) { + SnmpOid val= e.nextElement(); + msg.append("//").append( val.toString()); } return msg.toString(); } @@ -180,7 +181,7 @@ public class SnmpIndex implements Serializable { * The list of OIDs. * @serial */ - private Vector oids = new Vector(); + private Vector oids = new Vector<>(); /** * The number of elements in the index. diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMib.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMib.java index 13ae08c9cbe27dcbd7fa93abc982375208390253..df7587404ef283564e2730fe3865a3d0120911e1 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMib.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMib.java @@ -42,10 +42,6 @@ import com.sun.jmx.snmp.SnmpOid; import com.sun.jmx.snmp.SnmpVarBind; import com.sun.jmx.snmp.SnmpDefinitions; import com.sun.jmx.snmp.SnmpStatusException; -import com.sun.jmx.snmp.SnmpEngine; -import com.sun.jmx.snmp.SnmpUnknownModelException; -import com.sun.jmx.snmp.internal.SnmpAccessControlModel; -import com.sun.jmx.snmp.internal.SnmpEngineImpl; /** * Abstract class for representing an SNMP MIB. @@ -241,6 +237,7 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // Implements the method defined in SnmpMibAgent. See SnmpMibAgent // for java-doc // + @Override public void get(SnmpMibRequest req) throws SnmpStatusException { // Builds the request tree: creation is not allowed, operation @@ -259,8 +256,8 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // For each sub-request stored in the request-tree, invoke the // get() method. - for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) { - h = (SnmpRequestTree.Handler) eh.nextElement(); + for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) { + h = eh.nextElement(); // Gets the Meta node. It can be either a Group Meta or a // Table Meta. @@ -270,11 +267,11 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // Gets the depth of the Meta node in the OID tree final int depth = handlers.getOidDepth(h); - for (Enumeration rqs=handlers.getSubRequests(h); + for (Enumeration rqs=handlers.getSubRequests(h); rqs.hasMoreElements();) { // Invoke the get() operation. - meta.get((SnmpMibSubRequest)rqs.nextElement(),depth); + meta.get(rqs.nextElement(),depth); } } } @@ -286,6 +283,7 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // Implements the method defined in SnmpMibAgent. See SnmpMibAgent // for java-doc // + @Override public void set(SnmpMibRequest req) throws SnmpStatusException { SnmpRequestTree handlers = null; @@ -307,8 +305,8 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { handlers.switchCreationFlag(false); handlers.setPduType(reqType); - SnmpRequestTree.Handler h = null; - SnmpMibNode meta = null; + SnmpRequestTree.Handler h; + SnmpMibNode meta; if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), @@ -317,8 +315,8 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // For each sub-request stored in the request-tree, invoke the // get() method. - for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) { - h = (SnmpRequestTree.Handler) eh.nextElement(); + for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) { + h = eh.nextElement(); // Gets the Meta node. It can be either a Group Meta or a // Table Meta. @@ -328,11 +326,11 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // Gets the depth of the Meta node in the OID tree final int depth = handlers.getOidDepth(h); - for (Enumeration rqs=handlers.getSubRequests(h); + for (Enumeration rqs=handlers.getSubRequests(h); rqs.hasMoreElements();) { // Invoke the set() operation - meta.set((SnmpMibSubRequest)rqs.nextElement(),depth); + meta.set(rqs.nextElement(),depth); } } } @@ -346,6 +344,7 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // Implements the method defined in SnmpMibAgent. See SnmpMibAgent // for java-doc // + @Override public void check(SnmpMibRequest req) throws SnmpStatusException { final int reqType = SnmpDefinitions.pduWalkRequest; @@ -353,8 +352,8 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // is atomic. SnmpRequestTree handlers = getHandlers(req,true,true,reqType); - SnmpRequestTree.Handler h = null; - SnmpMibNode meta = null; + SnmpRequestTree.Handler h; + SnmpMibNode meta; if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), @@ -363,8 +362,8 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // For each sub-request stored in the request-tree, invoke the // check() method. - for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) { - h = (SnmpRequestTree.Handler) eh.nextElement(); + for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) { + h = eh.nextElement(); // Gets the Meta node. It can be either a Group Meta or a // Table Meta. @@ -374,11 +373,11 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // Gets the depth of the Meta node in the OID tree final int depth = handlers.getOidDepth(h); - for (Enumeration rqs=handlers.getSubRequests(h); + for (Enumeration rqs=handlers.getSubRequests(h); rqs.hasMoreElements();) { // Invoke the check() operation - meta.check((SnmpMibSubRequest)rqs.nextElement(),depth); + meta.check(rqs.nextElement(),depth); } } @@ -398,13 +397,14 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // Implements the method defined in SnmpMibAgent. See SnmpMibAgent // for java-doc // + @Override public void getNext(SnmpMibRequest req) throws SnmpStatusException { // Build the request tree for the operation // The subrequest stored in the request tree are valid GET requests SnmpRequestTree handlers = getGetNextHandlers(req); - SnmpRequestTree.Handler h = null; - SnmpMibNode meta = null; + SnmpRequestTree.Handler h; + SnmpMibNode meta; if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), @@ -412,8 +412,8 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { } // Now invoke get() for each subrequest of the request tree. - for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) { - h = (SnmpRequestTree.Handler) eh.nextElement(); + for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) { + h = eh.nextElement(); // Gets the Meta node. It can be either a Group Meta or a // Table Meta. @@ -423,11 +423,11 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // Gets the depth of the Meta node in the OID tree int depth = handlers.getOidDepth(h); - for (Enumeration rqs=handlers.getSubRequests(h); + for (Enumeration rqs=handlers.getSubRequests(h); rqs.hasMoreElements();) { // Invoke the get() operation - meta.get((SnmpMibSubRequest)rqs.nextElement(),depth); + meta.get(rqs.nextElement(),depth); } } } @@ -442,6 +442,7 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // Implements the method defined in SnmpMibAgent. See SnmpMibAgent // for java-doc // + @Override public void getBulk(SnmpMibRequest req, int nonRepeat, int maxRepeat) throws SnmpStatusException { @@ -456,10 +457,11 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { * * @return The root object identifier. */ + @Override public long[] getRootOid() { if( rootOid == null) { - Vector list= new Vector(10); + Vector list= new Vector<>(10); // Ask the tree to do the job ! // @@ -507,13 +509,13 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { new SnmpRequestTree(req,createflag,type); int index=0; - SnmpVarBind var = null; + SnmpVarBind var; final int ver= req.getVersion(); // For each varbind in the list finds its handling node. - for (Enumeration e= req.getElements(); e.hasMoreElements(); index++) { + for (Enumeration e= req.getElements(); e.hasMoreElements(); index++) { - var= (SnmpVarBind) e.nextElement(); + var= e.nextElement(); try { // Find the handling node for this varbind. @@ -657,10 +659,10 @@ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { // request into a valid GET request, replacing the OIDs in the // original GET-NEXT request with the OID of the first leaf that // follows. - for (Enumeration e= req.getElements(); e.hasMoreElements(); index++) { + for (Enumeration e= req.getElements(); e.hasMoreElements(); index++) { - var = (SnmpVarBind) e.nextElement(); - SnmpOid result = null; + var = e.nextElement(); + SnmpOid result; try { // Find the node handling the OID that follows the varbind // OID. `result' contains this next leaf OID. diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibAgent.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibAgent.java index e0ba715d6e98362d697a49d5ac43d094e36322b9..451fa859df4a954a4aa7f8027d7b53a465ae55d1 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibAgent.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibAgent.java @@ -33,14 +33,12 @@ package com.sun.jmx.snmp.agent; import java.io.Serializable; import java.util.Vector; import java.util.Enumeration; -import java.util.Set; // jmx imports // import javax.management.MBeanServer; import javax.management.MBeanRegistration; import javax.management.ObjectName; -import javax.management.MalformedObjectNameException; import javax.management.InstanceNotFoundException; import javax.management.ServiceNotFoundException; import javax.management.ReflectionException; @@ -94,6 +92,7 @@ public abstract class SnmpMibAgent * * @exception java.lang.Exception */ + @Override public abstract ObjectName preRegister(MBeanServer server, ObjectName name) throws java.lang.Exception; @@ -101,18 +100,21 @@ public abstract class SnmpMibAgent /** * Not used in this context. */ + @Override public void postRegister (Boolean registrationDone) { } /** * Not used in this context. */ + @Override public void preDeregister() throws java.lang.Exception { } /** * Not used in this context. */ + @Override public void postDeregister() { } @@ -127,6 +129,7 @@ public abstract class SnmpMibAgent * * @exception SnmpStatusException An error occured during the operation. */ + @Override public abstract void get(SnmpMibRequest req) throws SnmpStatusException; @@ -141,6 +144,7 @@ public abstract class SnmpMibAgent * * @exception SnmpStatusException An error occured during the operation. */ + @Override public abstract void getNext(SnmpMibRequest req) throws SnmpStatusException; @@ -164,6 +168,7 @@ public abstract class SnmpMibAgent * * @exception SnmpStatusException An error occured during the operation. */ + @Override public abstract void getBulk(SnmpMibRequest req, int nonRepeat, int maxRepeat) throws SnmpStatusException; @@ -185,6 +190,7 @@ public abstract class SnmpMibAgent * the exception is thrown in the {@link #check(SnmpMibRequest)} * method instead. */ + @Override public abstract void set(SnmpMibRequest req) throws SnmpStatusException; @@ -203,6 +209,7 @@ public abstract class SnmpMibAgent * @exception SnmpStatusException The set operation * cannot be performed. */ + @Override public abstract void check(SnmpMibRequest req) throws SnmpStatusException; @@ -226,6 +233,7 @@ public abstract class SnmpMibAgent * @return The MBean server or null if the MIB is not registered in any * MBean server. */ + @Override public MBeanServer getMBeanServer() { return server; } @@ -236,6 +244,7 @@ public abstract class SnmpMibAgent * * @return The SNMP MIB handler. */ + @Override public SnmpMibHandler getSnmpAdaptor() { return adaptor; } @@ -246,6 +255,7 @@ public abstract class SnmpMibAgent * * @param stack The SNMP MIB handler. */ + @Override public void setSnmpAdaptor(SnmpMibHandler stack) { if (adaptor != null) { adaptor.removeMib(this); @@ -266,6 +276,7 @@ public abstract class SnmpMibAgent * * @since 1.5 */ + @Override public void setSnmpAdaptor(SnmpMibHandler stack, SnmpOid[] oids) { if (adaptor != null) { adaptor.removeMib(this); @@ -288,6 +299,7 @@ public abstract class SnmpMibAgent * * @since 1.5 */ + @Override public void setSnmpAdaptor(SnmpMibHandler stack, String contextName) { if (adaptor != null) { adaptor.removeMib(this, contextName); @@ -309,6 +321,7 @@ public abstract class SnmpMibAgent * * @since 1.5 */ + @Override public void setSnmpAdaptor(SnmpMibHandler stack, String contextName, SnmpOid[] oids) { @@ -327,6 +340,7 @@ public abstract class SnmpMibAgent * * @return The name of the SNMP protocol adaptor. */ + @Override public ObjectName getSnmpAdaptorName() { return adaptorName; } @@ -344,6 +358,7 @@ public abstract class SnmpMibAgent * @exception ServiceNotFoundException This SNMP MIB is not registered * in the MBean server or the requested service is not supported. */ + @Override public void setSnmpAdaptorName(ObjectName name) throws InstanceNotFoundException, ServiceNotFoundException { @@ -389,6 +404,7 @@ public abstract class SnmpMibAgent * * @since 1.5 */ + @Override public void setSnmpAdaptorName(ObjectName name, SnmpOid[] oids) throws InstanceNotFoundException, ServiceNotFoundException { @@ -434,6 +450,7 @@ public abstract class SnmpMibAgent * * @since 1.5 */ + @Override public void setSnmpAdaptorName(ObjectName name, String contextName) throws InstanceNotFoundException, ServiceNotFoundException { @@ -481,6 +498,7 @@ public abstract class SnmpMibAgent * * @since 1.5 */ + @Override public void setSnmpAdaptorName(ObjectName name, String contextName, SnmpOid[] oids) throws InstanceNotFoundException, ServiceNotFoundException { @@ -522,6 +540,7 @@ public abstract class SnmpMibAgent * @return true if the MIB module is bound, * false otherwise. */ + @Override public boolean getBindingState() { if (adaptor == null) return false; @@ -534,6 +553,7 @@ public abstract class SnmpMibAgent * * @return The MIB name. */ + @Override public String getMibName() { return mibName; } @@ -681,7 +701,7 @@ public abstract class SnmpMibAgent private Vector splitFrom(Vector original, int limit) { int max= original.size(); - Vector result= new Vector(max - limit); + Vector result= new Vector<>(max - limit); int i= limit; // Ok the loop looks a bit strange. But in order to improve the @@ -697,21 +717,12 @@ public abstract class SnmpMibAgent return result; } - private void concatVector(SnmpMibRequest req, Vector source) { - for(Enumeration e= source.elements(); e.hasMoreElements(); ) { - SnmpVarBind var= (SnmpVarBind) e.nextElement(); - // We need to duplicate the SnmpVarBind otherwise it is going - // to be overloaded by the next get Next ... - req.addVarBind(new SnmpVarBind(var.oid, var.value)); - } - } - - private void concatVector(Vector target, Vector source) { + private void concatVector(SnmpMibRequest req, Vector source) { for(Enumeration e= source.elements(); e.hasMoreElements(); ) { SnmpVarBind var= e.nextElement(); // We need to duplicate the SnmpVarBind otherwise it is going // to be overloaded by the next get Next ... - target.addElement(new SnmpVarBind(var.oid, var.value)); + req.addVarBind(new SnmpVarBind(var.oid, var.value)); } } diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java index b34e0009481502750ee7ed43a296e50445a68fa8..29882ce01d4ff7c3a4e8b2c0e74ae0ef82dd8ee4 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java @@ -29,20 +29,13 @@ package com.sun.jmx.snmp.agent; // import java.io.Serializable; import java.util.Hashtable; -import java.util.Enumeration; import java.util.Vector; // jmx imports // -import com.sun.jmx.snmp.SnmpOid; -import com.sun.jmx.snmp.SnmpValue; import com.sun.jmx.snmp.SnmpVarBind; import com.sun.jmx.snmp.SnmpStatusException; -// SNMP Runtime imports -// -import com.sun.jmx.snmp.agent.SnmpMibOid; -import com.sun.jmx.snmp.agent.SnmpMibNode; /** * Represents a node in an SNMP MIB which corresponds to a group. @@ -174,6 +167,7 @@ public abstract class SnmpMibGroup extends SnmpMibOid * @exception SnmpStatusException An error occurred while accessing * the MIB node. */ + @Override abstract public void get(SnmpMibSubRequest req, int depth) throws SnmpStatusException; @@ -203,6 +197,7 @@ public abstract class SnmpMibGroup extends SnmpMibOid * @exception SnmpStatusException An error occurred while accessing * the MIB node. */ + @Override abstract public void set(SnmpMibSubRequest req, int depth) throws SnmpStatusException; @@ -234,6 +229,7 @@ public abstract class SnmpMibGroup extends SnmpMibOid * @exception SnmpStatusException An error occurred while accessing * the MIB node. */ + @Override abstract public void check(SnmpMibSubRequest req, int depth) throws SnmpStatusException; @@ -241,8 +237,8 @@ public abstract class SnmpMibGroup extends SnmpMibOid // If we reach this node, we are below the root OID, so we just // return. // -------------------------------------------------------------------- - public void getRootOid(Vector result) { - return; + @Override + public void getRootOid(Vector result) { } // ------------------------------------------------------------------- @@ -264,7 +260,7 @@ public abstract class SnmpMibGroup extends SnmpMibOid */ void registerNestedArc(long arc) { Long obj = new Long(arc); - if (subgroups == null) subgroups = new Hashtable(); + if (subgroups == null) subgroups = new Hashtable<>(); // registers the arc in the hashtable. subgroups.put(obj,obj); } @@ -312,6 +308,7 @@ public abstract class SnmpMibGroup extends SnmpMibOid * @param node The node being registered. * */ + @Override void registerNode(long[] oid, int cursor ,SnmpMibNode node) throws IllegalAccessException { super.registerNode(oid,cursor,node); @@ -325,13 +322,13 @@ public abstract class SnmpMibGroup extends SnmpMibOid // ------------------------------------------------------------------- // see comments in SnmpMibNode // ------------------------------------------------------------------- + @Override void findHandlingNode(SnmpVarBind varbind, long[] oid, int depth, SnmpRequestTree handlers) throws SnmpStatusException { int length = oid.length; - SnmpMibNode node = null; if (handlers == null) throw new SnmpStatusException(SnmpStatusException.snmpRspGenErr); @@ -349,7 +346,6 @@ public abstract class SnmpMibGroup extends SnmpMibOid // This arc leads to a subgroup: delegates the search to the // method defined in SnmpMibOid super.findHandlingNode(varbind,oid,depth,handlers); - return; } else if (isTable(arc)) { // This arc leads to a table: forward the search to the table. @@ -384,6 +380,7 @@ public abstract class SnmpMibGroup extends SnmpMibOid // ------------------------------------------------------------------- // See comments in SnmpMibNode. // ------------------------------------------------------------------- + @Override long[] findNextHandlingNode(SnmpVarBind varbind, long[] oid, int pos, int depth, SnmpRequestTree handlers, AcmChecker checker) diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibOid.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibOid.java index a9411b9d17610baf406fdf097035ff641a759e66..f3965bce637e627d2215f024f48771dcffd1af38 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibOid.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibOid.java @@ -37,7 +37,6 @@ import java.util.Enumeration; // jmx imports // import com.sun.jmx.snmp.SnmpOid; -import com.sun.jmx.snmp.SnmpValue; import com.sun.jmx.snmp.SnmpVarBind; import com.sun.jmx.snmp.SnmpStatusException; @@ -79,10 +78,11 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { * @exception SnmpStatusException The default implementation (if not * overridden) is to generate a SnmpStatusException. */ + @Override public void get(SnmpMibSubRequest req, int depth) throws SnmpStatusException { - for (Enumeration e= req.getElements(); e.hasMoreElements();) { - SnmpVarBind var= (SnmpVarBind) e.nextElement(); + for (Enumeration e= req.getElements(); e.hasMoreElements();) { + SnmpVarBind var= e.nextElement(); SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noSuchObject); req.registerGetException(var,x); @@ -102,10 +102,11 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { * @exception SnmpStatusException The default implementation (if not * overridden) is to generate a SnmpStatusException. */ + @Override public void set(SnmpMibSubRequest req, int depth) throws SnmpStatusException { - for (Enumeration e= req.getElements(); e.hasMoreElements();) { - SnmpVarBind var= (SnmpVarBind) e.nextElement(); + for (Enumeration e= req.getElements(); e.hasMoreElements();) { + SnmpVarBind var= e.nextElement(); SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noAccess); req.registerSetException(var,x); @@ -123,12 +124,13 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { * @param depth The depth reached in the OID tree. * * @exception SnmpStatusException The default implementation (if not - * overriden) is to generate a SnmpStatusException. + * overridden) is to generate a SnmpStatusException. */ + @Override public void check(SnmpMibSubRequest req, int depth) throws SnmpStatusException { - for (Enumeration e= req.getElements(); e.hasMoreElements();) { - SnmpVarBind var= (SnmpVarBind) e.nextElement(); + for (Enumeration e= req.getElements(); e.hasMoreElements();) { + SnmpVarBind var= e.nextElement(); SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noAccess); req.registerCheckException(var,x); @@ -143,6 +145,7 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { // // --------------------------------------------------------------------- // + @Override void findHandlingNode(SnmpVarBind varbind, long[] oid, int depth, SnmpRequestTree handlers) @@ -191,6 +194,7 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { // // --------------------------------------------------------------------- // + @Override long[] findNextHandlingNode(SnmpVarBind varbind, long[] oid, int pos, int depth, SnmpRequestTree handlers, @@ -267,6 +271,7 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { /** * Computes the root OID of the MIB. */ + @Override public void getRootOid(Vector result) { // If a node has several children, let assume that we are one step to @@ -359,7 +364,6 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { // String.valueOf(var) + " position= " + cursor); children.insertElementAt(child, newPos); child.registerNode(oid, cursor + 1, node); - return; } else { // The node is already registered @@ -404,7 +408,6 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { } } children.setElementAt(node,pos); - return; } else { if (child == null) throw new IllegalAccessException(); @@ -469,7 +472,7 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { int max= varList.length -1 ; int curr= low + (max-low)/2; - int elmt= 0; + int elmt; while (low <= max) { elmt= varList[curr]; if (cursor == elmt) { @@ -494,7 +497,7 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { if (varList == null) return -1; int max= varList.length -1 ; - int elmt=0; + int elmt; //final int[] v = varList; //if (index > a[max]) @@ -528,7 +531,7 @@ public class SnmpMibOid extends SnmpMibNode implements Serializable { /** * Contains the list of sub nodes. */ - private NonSyncVector children = new NonSyncVector(1); + private NonSyncVector children = new NonSyncVector<>(1); /** * The number of sub nodes. diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibRequest.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibRequest.java index b45a8bca877cf486e5d6aa0f83272156b8fb581d..e117bf2a8cdd0b6caef838f02f6f5e919c71fa9a 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibRequest.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibRequest.java @@ -50,7 +50,7 @@ public interface SnmpMibRequest { * @return The element of the enumeration are instances of * {@link com.sun.jmx.snmp.SnmpVarBind} */ - public Enumeration getElements(); + public Enumeration getElements(); /** * Returns the vector of varbind to be handled by the SNMP mib node. diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibRequestImpl.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibRequestImpl.java index dfd9f4645e94275e394c56067e5ed0644eaedd92..5f204bcba5808f8d860d72033d6ce5208b54a983 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibRequestImpl.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibRequestImpl.java @@ -87,6 +87,7 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { * Returns the local engine. This parameter is returned only if SnmpV3AdaptorServer is the adaptor receiving this request. Otherwise null is returned. * @return the local engine. */ + @Override public SnmpEngine getEngine() { return engine; } @@ -95,6 +96,7 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { * Gets the incoming request principal. This parameter is returned only if SnmpV3AdaptorServer is the adaptor receiving this request. Otherwise null is returned. * @return The request principal. **/ + @Override public String getPrincipal() { return principal; } @@ -103,6 +105,7 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { * Gets the incoming request security level. This level is defined in {@link com.sun.jmx.snmp.SnmpEngine SnmpEngine}. This parameter is returned only if SnmpV3AdaptorServer is the adaptor receiving this request. Otherwise -1 is returned. * @return The security level. */ + @Override public int getSecurityLevel() { return securityLevel; } @@ -110,6 +113,7 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { * Gets the incoming request security model. This parameter is returned only if SnmpV3AdaptorServer is the adaptor receiving this request. Otherwise -1 is returned. * @return The security model. */ + @Override public int getSecurityModel() { return securityModel; } @@ -117,6 +121,7 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { * Gets the incoming request context name. This parameter is returned only if SnmpV3AdaptorServer is the adaptor receiving this request. Otherwise null is returned. * @return The context name. */ + @Override public byte[] getContextName() { return contextName; } @@ -125,6 +130,7 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { * Gets the incoming request context name used by Access Control Model in order to allow or deny the access to OIDs. This parameter is returned only if SnmpV3AdaptorServer is the adaptor receiving this request. Otherwise null is returned. * @return The checked context. */ + @Override public byte[] getAccessContextName() { return accessContextName; } @@ -133,6 +139,7 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------------- + @Override public final SnmpPdu getPdu() { return reqPdu; } @@ -141,18 +148,21 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------------- - public final Enumeration getElements() {return varbinds.elements();} + @Override + public final Enumeration getElements() {return varbinds.elements();} // ------------------------------------------------------------------- // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------------- + @Override public final Vector getSubList() {return varbinds;} // ------------------------------------------------------------------- // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------------- + @Override public final int getSize() { if (varbinds == null) return 0; return varbinds.size(); @@ -162,24 +172,28 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------------- + @Override public final int getVersion() {return version;} // ------------------------------------------------------------------- // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------------- + @Override public final int getRequestPduVersion() {return reqPdu.version;} // ------------------------------------------------------------------- // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------------- + @Override public final Object getUserData() {return data;} // ------------------------------------------------------------------- // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------------- + @Override public final int getVarIndex(SnmpVarBind varbind) { return varbinds.indexOf(varbind); } @@ -188,6 +202,7 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------------- + @Override public void addVarBind(SnmpVarBind varbind) { varbinds.addElement(varbind); } @@ -218,7 +233,7 @@ final class SnmpMibRequestImpl implements SnmpMibRequest { // Returns the underlying vector of SNMP varbinds (used for algorithm // optimization). // ------------------------------------------------------------------- - final Vector getVarbinds() {return varbinds;} + final Vector getVarbinds() {return varbinds;} // ------------------------------------------------------------------- // Private variables diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibSubRequest.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibSubRequest.java index cd72847945ac1c997c108a3af3ef7bffa49e9280..76aa168b454bf072c95f3a00eacd970a7eb6a0f7 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibSubRequest.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibSubRequest.java @@ -65,7 +65,8 @@ public interface SnmpMibSubRequest extends SnmpMibRequest { * @return The elements of the enumeration are instances of * {@link com.sun.jmx.snmp.SnmpVarBind} */ - public Enumeration getElements(); + @Override + public Enumeration getElements(); /** * Return the list of varbind to be handled by the SNMP MIB node. @@ -85,6 +86,7 @@ public interface SnmpMibSubRequest extends SnmpMibRequest { * @return The elements of the vector are instances of * {@link com.sun.jmx.snmp.SnmpVarBind} */ + @Override public Vector getSubList(); /** diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibTable.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibTable.java index 7b6631afc057849629692c7c1e30b1c018b29577..e0282c6cec06a8a171db0ce56c0c381e23d0fc1d 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibTable.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibTable.java @@ -266,6 +266,7 @@ public abstract class SnmpMibTable extends SnmpMibNode *

* */ + @Override public void get(SnmpMibSubRequest req, int depth) throws SnmpStatusException { @@ -276,9 +277,9 @@ public abstract class SnmpMibTable extends SnmpMibNode // each varbind involved (nb: should not happen, the error // should have been registered earlier) if (isnew) { - SnmpVarBind var = null; - for (Enumeration e= r.getElements(); e.hasMoreElements();) { - var = (SnmpVarBind) e.nextElement(); + SnmpVarBind var; + for (Enumeration e= r.getElements(); e.hasMoreElements();) { + var = e.nextElement(); r.registerGetException(var,noSuchInstanceException); } } @@ -329,6 +330,7 @@ public abstract class SnmpMibTable extends SnmpMibNode *

* */ + @Override public void check(SnmpMibSubRequest req, int depth) throws SnmpStatusException { final SnmpOid oid = req.getEntryOid(); @@ -389,6 +391,7 @@ public abstract class SnmpMibTable extends SnmpMibNode *

* */ + @Override public void set(SnmpMibSubRequest req, int depth) throws SnmpStatusException { @@ -755,6 +758,7 @@ public abstract class SnmpMibTable extends SnmpMibNode * * @exception IllegalArgumentException Listener parameter is null. */ + @Override public synchronized void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) { @@ -768,13 +772,11 @@ public abstract class SnmpMibTable extends SnmpMibNode // looking for listener in handbackTable // - Vector handbackList = - handbackTable.get(listener) ; - Vector filterList = - filterTable.get(listener) ; + Vector handbackList = handbackTable.get(listener) ; + Vector filterList = filterTable.get(listener) ; if ( handbackList == null ) { - handbackList = new Vector() ; - filterList = new Vector() ; + handbackList = new Vector<>() ; + filterList = new Vector<>() ; handbackTable.put(listener, handbackList) ; filterTable.put(listener, filterList) ; } @@ -797,16 +799,14 @@ public abstract class SnmpMibTable extends SnmpMibNode * @exception ListenerNotFoundException The listener is not registered * in the MBean. */ + @Override public synchronized void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException { // looking for listener in handbackTable // - java.util.Vector handbackList = - (java.util.Vector) handbackTable.get(listener) ; - java.util.Vector filterList = - (java.util.Vector) filterTable.get(listener) ; + java.util.Vector handbackList = handbackTable.get(listener) ; if ( handbackList == null ) { throw new ListenerNotFoundException("listener"); } @@ -822,6 +822,7 @@ public abstract class SnmpMibTable extends SnmpMibNode * notification class and the notification type sent by the * SnmpMibTable. */ + @Override public MBeanNotificationInfo[] getNotificationInfo() { String[] types = {SnmpTableEntryNotification.SNMP_ENTRY_ADDED, @@ -1813,9 +1814,9 @@ public abstract class SnmpMibTable extends SnmpMibNode // // --------------------------------------------------------------------- - final static void checkRowStatusFail(SnmpMibSubRequest req, - int errorStatus) + static void checkRowStatusFail(SnmpMibSubRequest req, int errorStatus) throws SnmpStatusException { + final SnmpVarBind statusvb = req.getRowStatusVarBind(); final SnmpStatusException x = new SnmpStatusException(errorStatus); req.registerCheckException(statusvb,x); @@ -1827,9 +1828,9 @@ public abstract class SnmpMibTable extends SnmpMibNode // // --------------------------------------------------------------------- - final static void setRowStatusFail(SnmpMibSubRequest req, - int errorStatus) + static void setRowStatusFail(SnmpMibSubRequest req, int errorStatus) throws SnmpStatusException { + final SnmpVarBind statusvb = req.getRowStatusVarBind(); final SnmpStatusException x = new SnmpStatusException(errorStatus); req.registerSetException(statusvb,x); @@ -1840,6 +1841,7 @@ public abstract class SnmpMibTable extends SnmpMibNode // Implements the method defined in SnmpMibNode. // // --------------------------------------------------------------------- + @Override final synchronized void findHandlingNode(SnmpVarBind varbind, long[] oid, int depth, SnmpRequestTree handlers) @@ -1909,11 +1911,15 @@ public abstract class SnmpMibTable extends SnmpMibNode // largely inspired from the original getNext() method. // // --------------------------------------------------------------------- + @Override final synchronized long[] findNextHandlingNode(SnmpVarBind varbind, - long[] oid, int pos, int depth, - SnmpRequestTree handlers, - AcmChecker checker) + long[] oid, + int pos, + int depth, + SnmpRequestTree handlers, + AcmChecker checker) throws SnmpStatusException { + int length = oid.length; if (handlers == null) @@ -1974,7 +1980,7 @@ public abstract class SnmpMibTable extends SnmpMibNode } // Now that we've got everything right we can begin. - SnmpOid entryoid = null ; + SnmpOid entryoid; if (pos == (length - 1)) { // pos points to the last arc in the oid, and this arc is @@ -2200,28 +2206,25 @@ public abstract class SnmpMibTable extends SnmpMibNode // loop on listener // - for(java.util.Enumeration k = handbackTable.keys(); + for(java.util.Enumeration k = handbackTable.keys(); k.hasMoreElements(); ) { - NotificationListener listener = - (NotificationListener) k.nextElement(); + NotificationListener listener = k.nextElement(); // Get the associated handback list and the associated filter list // - java.util.Vector handbackList = - (java.util.Vector) handbackTable.get(listener) ; - java.util.Vector filterList = - (java.util.Vector) filterTable.get(listener) ; + java.util.Vector handbackList = handbackTable.get(listener) ; + java.util.Vector filterList = + filterTable.get(listener) ; // loop on handback // - java.util.Enumeration f = filterList.elements(); - for(java.util.Enumeration h = handbackList.elements(); + java.util.Enumeration f = filterList.elements(); + for(java.util.Enumeration h = handbackList.elements(); h.hasMoreElements(); ) { Object handback = h.nextElement(); - NotificationFilter filter = - (NotificationFilter)f.nextElement(); + NotificationFilter filter = f.nextElement(); if ((filter == null) || (filter.isNotificationEnabled(notification))) { @@ -2300,7 +2303,7 @@ public abstract class SnmpMibTable extends SnmpMibNode * OID was not found. * **/ - private final int findObject(SnmpOid oid) { + private int findObject(SnmpOid oid) { int low= 0; int max= size - 1; SnmpOid pos; @@ -2332,25 +2335,6 @@ public abstract class SnmpMibTable extends SnmpMibNode return -1; } - /** - * Search the position at which the given oid should be inserted - * in the OID table (tableoids). - * - *

- * @param oid The OID we would like to insert. - * - * @return The position at which the OID should be inserted in - * the table. - * - * @exception SnmpStatusException if the OID is already present in the - * table. - * - **/ - private final int getInsertionPoint(SnmpOid oid) - throws SnmpStatusException { - return getInsertionPoint(oid, true); - } - /** * Search the position at which the given oid should be inserted * in the OID table (tableoids). @@ -2371,7 +2355,7 @@ public abstract class SnmpMibTable extends SnmpMibNode * table and fail is true. * **/ - private final int getInsertionPoint(SnmpOid oid, boolean fail) + private int getInsertionPoint(SnmpOid oid, boolean fail) throws SnmpStatusException { final int failStatus = SnmpStatusException.snmpRspNotWritable; @@ -2413,7 +2397,7 @@ public abstract class SnmpMibTable extends SnmpMibNode * @param pos The position at which the OID to be removed is located. * **/ - private final void removeOid(int pos) { + private void removeOid(int pos) { if (pos >= tablecount) return; if (pos < 0) return; final int l1 = --tablecount-pos; @@ -2431,7 +2415,7 @@ public abstract class SnmpMibTable extends SnmpMibNode * @param pos The position at which the OID to be added is located. * **/ - private final void insertOid(int pos, SnmpOid oid) { + private void insertOid(int pos, SnmpOid oid) { if (pos >= tablesize || tablecount == tablesize) { // Vector must be enlarged @@ -2534,13 +2518,13 @@ public abstract class SnmpMibTable extends SnmpMibNode * The list of entries. * @serial */ - private final Vector entries= new Vector(); + private final Vector entries= new Vector<>(); /** * The list of object names. * @serial */ - private final Vector entrynames= new Vector(); + private final Vector entrynames= new Vector<>(); /** * Callback handlers @@ -2548,17 +2532,16 @@ public abstract class SnmpMibTable extends SnmpMibNode // final Vector callbacks = new Vector(); /** - * Listener hastable containing the hand-back objects. + * Listener hashtable containing the hand-back objects. */ private Hashtable> handbackTable = - new Hashtable>(); + new Hashtable<>(); /** - * Listener hastable containing the filter objects. + * Listener hashtable containing the filter objects. */ private Hashtable> - filterTable = - new Hashtable>(); + filterTable = new Hashtable<>(); // PACKAGE VARIABLES //------------------ diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpRequestTree.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpRequestTree.java index c401a73f77ecdff95b318398fe6a5846749aa8c1..dbcca12d9ef9b4dcce4b197a424b104e8476c2c4 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpRequestTree.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpRequestTree.java @@ -25,11 +25,9 @@ package com.sun.jmx.snmp.agent; import java.util.Vector; -import java.util.ArrayList; import java.util.Hashtable; import java.util.Enumeration; import java.util.Iterator; -import java.util.List; import java.util.NoSuchElementException; import java.util.Arrays; import java.util.logging.Level; @@ -77,7 +75,7 @@ final class SnmpRequestTree { this.request = req; this.version = req.getVersion(); this.creationflag = creationflag; - this.hashtable = new Hashtable(); + this.hashtable = new Hashtable<>(); setPduType(pdutype); } @@ -191,7 +189,7 @@ final class SnmpRequestTree { // SnmSubRequest associated with an Handler node. //------------------------------------------------------------------- - static final class Enum implements Enumeration { + static final class Enum implements Enumeration { Enum(SnmpRequestTree hlist,Handler h) { handler = h; this.hlist = hlist; @@ -203,11 +201,13 @@ final class SnmpRequestTree { private int iter = 0; private int size = 0; + @Override public boolean hasMoreElements() { return iter < size; } - public Object nextElement() throws NoSuchElementException { + @Override + public SnmpMibSubRequest nextElement() throws NoSuchElementException { if (iter == 0) { if (handler.sublist != null) { iter++; @@ -216,7 +216,7 @@ final class SnmpRequestTree { } iter ++; if (iter > size) throw new NoSuchElementException(); - Object result = hlist.getSubRequest(handler,entry); + SnmpMibSubRequest result = hlist.getSubRequest(handler,entry); entry++; return result; } @@ -252,7 +252,8 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------- - public Enumeration getElements() { + @Override + public Enumeration getElements() { return varbinds.elements(); } @@ -260,6 +261,7 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------- + @Override public Vector getSubList() { return varbinds; } @@ -268,6 +270,7 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------- + @Override public final int getSize() { if (varbinds == null) return 0; return varbinds.size(); @@ -277,6 +280,7 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------- + @Override public void addVarBind(SnmpVarBind varbind) { // XXX not sure we must also add the varbind in the global // request? or whether we should raise an exception: @@ -289,6 +293,7 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibSubRequest interface. // See SnmpMibSubRequest for the java doc. // ------------------------------------------------------------- + @Override public boolean isNewEntry() { return isnew; } @@ -297,6 +302,7 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibSubRequest interface. // See SnmpMibSubRequest for the java doc. // ------------------------------------------------------------- + @Override public SnmpOid getEntryOid() { return entryoid; } @@ -305,6 +311,7 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------- + @Override public int getVarIndex(SnmpVarBind varbind) { if (varbind == null) return 0; return global.getVarIndex(varbind); @@ -314,6 +321,7 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------- + @Override public Object getUserData() { return global.getUserData(); } @@ -322,6 +330,7 @@ final class SnmpRequestTree { // See SnmpMibSubRequest for the java doc. // ------------------------------------------------------------- + @Override public void registerGetException(SnmpVarBind var, SnmpStatusException exception) throws SnmpStatusException { @@ -364,6 +373,7 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibSubRequest interface. // See SnmpMibSubRequest for the java doc. // ------------------------------------------------------------- + @Override public void registerSetException(SnmpVarBind var, SnmpStatusException exception) throws SnmpStatusException { @@ -387,6 +397,7 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibSubRequest interface. // See SnmpMibSubRequest for the java doc. // ------------------------------------------------------------- + @Override public void registerCheckException(SnmpVarBind var, SnmpStatusException exception) throws SnmpStatusException { @@ -410,42 +421,52 @@ final class SnmpRequestTree { // Implements the method defined in SnmpMibRequest interface. // See SnmpMibRequest for the java doc. // ------------------------------------------------------------- + @Override public int getVersion() { return version; } + @Override public SnmpVarBind getRowStatusVarBind() { return statusvb; } + @Override public SnmpPdu getPdu() { return global.getPdu(); } + @Override public int getRequestPduVersion() { return global.getRequestPduVersion(); } + @Override public SnmpEngine getEngine() { return global.getEngine(); } + @Override public String getPrincipal() { return global.getPrincipal(); } + @Override public int getSecurityLevel() { return global.getSecurityLevel(); } + @Override public int getSecurityModel() { return global.getSecurityModel(); } + @Override public byte[] getContextName() { return global.getContextName(); } + @Override public byte[] getAccessContextName() { return global.getAccessContextName(); } @@ -485,7 +506,7 @@ final class SnmpRequestTree { * Adds a varbind in this node sublist. */ public void addVarbind(SnmpVarBind varbind) { - if (sublist == null) sublist = new Vector(); + if (sublist == null) sublist = new Vector<>(); sublist.addElement(varbind); } @@ -503,7 +524,7 @@ final class SnmpRequestTree { // Vectors are null: Allocate new vectors entryoids = new SnmpOid[Delta]; - entrylists = new Vector[Delta]; + entrylists = (Vector[])new Vector[Delta]; isentrynew = new boolean[Delta]; rowstatus = new SnmpVarBind[Delta]; entrysize = Delta; @@ -521,7 +542,7 @@ final class SnmpRequestTree { // Allocate larger vectors entrysize += Delta; entryoids = new SnmpOid[entrysize]; - entrylists = new Vector[entrysize]; + entrylists = (Vector[])new Vector[entrysize]; isentrynew = new boolean[entrysize]; rowstatus = new SnmpVarBind[entrysize]; @@ -595,7 +616,7 @@ final class SnmpRequestTree { // entryoids = new ArrayList(); // entrylists = new ArrayList(); // isentrynew = new ArrayList(); - v = new Vector(); + v = new Vector<>(); // entryoids.add(entryoid); // entrylists.add(v); // isentrynew.add(new Boolean(isnew)); @@ -614,7 +635,7 @@ final class SnmpRequestTree { // if (pos == -1 || pos >= entrycount ) { // pos = getInsertionPoint(entryoids,entryoid); // pos = getInsertionPoint(entryoids,entrycount,entryoid); - v = new Vector(); + v = new Vector<>(); // entryoids.add(pos,entryoid); // entrylists.add(pos,v); // isentrynew.add(pos,new Boolean(isnew)); @@ -775,7 +796,7 @@ final class SnmpRequestTree { // If it is a table, there will be one subrequest per entry involved. //------------------------------------------------------------------- - public Enumeration getSubRequests(Handler handler) { + public Enumeration getSubRequests(Handler handler) { return new Enum(this,handler); } @@ -783,7 +804,7 @@ final class SnmpRequestTree { // returns an enumeration of the Handlers stored in the Hashtable. //------------------------------------------------------------------- - public Enumeration getHandlers() { + public Enumeration getHandlers() { return hashtable.elements(); } @@ -1048,7 +1069,6 @@ final class SnmpRequestTree { handler.addVarbind(varbind); else handler.addVarbind(varbind,entryoid,isnew,statusvb); - return ; } diff --git a/src/share/classes/com/sun/jmx/snmp/agent/SnmpStandardObjectServer.java b/src/share/classes/com/sun/jmx/snmp/agent/SnmpStandardObjectServer.java index 5b2fbcfbb04909df80df90b9d2e7c7d795275b64..f0369468126b0c636d2bad25afdc042edf123c3a 100644 --- a/src/share/classes/com/sun/jmx/snmp/agent/SnmpStandardObjectServer.java +++ b/src/share/classes/com/sun/jmx/snmp/agent/SnmpStandardObjectServer.java @@ -27,14 +27,7 @@ package com.sun.jmx.snmp.agent; // java imports // import java.io.Serializable; -import java.util.Hashtable; import java.util.Enumeration; -import java.util.Vector; - -// jmx imports -// -import com.sun.jmx.snmp.SnmpOid; -import com.sun.jmx.snmp.SnmpValue; import com.sun.jmx.snmp.SnmpVarBind; import com.sun.jmx.snmp.SnmpStatusException; @@ -121,8 +114,8 @@ public class SnmpStandardObjectServer implements Serializable { final Object data = req.getUserData(); - for (Enumeration e= req.getElements(); e.hasMoreElements();) { - final SnmpVarBind var= (SnmpVarBind) e.nextElement(); + for (Enumeration e= req.getElements(); e.hasMoreElements();) { + final SnmpVarBind var= e.nextElement(); try { final long id = var.oid.getOidArc(depth); var.value = meta.get(id, data); @@ -182,9 +175,8 @@ public class SnmpStandardObjectServer implements Serializable { final Object data = req.getUserData(); - for (Enumeration e= req.getElements(); e.hasMoreElements();) { - SnmpVarBind var = null; - var = (SnmpVarBind) e.nextElement(); + for (Enumeration e= req.getElements(); e.hasMoreElements();) { + SnmpVarBind var = e.nextElement(); try { // This method will generate a SnmpStatusException // if `depth' is out of bounds. @@ -248,8 +240,8 @@ public class SnmpStandardObjectServer implements Serializable { final Object data = req.getUserData(); - for (Enumeration e= req.getElements(); e.hasMoreElements();) { - final SnmpVarBind var = (SnmpVarBind) e.nextElement(); + for (Enumeration e= req.getElements(); e.hasMoreElements();) { + final SnmpVarBind var = e.nextElement(); try { // This method will generate a SnmpStatusException // if `depth' is out of bounds. diff --git a/src/share/classes/com/sun/jmx/snmp/daemon/CommunicatorServer.java b/src/share/classes/com/sun/jmx/snmp/daemon/CommunicatorServer.java index 4b576b60fa21a12b7192fd6a1820bbb0c8b6f339..b2634d8eee1ed281e89c94c3a37411f04c6b3364 100644 --- a/src/share/classes/com/sun/jmx/snmp/daemon/CommunicatorServer.java +++ b/src/share/classes/com/sun/jmx/snmp/daemon/CommunicatorServer.java @@ -33,7 +33,6 @@ package com.sun.jmx.snmp.daemon; import java.io.ObjectInputStream; import java.io.IOException; import java.net.InetAddress; -import java.util.Enumeration; import java.util.logging.Level; import java.util.Vector; import java.util.NoSuchElementException; @@ -50,8 +49,6 @@ import javax.management.NotificationBroadcasterSupport; import javax.management.MBeanNotificationInfo; import javax.management.AttributeChangeNotification; import javax.management.ListenerNotFoundException; -import javax.management.loading.ClassLoaderRepository; -import javax.management.MBeanServerFactory; import static com.sun.jmx.defaults.JmxProperties.SNMP_ADAPTOR_LOGGER; @@ -225,9 +222,8 @@ public abstract class CommunicatorServer private transient Object stateLock = new Object(); private transient Vector - clientHandlerVector = new Vector() ; + clientHandlerVector = new Vector<>() ; - private transient Thread fatherThread = Thread.currentThread() ; private transient Thread mainThread = null ; private volatile boolean stopRequested = false ; @@ -328,6 +324,7 @@ public abstract class CommunicatorServer * Has no effect if this CommunicatorServer is * ONLINE or STOPPING. */ + @Override public void start() { try { start(0); @@ -346,6 +343,7 @@ public abstract class CommunicatorServer * Has no effect if this CommunicatorServer is * OFFLINE or STOPPING. */ + @Override public void stop() { synchronized (stateLock) { if (state == OFFLINE || state == STOPPING) { @@ -393,6 +391,7 @@ public abstract class CommunicatorServer * * @return True if connector is ONLINE; false otherwise. */ + @Override public boolean isActive() { synchronized (stateLock) { return (state == ONLINE); @@ -431,6 +430,7 @@ public abstract class CommunicatorServer * @return true if the value of this MBean's State attribute is the * same as the wantedState parameter; false otherwise. */ + @Override public boolean waitState(int wantedState, long timeOut) { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, @@ -595,6 +595,7 @@ public abstract class CommunicatorServer * @return ONLINE, OFFLINE, * STARTING or STOPPING. */ + @Override public int getState() { synchronized (stateLock) { return state ; @@ -607,6 +608,7 @@ public abstract class CommunicatorServer * @return One of the strings "ONLINE", "OFFLINE", "STARTING" or * "STOPPING". */ + @Override public String getStateString() { return getStringForState(state) ; } @@ -616,6 +618,7 @@ public abstract class CommunicatorServer * * @return The host name used by this CommunicatorServer. */ + @Override public String getHost() { try { host = InetAddress.getLocalHost().getHostName(); @@ -630,6 +633,7 @@ public abstract class CommunicatorServer * * @return The port number used by this CommunicatorServer. */ + @Override public int getPort() { synchronized (stateLock) { return port ; @@ -645,6 +649,7 @@ public abstract class CommunicatorServer * @exception java.lang.IllegalStateException This method has been invoked * while the communicator was ONLINE or STARTING. */ + @Override public void setPort(int port) throws java.lang.IllegalStateException { synchronized (stateLock) { if ((state == ONLINE) || (state == STARTING)) @@ -659,7 +664,8 @@ public abstract class CommunicatorServer * Gets the protocol being used by this CommunicatorServer. * @return The protocol as a string. */ - public abstract String getProtocol() ; + @Override + public abstract String getProtocol(); /** * Gets the number of clients that have been processed by this @@ -754,6 +760,7 @@ public abstract class CommunicatorServer *

* The run method executed by this connector's main thread. */ + @Override public void run() { // Fix jaw.00667.B @@ -851,7 +858,7 @@ public abstract class CommunicatorServer } finally { synchronized (stateLock) { interrupted = true; - Thread.currentThread().interrupted(); + Thread.interrupted(); } // ---------------------- @@ -970,7 +977,7 @@ public abstract class CommunicatorServer "MBeanServer argument must be MBean server where this " + "server is registered, or an MBeanServerForwarder " + "leading to that server"; - Vector seenMBS = new Vector(); + Vector seenMBS = new Vector<>(); for (MBeanServer mbs = newMBS; mbs != bottomMBS; mbs = ((MBeanServerForwarder) mbs).getMBeanServer()) { @@ -1153,8 +1160,7 @@ public abstract class CommunicatorServer state = OFFLINE; stopRequested = false; servedClientCount = 0; - clientHandlerVector = new Vector(); - fatherThread = Thread.currentThread(); + clientHandlerVector = new Vector<>(); mainThread = null; notifCount = 0; notifInfos = null; @@ -1184,6 +1190,7 @@ public abstract class CommunicatorServer * * @exception IllegalArgumentException Listener parameter is null. */ + @Override public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) @@ -1207,6 +1214,7 @@ public abstract class CommunicatorServer * * @exception ListenerNotFoundException The listener is not registered. */ + @Override public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException { @@ -1225,6 +1233,7 @@ public abstract class CommunicatorServer * sent when the State attribute of this CommunicatorServer * changes. */ + @Override public MBeanNotificationInfo[] getNotificationInfo() { // Initialize notifInfos on first call to getNotificationInfo() @@ -1304,6 +1313,7 @@ public abstract class CommunicatorServer * the MBeanServer and re-thrown * as an MBeanRegistrationException. */ + @Override public ObjectName preRegister(MBeanServer server, ObjectName name) throws java.lang.Exception { objectName = name; @@ -1325,6 +1335,7 @@ public abstract class CommunicatorServer * successfully registered in the MBeanServer. * The value false means that the registration phase has failed. */ + @Override public void postRegister(Boolean registrationDone) { if (!registrationDone.booleanValue()) { synchronized (this) { @@ -1340,6 +1351,7 @@ public abstract class CommunicatorServer * the MBeanServer and re-thrown * as an MBeanRegistrationException. */ + @Override public void preDeregister() throws java.lang.Exception { synchronized (this) { topMBS = bottomMBS = null; @@ -1354,22 +1366,8 @@ public abstract class CommunicatorServer /** * Do nothing. */ + @Override public void postDeregister(){ } - /** - * Load a class using the default loader repository - **/ - Class loadClass(String className) - throws ClassNotFoundException { - try { - return Class.forName(className); - } catch (ClassNotFoundException e) { - final ClassLoaderRepository clr = - MBeanServerFactory.getClassLoaderRepository(bottomMBS); - if (clr == null) throw new ClassNotFoundException(className); - return clr.loadClass(className); - } - } - } diff --git a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServer.java b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServer.java index 03822a091fa341901375efefb9fdcb3fba8c9e71..612d4c57437968f3615a2487f6bac8b9a28984f5 100644 --- a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServer.java +++ b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 @@ -47,7 +47,6 @@ import java.io.InterruptedIOException; import javax.management.MBeanServer; import javax.management.MBeanRegistration; import javax.management.ObjectName; -import javax.management.InstanceAlreadyExistsException; import static com.sun.jmx.defaults.JmxProperties.SNMP_ADAPTOR_LOGGER; import com.sun.jmx.snmp.SnmpIpAddress; import com.sun.jmx.snmp.SnmpMessage; @@ -157,7 +156,7 @@ public class SnmpAdaptorServer extends CommunicatorServer /** * The IP address based ACL used by this SNMP protocol adaptor. */ - private Object ipacl = null; + private InetAddressAcl ipacl = null; /** * The factory object. @@ -199,7 +198,7 @@ public class SnmpAdaptorServer extends CommunicatorServer transient DatagramSocket trapSocket = null; private transient SnmpSession informSession = null; private transient DatagramPacket packet = null; - transient Vector mibs = new Vector(); + transient Vector mibs = new Vector<>(); private transient SnmpMibTree root; /** @@ -482,8 +481,7 @@ public class SnmpAdaptorServer extends CommunicatorServer // if (acl == null && forceAcl) { try { - acl = (InetAddressAcl) - new SnmpAcl("SNMP protocol adaptor IP ACL"); + acl = new SnmpAcl("SNMP protocol adaptor IP ACL"); } catch (UnknownHostException e) { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, @@ -508,6 +506,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * since its creation. This counter is not reset by the stop * method. */ + @Override public int getServedClientCount() { return super.getServedClientCount(); } @@ -519,6 +518,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @return The number of managers currently being processed by this * SNMP protocol adaptor. */ + @Override public int getActiveClientCount() { return super.getActiveClientCount(); } @@ -530,6 +530,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @return The maximum number of managers that this SNMP protocol adaptor * can process concurrently. */ + @Override public int getMaxActiveClientCount() { return super.getMaxActiveClientCount(); } @@ -543,6 +544,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @exception java.lang.IllegalStateException This method has been invoked * while the communicator was ONLINE or STARTING. */ + @Override public void setMaxActiveClientCount(int c) throws java.lang.IllegalStateException { super.setMaxActiveClientCount(c); @@ -554,8 +556,9 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public InetAddressAcl getInetAddressAcl() { - return (InetAddressAcl)ipacl; + return ipacl; } /** @@ -564,6 +567,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The port number for sending SNMP traps. */ + @Override public Integer getTrapPort() { return new Integer(trapPort) ; } @@ -573,6 +577,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @param port The port number for sending SNMP traps. */ + @Override public void setTrapPort(Integer port) { setTrapPort(port.intValue()); } @@ -595,6 +600,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The port number for sending SNMP inform requests. */ + @Override public int getInformPort() { return informPort; } @@ -605,6 +611,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @param port The port number for sending SNMP inform requests. */ + @Override public void setInformPort(int port) { if (port < 0) throw new IllegalArgumentException("Inform request port "+ @@ -617,6 +624,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The string "snmp". */ + @Override public String getProtocol() { return "snmp"; } @@ -629,6 +637,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The buffer size. */ + @Override public Integer getBufferSize() { return new Integer(bufferSize) ; } @@ -643,6 +652,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @exception java.lang.IllegalStateException This method has been invoked * while the communicator was ONLINE or STARTING. */ + @Override public void setBufferSize(Integer s) throws java.lang.IllegalStateException { if ((state == ONLINE) || (state == STARTING)) { @@ -658,6 +668,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * By default, a maximum of 3 tries is used. * @return The maximun number of tries. */ + @Override final public int getMaxTries() { return maxTries; } @@ -667,6 +678,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * request before giving up. * @param newMaxTries The maximun number of tries. */ + @Override final public synchronized void setMaxTries(int newMaxTries) { if (newMaxTries < 0) throw new IllegalArgumentException(); @@ -678,6 +690,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * By default, a timeout of 3 seconds is used. * @return The value of the timeout property. */ + @Override final public int getTimeout() { return timeout; } @@ -686,6 +699,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * Changes the timeout to wait for an inform response from the manager. * @param newTimeout The timeout (in milliseconds). */ + @Override final public synchronized void setTimeout(int newTimeout) { if (newTimeout < 0) throw new IllegalArgumentException(); @@ -697,6 +711,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The factory object. */ + @Override public SnmpPduFactory getPduFactory() { return pduFactory ; } @@ -706,6 +721,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @param factory The factory object (null means the default factory). */ + @Override public void setPduFactory(SnmpPduFactory factory) { if (factory == null) pduFactory = new SnmpPduFactoryBER() ; @@ -719,6 +735,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @param factory The factory object (null means no factory). * @see com.sun.jmx.snmp.agent.SnmpUserDataFactory */ + @Override public void setUserDataFactory(SnmpUserDataFactory factory) { userDataFactory = factory ; } @@ -729,6 +746,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @return The factory object (null means no factory). * @see com.sun.jmx.snmp.agent.SnmpUserDataFactory */ + @Override public SnmpUserDataFactory getUserDataFactory() { return userDataFactory; } @@ -745,6 +763,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @return true if authentication traps are enabled, * false otherwise. */ + @Override public boolean getAuthTrapEnabled() { return authTrapEnabled ; } @@ -755,6 +774,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @param enabled Flag indicating if traps need to be sent. */ + @Override public void setAuthTrapEnabled(boolean enabled) { authTrapEnabled = enabled ; } @@ -772,6 +792,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return true if responses are sent. */ + @Override public boolean getAuthRespEnabled() { return authRespEnabled ; } @@ -782,6 +803,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @param enabled Flag indicating if responses need to be sent. */ + @Override public void setAuthRespEnabled(boolean enabled) { authRespEnabled = enabled ; } @@ -793,6 +815,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The OID in string format "x.x.x.x". */ + @Override public String getEnterpriseOid() { return enterpriseOid.toString() ; } @@ -804,6 +827,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @exception IllegalArgumentException The string format is incorrect */ + @Override public void setEnterpriseOid(String oid) throws IllegalArgumentException { enterpriseOid = new SnmpOid(oid) ; } @@ -813,11 +837,12 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return An array of MIB names. */ + @Override public String[] getMibs() { String[] result = new String[mibs.size()] ; int i = 0 ; - for (Enumeration e = mibs.elements() ; e.hasMoreElements() ;) { - SnmpMibAgent mib = (SnmpMibAgent)e.nextElement() ; + for (Enumeration e = mibs.elements() ; e.hasMoreElements() ;) { + SnmpMibAgent mib = e.nextElement() ; result[i++] = mib.getMibName(); } return result ; @@ -831,6 +856,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpOutTraps value. */ + @Override public Long getSnmpOutTraps() { return new Long(snmpOutTraps); } @@ -840,6 +866,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpOutGetResponses value. */ + @Override public Long getSnmpOutGetResponses() { return new Long(snmpOutGetResponses); } @@ -849,6 +876,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpOutGenErrs value. */ + @Override public Long getSnmpOutGenErrs() { return new Long(snmpOutGenErrs); } @@ -858,6 +886,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpOutBadValues value. */ + @Override public Long getSnmpOutBadValues() { return new Long(snmpOutBadValues); } @@ -867,6 +896,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpOutNoSuchNames value. */ + @Override public Long getSnmpOutNoSuchNames() { return new Long(snmpOutNoSuchNames); } @@ -876,6 +906,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpOutTooBigs value. */ + @Override public Long getSnmpOutTooBigs() { return new Long(snmpOutTooBigs); } @@ -885,6 +916,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpInASNParseErrs value. */ + @Override public Long getSnmpInASNParseErrs() { return new Long(snmpInASNParseErrs); } @@ -894,6 +926,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpInBadCommunityUses value. */ + @Override public Long getSnmpInBadCommunityUses() { return new Long(snmpInBadCommunityUses); } @@ -904,6 +937,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpInBadCommunityNames value. */ + @Override public Long getSnmpInBadCommunityNames() { return new Long(snmpInBadCommunityNames); } @@ -913,6 +947,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpInBadVersions value. */ + @Override public Long getSnmpInBadVersions() { return new Long(snmpInBadVersions); } @@ -922,6 +957,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpOutPkts value. */ + @Override public Long getSnmpOutPkts() { return new Long(snmpOutPkts); } @@ -931,6 +967,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpInPkts value. */ + @Override public Long getSnmpInPkts() { return new Long(snmpInPkts); } @@ -940,6 +977,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpInGetRequests value. */ + @Override public Long getSnmpInGetRequests() { return new Long(snmpInGetRequests); } @@ -949,6 +987,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpInGetNexts value. */ + @Override public Long getSnmpInGetNexts() { return new Long(snmpInGetNexts); } @@ -958,6 +997,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpInSetRequests value. */ + @Override public Long getSnmpInSetRequests() { return new Long(snmpInSetRequests); } @@ -967,6 +1007,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpInTotalSetVars value. */ + @Override public Long getSnmpInTotalSetVars() { return new Long(snmpInTotalSetVars); } @@ -976,6 +1017,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @return The snmpInTotalReqVars value. */ + @Override public Long getSnmpInTotalReqVars() { return new Long(snmpInTotalReqVars); } @@ -988,6 +1030,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public Long getSnmpSilentDrops() { return new Long(snmpSilentDrops); } @@ -1000,6 +1043,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public Long getSnmpProxyDrops() { return new Long(0); } @@ -1027,6 +1071,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @exception java.lang.Exception */ + @Override public ObjectName preRegister(MBeanServer server, ObjectName name) throws java.lang.Exception { @@ -1040,6 +1085,7 @@ public class SnmpAdaptorServer extends CommunicatorServer /** * Not used in this context. */ + @Override public void postRegister (Boolean registrationDone) { super.postRegister(registrationDone); } @@ -1047,6 +1093,7 @@ public class SnmpAdaptorServer extends CommunicatorServer /** * Not used in this context. */ + @Override public void preDeregister() throws java.lang.Exception { super.preDeregister(); } @@ -1054,6 +1101,7 @@ public class SnmpAdaptorServer extends CommunicatorServer /** * Not used in this context. */ + @Override public void postDeregister() { super.postDeregister(); } @@ -1067,6 +1115,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @exception IllegalArgumentException If the parameter is null. */ + @Override public SnmpMibHandler addMib(SnmpMibAgent mib) throws IllegalArgumentException { if (mib == null) { @@ -1097,6 +1146,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public SnmpMibHandler addMib(SnmpMibAgent mib, SnmpOid[] oids) throws IllegalArgumentException { if (mib == null) { @@ -1129,6 +1179,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public SnmpMibHandler addMib(SnmpMibAgent mib, String contextName) throws IllegalArgumentException { return addMib(mib); @@ -1150,10 +1201,12 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public SnmpMibHandler addMib(SnmpMibAgent mib, String contextName, SnmpOid[] oids) throws IllegalArgumentException { + return addMib(mib, oids); } @@ -1171,6 +1224,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public boolean removeMib(SnmpMibAgent mib, String contextName) { return removeMib(mib); } @@ -1183,6 +1237,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @return true if the specified mib was a MIB * included in the SNMP MIB handler, false otherwise. */ + @Override public boolean removeMib(SnmpMibAgent mib) { root.unregister(mib); return (mibs.removeElement(mib)) ; @@ -1199,6 +1254,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public boolean removeMib(SnmpMibAgent mib, SnmpOid[] oids) { root.unregister(mib, oids); return (mibs.removeElement(mib)) ; @@ -1216,6 +1272,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public boolean removeMib(SnmpMibAgent mib, String contextName, SnmpOid[] oids) { @@ -1228,6 +1285,7 @@ public class SnmpAdaptorServer extends CommunicatorServer /** * Creates the datagram socket. */ + @Override protected void doBind() throws CommunicationException, InterruptedException { @@ -1255,6 +1313,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * that port number was 0. * @return the actual port to which the adaptor is bound. **/ + @Override public int getPort() { synchronized (this) { if (socket != null) return socket.getLocalPort(); @@ -1265,6 +1324,7 @@ public class SnmpAdaptorServer extends CommunicatorServer /** * Closes the datagram socket. */ + @Override protected void doUnbind() throws CommunicationException, InterruptedException { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { @@ -1282,12 +1342,17 @@ public class SnmpAdaptorServer extends CommunicatorServer closeInformSocketIfNeeded() ; } - void createSnmpRequestHandler(SnmpAdaptorServer server, int id, - DatagramSocket s, DatagramPacket p, - SnmpMibTree tree, Vector m, Object a, - SnmpPduFactory factory, - SnmpUserDataFactory dataFactory, - MBeanServer f, ObjectName n) { + private void createSnmpRequestHandler(SnmpAdaptorServer server, + int id, + DatagramSocket s, + DatagramPacket p, + SnmpMibTree tree, + Vector m, + InetAddressAcl a, + SnmpPduFactory factory, + SnmpUserDataFactory dataFactory, + MBeanServer f, + ObjectName n) { final SnmpRequestHandler handler = new SnmpRequestHandler(this, id, s, p, tree, m, a, factory, dataFactory, f, n); @@ -1298,6 +1363,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * Reads a packet from the datagram socket and creates a request * handler which decodes and processes the request. */ + @Override protected void doReceive() throws CommunicationException, InterruptedException { @@ -1339,13 +1405,14 @@ public class SnmpAdaptorServer extends CommunicatorServer } } + @Override protected void doError(Exception e) throws CommunicationException { - return; } /** * Not used in this context. */ + @Override protected void doProcess() throws CommunicationException, InterruptedException { } @@ -1357,6 +1424,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * We attempt only once... * @return 1 **/ + @Override protected int getBindTries() { return 1; } @@ -1368,6 +1436,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * Has no effect if this SNMP protocol adaptor is OFFLINE or * STOPPING. */ + @Override public void stop(){ final int port = getPort(); @@ -1424,6 +1493,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @exception SnmpStatusException If the trap exceeds the limit defined * by bufferSize. */ + @Override public void snmpV1Trap(int generic, int specific, SnmpVarBindList varBindList) throws IOException, SnmpStatusException { @@ -1499,6 +1569,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @exception SnmpStatusException If the trap exceeds the limit defined * by bufferSize. */ + @Override public void snmpV1Trap(InetAddress addr, String cs, int generic, int specific, SnmpVarBindList varBindList) throws IOException, SnmpStatusException { @@ -1617,6 +1688,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public void snmpV1Trap(SnmpPeer peer, SnmpIpAddress agentAddr, SnmpOid enterpOid, @@ -1625,6 +1697,7 @@ public class SnmpAdaptorServer extends CommunicatorServer SnmpVarBindList varBindList, SnmpTimeticks time) throws IOException, SnmpStatusException { + SnmpParameters p = (SnmpParameters) peer.getParams(); snmpV1Trap(peer.getDestAddr(), peer.getDestPort(), @@ -1745,11 +1818,13 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public void snmpV2Trap(SnmpPeer peer, SnmpOid trapOid, SnmpVarBindList varBindList, SnmpTimeticks time) throws IOException, SnmpStatusException { + SnmpParameters p = (SnmpParameters) peer.getParams(); snmpV2Trap(peer.getDestAddr(), peer.getDestPort(), @@ -1781,6 +1856,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @exception SnmpStatusException If the trap exceeds the limit defined * by bufferSize. */ + @Override public void snmpV2Trap(SnmpOid trapOid, SnmpVarBindList varBindList) throws IOException, SnmpStatusException { @@ -1801,7 +1877,7 @@ public class SnmpAdaptorServer extends CommunicatorServer SnmpVarBindList fullVbl ; if (varBindList != null) - fullVbl = (SnmpVarBindList)varBindList.clone() ; + fullVbl = varBindList.clone() ; else fullVbl = new SnmpVarBindList(2) ; SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ; @@ -1840,6 +1916,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @exception SnmpStatusException If the trap exceeds the limit * defined by bufferSize. */ + @Override public void snmpV2Trap(InetAddress addr, String cs, SnmpOid trapOid, SnmpVarBindList varBindList) throws IOException, SnmpStatusException { @@ -1865,7 +1942,7 @@ public class SnmpAdaptorServer extends CommunicatorServer SnmpVarBindList fullVbl ; if (varBindList != null) - fullVbl = (SnmpVarBindList)varBindList.clone() ; + fullVbl = varBindList.clone() ; else fullVbl = new SnmpVarBindList(2) ; SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ; @@ -1964,12 +2041,12 @@ public class SnmpAdaptorServer extends CommunicatorServer SnmpVarBindList fullVbl ; if (varBindList != null) - fullVbl = (SnmpVarBindList)varBindList.clone() ; + fullVbl = varBindList.clone() ; else fullVbl = new SnmpVarBindList(2) ; // Only difference with other - SnmpTimeticks sysUpTimeValue = null; + SnmpTimeticks sysUpTimeValue; if(time != null) sysUpTimeValue = time; else @@ -2002,6 +2079,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public void snmpPduTrap(InetAddress address, SnmpPduPacket pdu) throws IOException, SnmpStatusException { @@ -2021,6 +2099,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * by bufferSize. * @since 1.5 */ + @Override public void snmpPduTrap(SnmpPeer peer, SnmpPduPacket pdu) throws IOException, SnmpStatusException { @@ -2066,13 +2145,12 @@ public class SnmpAdaptorServer extends CommunicatorServer int sendingCount = 0 ; openTrapSocketIfNeeded() ; if (ipacl != null) { - Enumeration ed = ((InetAddressAcl)ipacl).getTrapDestinations() ; + Enumeration ed = ipacl.getTrapDestinations() ; while (ed.hasMoreElements()) { - msg.address = (InetAddress)ed.nextElement() ; - Enumeration ec = ((InetAddressAcl)ipacl). - getTrapCommunities(msg.address) ; + msg.address = ed.nextElement() ; + Enumeration ec = ipacl.getTrapCommunities(msg.address) ; while (ec.hasMoreElements()) { - msg.community = ((String)ec.nextElement()).getBytes() ; + msg.community = ec.nextElement().getBytes() ; try { sendTrapMessage(msg) ; sendingCount++ ; @@ -2164,6 +2242,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ private void sendTrapMessage(SnmpMessage msg) throws IOException, SnmpTooBigException { + byte[] buffer = new byte[bufferSize] ; DatagramPacket packet = new DatagramPacket(buffer, buffer.length) ; int encodingLength = msg.encodeMessage(buffer) ; @@ -2245,8 +2324,10 @@ public class SnmpAdaptorServer extends CommunicatorServer * @exception SnmpStatusException If the inform request exceeds the * limit defined by bufferSize. */ - public Vector snmpInformRequest(SnmpInformHandler cb, SnmpOid trapOid, - SnmpVarBindList varBindList) + @Override + public Vector snmpInformRequest(SnmpInformHandler cb, + SnmpOid trapOid, + SnmpVarBindList varBindList) throws IllegalStateException, IOException, SnmpStatusException { if (!isActive()) { @@ -2263,7 +2344,7 @@ public class SnmpAdaptorServer extends CommunicatorServer // SnmpVarBindList fullVbl ; if (varBindList != null) - fullVbl = (SnmpVarBindList)varBindList.clone() ; + fullVbl = varBindList.clone() ; else fullVbl = new SnmpVarBindList(2) ; SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ; @@ -2277,17 +2358,16 @@ public class SnmpAdaptorServer extends CommunicatorServer // Now send the SNMP message to each destination // - Vector informReqList = new Vector(); - InetAddress addr = null; - String cs = null; + Vector informReqList = new Vector<>(); + InetAddress addr; + String cs; if (ipacl != null) { - Enumeration ed = ((InetAddressAcl)ipacl).getInformDestinations() ; + Enumeration ed = ipacl.getInformDestinations() ; while (ed.hasMoreElements()) { - addr = (InetAddress)ed.nextElement() ; - Enumeration ec = ((InetAddressAcl)ipacl). - getInformCommunities(addr) ; + addr = ed.nextElement() ; + Enumeration ec = ipacl.getInformCommunities(addr) ; while (ec.hasMoreElements()) { - cs = (String)ec.nextElement() ; + cs = ec.nextElement() ; informReqList.addElement( informSession.makeAsyncRequest(addr, cs, cb, fullVbl,getInformPort())) ; @@ -2330,6 +2410,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * @exception SnmpStatusException If the inform request exceeds the * limit defined by bufferSize. */ + @Override public SnmpInformRequest snmpInformRequest(InetAddress addr, String cs, SnmpInformHandler cb, @@ -2380,11 +2461,13 @@ public class SnmpAdaptorServer extends CommunicatorServer * * @since 1.5 */ + @Override public SnmpInformRequest snmpInformRequest(SnmpPeer peer, SnmpInformHandler cb, SnmpOid trapOid, SnmpVarBindList varBindList) throws IllegalStateException, IOException, SnmpStatusException { + SnmpParameters p = (SnmpParameters) peer.getParams(); return snmpInformRequest(peer.getDestAddr(), peer.getDestPort(), @@ -2401,9 +2484,9 @@ public class SnmpAdaptorServer extends CommunicatorServer * @param protocolVersion The protocol version. * @param reqPduType The pdu type. */ - public static final int mapErrorStatus(int errorStatus, - int protocolVersion, - int reqPduType) { + public static int mapErrorStatus(int errorStatus, + int protocolVersion, + int reqPduType) { return SnmpSubRequestHandler.mapErrorStatus(errorStatus, protocolVersion, reqPduType); @@ -2416,6 +2499,7 @@ public class SnmpAdaptorServer extends CommunicatorServer SnmpOid trapOid, SnmpVarBindList varBindList) throws IllegalStateException, IOException, SnmpStatusException { + if (!isActive()) { throw new IllegalStateException( "Start SNMP adaptor server before carrying out this operation"); @@ -2430,7 +2514,7 @@ public class SnmpAdaptorServer extends CommunicatorServer // SnmpVarBindList fullVbl ; if (varBindList != null) - fullVbl = (SnmpVarBindList)varBindList.clone() ; + fullVbl = varBindList.clone() ; else fullVbl = new SnmpVarBindList(2) ; SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ; @@ -2489,6 +2573,7 @@ public class SnmpAdaptorServer extends CommunicatorServer * references to the object. *

Closes the datagram socket associated to this SNMP protocol adaptor. */ + @Override protected void finalize() { try { if (socket != null) { @@ -2511,6 +2596,7 @@ public class SnmpAdaptorServer extends CommunicatorServer /** * Returns the string used in debug traces. */ + @Override String makeDebugTag() { return "SnmpAdaptorServer["+ getProtocol() + ":" + getPort() + "]"; } @@ -2615,13 +2701,13 @@ public class SnmpAdaptorServer extends CommunicatorServer // This is for transient structures to be initialized to specific // default values. // - mibs = new Vector() ; + mibs = new Vector<>() ; } /** * Common initializations. */ - private void init(Object acl, int p, InetAddress a) { + private void init(InetAddressAcl acl, int p, InetAddress a) { root= new SnmpMibTree(); @@ -2650,6 +2736,7 @@ public class SnmpAdaptorServer extends CommunicatorServer return root.getAgentMib(oid); } + @Override protected Thread createMainThread() { final Thread t = super.createMainThread(); t.setDaemon(true); diff --git a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServerMBean.java b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServerMBean.java index e2d86b68a36cfdce851eca68d56457d1456cd4cd..1b42ed4f0432c69b2e594cc0970863c52f35857b 100644 --- a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServerMBean.java +++ b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServerMBean.java @@ -140,6 +140,7 @@ public interface SnmpAdaptorServerMBean extends CommunicatorServerMBean { * * @return The string "snmp". */ + @Override public String getProtocol(); /** @@ -636,7 +637,8 @@ public interface SnmpAdaptorServerMBean extends CommunicatorServerMBean { * @exception IOException An I/O error occurred while sending the inform request. * @exception SnmpStatusException If the inform request exceeds the limit defined by bufferSize. */ - public Vector snmpInformRequest(SnmpInformHandler cb, SnmpOid trapOid, SnmpVarBindList varBindList) + public Vector snmpInformRequest(SnmpInformHandler cb, SnmpOid trapOid, + SnmpVarBindList varBindList) throws IllegalStateException, IOException, SnmpStatusException; /** diff --git a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpMibTree.java b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpMibTree.java index 66fe5f8a313776f865b5aea175ac353736a27d48..c6f67700f4863379899c294ecd5d3f4b5760834c 100644 --- a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpMibTree.java +++ b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpMibTree.java @@ -125,7 +125,7 @@ final class SnmpMibTree { TreeNode node= retrieveChild(oid, cursor); if (node == null) return this; - if (children.size() == 0) { + if (children.isEmpty()) { // In this case, the node does not have any children. So no point to // continue the search ... return node; @@ -149,24 +149,24 @@ final class SnmpMibTree { public void printTree(String ident) { - StringBuffer buff= new StringBuffer(); + StringBuilder buff= new StringBuilder(); if (agents == null) { return; } - for(Enumeration e= agents.elements(); e.hasMoreElements(); ) { - SnmpMibAgent mib= (SnmpMibAgent) e.nextElement(); + for(Enumeration e= agents.elements(); e.hasMoreElements(); ) { + SnmpMibAgent mib= e.nextElement(); if (mib == null) buff.append("empty "); else - buff.append(mib.getMibName() + " "); + buff.append(mib.getMibName()).append(" "); } ident+= " "; if (children == null) { return; } - for(Enumeration e= children.elements(); e.hasMoreElements(); ) { - TreeNode node= (TreeNode) e.nextElement(); + for(Enumeration e= children.elements(); e.hasMoreElements(); ) { + TreeNode node= e.nextElement(); node.printTree(ident); } } @@ -185,7 +185,7 @@ final class SnmpMibTree { } private void removeAgentFully(SnmpMibAgent agent) { - Vector v = new Vector(); + Vector v = new Vector<>(); for(Enumeration e= children.elements(); e.hasMoreElements(); ) { @@ -212,9 +212,9 @@ final class SnmpMibTree { } - private void setAgent(SnmpMibAgent agent) { - this.agent = agent; - } + private void setAgent(SnmpMibAgent agent) { + this.agent = agent; + } private void registerNode(long[] oid, int cursor, SnmpMibAgent agent) { @@ -247,20 +247,20 @@ final class SnmpMibTree { private TreeNode retrieveChild(long[] oid, int current) { long theValue= oid[current]; - for(Enumeration e= children.elements(); e.hasMoreElements(); ) { - TreeNode node= (TreeNode) e.nextElement(); + for(Enumeration e= children.elements(); e.hasMoreElements(); ) { + TreeNode node= e.nextElement(); if (node.match(theValue)) return node; } return null; } - final private boolean match(long value) { + private boolean match(long value) { return (nodeValue == value) ? true : false; } - private Vector children= new Vector(); - private Vector agents= new Vector(); + private Vector children= new Vector<>(); + private Vector agents= new Vector<>(); private long nodeValue; private SnmpMibAgent agent; private TreeNode parent; diff --git a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpRequestHandler.java b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpRequestHandler.java index f56b189b48ec429228083dc022ffce7c2e69dc36..0b60e8022706e9d52fd2eb89a15d00566a9dead4 100644 --- a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpRequestHandler.java +++ b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpRequestHandler.java @@ -71,9 +71,9 @@ import com.sun.jmx.snmp.InetAddressAcl; class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { - private transient DatagramSocket socket = null ; - private transient DatagramPacket packet = null ; - private transient Vector mibs = null ; + private transient DatagramSocket socket = null ; + private transient DatagramPacket packet = null ; + private transient Vector mibs = null ; /** * Contains the list of sub-requests associated to the current request. @@ -85,7 +85,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { */ private transient SnmpMibTree root; - private transient Object ipacl = null ; + private transient InetAddressAcl ipacl = null ; private transient SnmpPduFactory pduFactory = null ; private transient SnmpUserDataFactory userDataFactory = null ; private transient SnmpAdaptorServer adaptor = null; @@ -94,7 +94,8 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { */ public SnmpRequestHandler(SnmpAdaptorServer server, int id, DatagramSocket s, DatagramPacket p, - SnmpMibTree tree, Vector m, Object a, + SnmpMibTree tree, Vector m, + InetAddressAcl a, SnmpPduFactory factory, SnmpUserDataFactory dataFactory, MBeanServer f, ObjectName n) @@ -108,8 +109,8 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { socket = s; packet = p; root= tree; - mibs = (Vector) m.clone(); - subs= new Hashtable(mibs.size()); + mibs = new Vector<>(m); + subs= new Hashtable<>(mibs.size()); ipacl = a; pduFactory = factory ; userDataFactory = dataFactory ; @@ -121,6 +122,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { * back to the client. * Note: we overwrite 'packet' with the response bytes. */ + @Override public void doRun() { // Trace the input packet @@ -243,7 +245,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { // Transform the request message into a request pdu // - SnmpPduPacket reqPdu = null ; + SnmpPduPacket reqPdu; Object userData = null; try { reqPdu = (SnmpPduPacket)pduFactory.decodeSnmpPdu(reqMsg) ; @@ -306,7 +308,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "makeResponseMessage", "fail on element" + pos); } - int old= 0; + int old; while (true) { try { respPdu = reduceResponsePdu(reqPdu, respPdu, pos) ; @@ -580,20 +582,18 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { Object userData) { int errorStatus = SnmpDefinitions.snmpRspNoError ; - int nbSubRequest= subs.size(); - int i=0; + int i; // If it's a set request, we must first check any varBind // if (req.type == pduSetRequestPdu) { i=0; - for(Enumeration e= subs.elements(); e.hasMoreElements() ; i++) { + for(Enumeration e= subs.elements(); e.hasMoreElements() ; i++) { // Indicate to the sub request that a check must be invoked ... // OK we should have defined out own tag for that ! // - SnmpSubRequestHandler sub= (SnmpSubRequestHandler) - e.nextElement(); + SnmpSubRequestHandler sub= e.nextElement(); sub.setUserData(userData); sub.type= pduWalkRequest; @@ -618,8 +618,8 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { // Let's start the sub-requests. // i=0; - for(Enumeration e= subs.elements(); e.hasMoreElements() ;i++) { - SnmpSubRequestHandler sub= (SnmpSubRequestHandler) e.nextElement(); + for(Enumeration e= subs.elements(); e.hasMoreElements() ;i++) { + SnmpSubRequestHandler sub= e.nextElement(); /* NPCTE fix for bugId 4492741, esc 0, 16-August 2001 */ sub.setUserData(userData); /* end of NPCTE fix for bugId 4492741 */ @@ -650,7 +650,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { private SnmpPduPacket turboProcessingGetSet(SnmpPduRequest req, Object userData) { - int errorStatus = SnmpDefinitions.snmpRspNoError ; + int errorStatus; SnmpSubRequestHandler sub = subs.elements().nextElement(); sub.setUserData(userData); @@ -707,7 +707,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req, Object userData) { - SnmpVarBind[] respVarBindList = null ; + SnmpVarBind[] respVarBindList; // RFC 1905, Section 4.2.3, p14 int L = req.varBindList.length ; @@ -761,7 +761,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { */ private boolean checkPduType(SnmpPduPacket pdu) { - boolean result = true ; + boolean result; switch(pdu.type) { @@ -798,8 +798,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { // if (ipacl != null) { if (pdu.type == SnmpDefinitions.pduSetRequestPdu) { - if (!((InetAddressAcl)ipacl). - checkWritePermission(pdu.address, community)) { + if (!ipacl.checkWritePermission(pdu.address, community)) { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "checkAcl", "sender is " + pdu.address + @@ -820,7 +819,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { } } else { - if (!((InetAddressAcl)ipacl).checkReadPermission(pdu.address, community)) { + if (!ipacl.checkReadPermission(pdu.address, community)) { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "checkAcl", "sender is " + pdu.address + @@ -854,7 +853,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { if (response != null) { SnmpAdaptorServer snmpServer = (SnmpAdaptorServer)adaptorServer ; snmpServer.incSnmpInBadCommunityUses(1) ; - if (((InetAddressAcl)ipacl).checkCommunity(community) == false) + if (ipacl.checkCommunity(community) == false) snmpServer.incSnmpInBadCommunityNames(1) ; } @@ -873,7 +872,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { result.port = reqPdu.port ; result.version = reqPdu.version ; result.community = reqPdu.community ; - result.type = result.pduGetResponsePdu ; + result.type = SnmpPduRequest.pduGetResponsePdu ; result.requestId = reqPdu.requestId ; result.errorStatus = SnmpDefinitions.snmpRspNoError ; result.errorIndex = 0 ; @@ -904,7 +903,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { private SnmpMessage newTooBigMessage(SnmpMessage reqMsg) throws SnmpTooBigException { SnmpMessage result = null ; - SnmpPduPacket reqPdu = null ; + SnmpPduPacket reqPdu; try { reqPdu = (SnmpPduPacket)pduFactory.decodeSnmpPdu(reqMsg) ; @@ -941,7 +940,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { // Reduction can be attempted only on bulk response // - if (req.type != req.pduGetBulkRequestPdu) { + if (req.type != SnmpPduPacket.pduGetBulkRequestPdu) { if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "reduceResponsePdu", "cannot remove anything"); @@ -961,7 +960,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { // * when it is 0 (in fact, acceptedVbCount is not available), // we split the varbindlist by 2. // - int vbCount = resp.varBindList.length ; + int vbCount; if (acceptedVbCount >= 3) vbCount = Math.min(acceptedVbCount - 1, resp.varBindList.length) ; else if (acceptedVbCount == 1) @@ -998,7 +997,7 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { private void splitRequest(SnmpPduRequest req) { int nbAgents= mibs.size(); - SnmpMibAgent agent= (SnmpMibAgent) mibs.firstElement(); + SnmpMibAgent agent = mibs.firstElement(); if (nbAgents == 1) { // Take all the oids contained in the request and // @@ -1010,8 +1009,8 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { // to all agents // if (req.type == pduGetNextRequestPdu) { - for(Enumeration e= mibs.elements(); e.hasMoreElements(); ) { - SnmpMibAgent ag= (SnmpMibAgent) e.nextElement(); + for(Enumeration e= mibs.elements(); e.hasMoreElements(); ) { + final SnmpMibAgent ag= e.nextElement(); subs.put(ag, new SnmpSubNextRequestHandler(adaptor, ag, req)); } return; @@ -1047,8 +1046,8 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { int R) { // Send the getBulk to all agents // - for(Enumeration e= mibs.elements(); e.hasMoreElements(); ) { - SnmpMibAgent agent = (SnmpMibAgent) e.nextElement(); + for(Enumeration e= mibs.elements(); e.hasMoreElements(); ) { + final SnmpMibAgent agent = e.nextElement(); if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, @@ -1064,7 +1063,6 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { maxRepetitions, R)); } - return; } private SnmpPduPacket mergeResponses(SnmpPduRequest req) { @@ -1078,8 +1076,8 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { // Go through the list of subrequests and concatenate. // Hopefully, by now all the sub-requests should be finished // - for(Enumeration e= subs.elements(); e.hasMoreElements();) { - SnmpSubRequestHandler sub= (SnmpSubRequestHandler) e.nextElement(); + for(Enumeration e= subs.elements(); e.hasMoreElements();) { + SnmpSubRequestHandler sub= e.nextElement(); sub.updateResult(result); } return newValidResponsePdu(req,result); @@ -1092,8 +1090,8 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { // Go through the list of subrequests and concatenate. // Hopefully, by now all the sub-requests should be finished // - for(Enumeration e= subs.elements(); e.hasMoreElements();) { - SnmpSubRequestHandler sub= (SnmpSubRequestHandler) e.nextElement(); + for(Enumeration e= subs.elements(); e.hasMoreElements();) { + SnmpSubRequestHandler sub= e.nextElement(); sub.updateResult(result); } @@ -1127,19 +1125,21 @@ class SnmpRequestHandler extends ClientHandler implements SnmpDefinitions { // Go through the list of subrequests and concatenate. // Hopefully, by now all the sub-requests should be finished // - for(Enumeration e= subs.elements(); e.hasMoreElements();) { - SnmpSubRequestHandler sub= (SnmpSubRequestHandler) e.nextElement(); + for(Enumeration e= subs.elements(); e.hasMoreElements();) { + SnmpSubRequestHandler sub= e.nextElement(); sub.updateResult(result); } return result; } + @Override protected String makeDebugTag() { return "SnmpRequestHandler[" + adaptorServer.getProtocol() + ":" + adaptorServer.getPort() + "]"; } + @Override Thread createThread(Runnable r) { return null; } diff --git a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpSubBulkRequestHandler.java b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpSubBulkRequestHandler.java index f662e374fbede22f3b40f7fb5238876e42d6888a..2754975082f35a3a226e417606ce94d829615cbd 100644 --- a/src/share/classes/com/sun/jmx/snmp/daemon/SnmpSubBulkRequestHandler.java +++ b/src/share/classes/com/sun/jmx/snmp/daemon/SnmpSubBulkRequestHandler.java @@ -31,7 +31,6 @@ package com.sun.jmx.snmp.daemon; // java import // import java.util.Enumeration; -import java.util.Vector; import java.util.logging.Level; // jmx imports // @@ -46,9 +45,6 @@ import com.sun.jmx.snmp.SnmpEngine; // import static com.sun.jmx.defaults.JmxProperties.SNMP_ADAPTOR_LOGGER; import com.sun.jmx.snmp.agent.SnmpMibAgent; -import com.sun.jmx.snmp.agent.SnmpMibRequest; -import com.sun.jmx.snmp.ThreadContext; -import com.sun.jmx.snmp.daemon.SnmpAdaptorServer; import com.sun.jmx.snmp.internal.SnmpIncomingRequest; import com.sun.jmx.snmp.ThreadContext; @@ -85,6 +81,7 @@ class SnmpSubBulkRequestHandler extends SnmpSubRequestHandler { init(server, req, nonRepeat, maxRepeat, R); } + @Override public void run() { size= varBind.size(); @@ -259,11 +256,12 @@ class SnmpSubBulkRequestHandler extends SnmpSubRequestHandler { * successful. As such the method getErrorIndex or getErrorStatus should be * called. */ + @Override protected void updateResult(SnmpVarBind[] result) { // we can assume that the run method is over ... // - final Enumeration e= varBind.elements(); + final Enumeration e= varBind.elements(); final int max= result.length; // First go through all the values once ... @@ -284,7 +282,7 @@ class SnmpSubBulkRequestHandler extends SnmpSubRequestHandler { continue; } - final SnmpVarBind element= (SnmpVarBind) e.nextElement(); + final SnmpVarBind element= e.nextElement(); if (element == null) continue; if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { @@ -309,7 +307,7 @@ class SnmpSubBulkRequestHandler extends SnmpSubRequestHandler { return; if (e.hasMoreElements() ==false) return; - final SnmpVarBind element= (SnmpVarBind) e.nextElement(); + final SnmpVarBind element= e.nextElement(); if (element == null) continue; if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) { diff --git a/src/share/classes/com/sun/jmx/snmp/defaults/SnmpProperties.java b/src/share/classes/com/sun/jmx/snmp/defaults/SnmpProperties.java index 675c15b32aa8be4fb642f754d4c28d0820e8dee4..f17c68208d55c7d82e86010bc58cf78143fbf497 100644 --- a/src/share/classes/com/sun/jmx/snmp/defaults/SnmpProperties.java +++ b/src/share/classes/com/sun/jmx/snmp/defaults/SnmpProperties.java @@ -60,7 +60,7 @@ public class SnmpProperties { InputStream is = new FileInputStream(file); props.load(is); is.close(); - for (final Enumeration e = props.keys(); e.hasMoreElements() ; ) { + for (final Enumeration e = props.keys(); e.hasMoreElements() ; ) { final String key = (String) e.nextElement(); System.setProperty(key,props.getProperty(key)); } diff --git a/src/share/classes/com/sun/jmx/snmp/tasks/ThreadService.java b/src/share/classes/com/sun/jmx/snmp/tasks/ThreadService.java index b1c053448bdfada6c699544162c254267a16a1b6..6b45ee36072b5e241a2f620ec40eb0d85b46413e 100644 --- a/src/share/classes/com/sun/jmx/snmp/tasks/ThreadService.java +++ b/src/share/classes/com/sun/jmx/snmp/tasks/ThreadService.java @@ -199,7 +199,7 @@ public class ThreadService implements TaskServer { // re-init this.setPriority(priority); - this.interrupted(); + Thread.interrupted(); this.setContextClassLoader(cloader); } } diff --git a/src/share/classes/com/sun/net/ssl/SSLPermission.java b/src/share/classes/com/sun/net/ssl/SSLPermission.java index 101dcc7af6c377f15a3e0dad0954435e949d8dfa..2bf9233051bca9c753fd163fda83775cdfe28264 100644 --- a/src/share/classes/com/sun/net/ssl/SSLPermission.java +++ b/src/share/classes/com/sun/net/ssl/SSLPermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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 @@ -46,8 +46,8 @@ import java.lang.SecurityManager; * convention follows the hierarchical property naming convention. * Also, an asterisk * may appear at the end of the name, following a ".", or by itself, to - * signify a wildcard match. For example: "foo.*" or "*" is valid, - * "*foo" or "a*b" is not valid. + * signify a wildcard match. For example: "foo.*" and "*" signify a wildcard + * match, while "*foo" and "a*b" do not. *

* The following table lists all the possible SSLPermission target names, * and for each provides a description of what the permission allows diff --git a/src/share/classes/java/lang/Class.java b/src/share/classes/java/lang/Class.java index 2da316afbd3f22ca5d62dbd329baef436e2a08f4..17665ed7b28b55e643f549210da1ddd5ae0a4290 100644 --- a/src/share/classes/java/lang/Class.java +++ b/src/share/classes/java/lang/Class.java @@ -48,6 +48,7 @@ import java.util.List; import java.util.Set; import java.util.Map; import java.util.HashMap; +import java.util.Objects; import sun.misc.Unsafe; import sun.reflect.ConstantPool; import sun.reflect.Reflection; @@ -3044,34 +3045,62 @@ public final * @throws NullPointerException {@inheritDoc} * @since 1.5 */ - @SuppressWarnings("unchecked") public A getAnnotation(Class annotationClass) { - if (annotationClass == null) - throw new NullPointerException(); + Objects.requireNonNull(annotationClass); initAnnotationsIfNecessary(); - return (A) annotations.get(annotationClass); + return AnnotationSupport.getOneAnnotation(annotations, annotationClass); } /** * @throws NullPointerException {@inheritDoc} * @since 1.5 */ - public boolean isAnnotationPresent( - Class annotationClass) { - if (annotationClass == null) - throw new NullPointerException(); + public boolean isAnnotationPresent(Class annotationClass) { + Objects.requireNonNull(annotationClass); return getAnnotation(annotationClass) != null; } + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public A[] getAnnotations(Class annotationClass) { + Objects.requireNonNull(annotationClass); + + initAnnotationsIfNecessary(); + return AnnotationSupport.getMultipleAnnotations(annotations, annotationClass); + } /** * @since 1.5 */ public Annotation[] getAnnotations() { initAnnotationsIfNecessary(); - return AnnotationParser.toArray(annotations); + return AnnotationSupport.unpackToArray(annotations); + } + + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public A getDeclaredAnnotation(Class annotationClass) { + Objects.requireNonNull(annotationClass); + + initAnnotationsIfNecessary(); + return AnnotationSupport.getOneAnnotation(declaredAnnotations, annotationClass); + } + + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public A[] getDeclaredAnnotations(Class annotationClass) { + Objects.requireNonNull(annotationClass); + + initAnnotationsIfNecessary(); + return AnnotationSupport.getMultipleAnnotations(declaredAnnotations, annotationClass); } /** @@ -3079,7 +3108,17 @@ public final */ public Annotation[] getDeclaredAnnotations() { initAnnotationsIfNecessary(); - return AnnotationParser.toArray(declaredAnnotations); + return AnnotationSupport.unpackToArray(declaredAnnotations); + } + + /** Returns one "directly" present annotation or null */ + A getDirectDeclaredAnnotation(Class annotationClass) { + Objects.requireNonNull(annotationClass); + + initAnnotationsIfNecessary(); + @SuppressWarnings("unchecked") // TODO check safe + A ret = (A)declaredAnnotations.get(annotationClass); + return ret; } // Annotations cache diff --git a/src/share/classes/java/lang/Package.java b/src/share/classes/java/lang/Package.java index f1f31b7acbe6f5abcef4ae08bd58d50ecd256cd7..744a292d6ee18641ee60265cba0415958d782203 100644 --- a/src/share/classes/java/lang/Package.java +++ b/src/share/classes/java/lang/Package.java @@ -394,6 +394,14 @@ public class Package implements java.lang.reflect.AnnotatedElement { return getPackageInfo().isAnnotationPresent(annotationClass); } + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public A[] getAnnotations(Class annotationClass) { + return getPackageInfo().getAnnotations(annotationClass); + } + /** * @since 1.5 */ @@ -401,6 +409,22 @@ public class Package implements java.lang.reflect.AnnotatedElement { return getPackageInfo().getAnnotations(); } + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public A getDeclaredAnnotation(Class annotationClass) { + return getPackageInfo().getDeclaredAnnotation(annotationClass); + } + + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public A[] getDeclaredAnnotations(Class annotationClass) { + return getPackageInfo().getDeclaredAnnotations(annotationClass); + } + /** * @since 1.5 */ diff --git a/src/share/classes/java/lang/RuntimePermission.java b/src/share/classes/java/lang/RuntimePermission.java index eeef0b5244b152850a9f07be27c27ccb4c8cb420..6dcbc275e9e4f96631684499de52fa3138847247 100644 --- a/src/share/classes/java/lang/RuntimePermission.java +++ b/src/share/classes/java/lang/RuntimePermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 @@ -41,8 +41,8 @@ import java.util.StringTokenizer; * naming convention follows the hierarchical property naming convention. * Also, an asterisk * may appear at the end of the name, following a ".", or by itself, to - * signify a wildcard match. For example: "loadLibrary.*" or "*" is valid, - * "*loadLibrary" or "a*b" is not valid. + * signify a wildcard match. For example: "loadLibrary.*" and "*" signify a + * wildcard match, while "*loadLibrary" and "a*b" do not. *

* The following table lists all the possible RuntimePermission target names, * and for each provides a description of what the permission allows diff --git a/src/share/classes/java/lang/System.java b/src/share/classes/java/lang/System.java index fde6aa36e6c0aa112345fcaa505da3f59a63561e..a6206e603915188d74907d41f8e50fec65308b8e 100644 --- a/src/share/classes/java/lang/System.java +++ b/src/share/classes/java/lang/System.java @@ -25,6 +25,7 @@ package java.lang; import java.io.*; +import java.lang.annotation.Annotation; import java.util.Properties; import java.util.PropertyPermission; import java.util.StringTokenizer; @@ -1195,6 +1196,9 @@ public final class System { public AnnotationType getAnnotationType(Class klass) { return klass.getAnnotationType(); } + public A getDirectDeclaredAnnotation(Class klass, Class anno) { + return klass.getDirectDeclaredAnnotation(anno); + } public > E[] getEnumConstantsShared(Class klass) { return klass.getEnumConstantsShared(); diff --git a/src/share/classes/java/lang/annotation/ContainedBy.java b/src/share/classes/java/lang/annotation/ContainedBy.java index 2449519d9ca7a2dc887195a1972d4a6df7426e14..4f0328637916c748ea6bda3cb996498a8781c1a7 100644 --- a/src/share/classes/java/lang/annotation/ContainedBy.java +++ b/src/share/classes/java/lang/annotation/ContainedBy.java @@ -26,10 +26,35 @@ package java.lang.annotation; /** - * A meta-annotation to indicate which annotation type should be used - * as a container for repeated values of the annotation type modified - * by the {@code ContainedBy} annotation. + * The annotation type {@code java.lang.annotation.ContainedBy} is + * used to indicate that the annotation type whose declaration it + * (meta-)annotates is repeatable. The value of + * {@code @ContainedBy} indicates the containing annotation + * type for the repeatable annotation type. * + *

The pair of annotation types {@code @ContainedBy} and + * {@link java.lang.annotation.ContainerFor @ContainerFor} are used to + * indicate that annotation types are repeatable. Specifically: + * + *

+ * + *

+ * An inconsistent pair of {@code @ContainedBy} and + * {@code @ContainerFor} annotations on a repeatable annotation type + * and its containing annotation type (JLS 9.6) will lead to + * compile-time errors and runtime exceptions when using reflection to + * read annotations of a repeatable type. + * + * @see java.lang.annotation.ContainerFor * @since 1.8 * @jls 9.6 Annotation Types * @jls 9.7 Annotations @@ -39,8 +64,8 @@ package java.lang.annotation; @Target(ElementType.ANNOTATION_TYPE) public @interface ContainedBy { /** - * The annotation type to use to store repeated values of another - * annotation. + * Indicates the containing annotation type for the + * repeatable annotation type. */ Class value(); } diff --git a/src/share/classes/java/lang/annotation/ContainerFor.java b/src/share/classes/java/lang/annotation/ContainerFor.java index dd13bf99fcb80b8bae01d38c6f8de9761bfe86cc..62f3446e021ff476d3e79a4b41fd4a5b6ba9b482 100644 --- a/src/share/classes/java/lang/annotation/ContainerFor.java +++ b/src/share/classes/java/lang/annotation/ContainerFor.java @@ -26,10 +26,36 @@ package java.lang.annotation; /** - * Indicates that an annotation type is a container for repeated - * instances of annotations of the type of the value of the - * {@code ContainerFor}'s value element. + * The annotation type {@code java.lang.annotation.ContainerFor} is + * used to indicate that the annotation type whose declaration it + * (meta-)annotates is a containing annotation type. The + * value of {@code @ContainerFor} indicates the repeatable + * annotation type for the containing annotation type. * + *

The pair of annotation types {@link + * java.lang.annotation.ContainedBy @ContainedBy} and + * {@code @ContainerFor} are used to indicate that annotation types + * are repeatable. Specifically: + * + *

    + *
  • The annotation type {@code @ContainedBy} is used on the + * declaration of a repeatable annotation type (JLS 9.6) to indicate + * its containing annotation type. + * + *
  • The annotation type {@code @ContainerFor} is used on the + * declaration of a containing annotation type (JLS 9.6) to indicate + * the repeatable annotation type for which it serves as the + * containing annotation type. + *
+ * + *

+ * An inconsistent pair of {@code @ContainedBy} and + * {@code @ContainerFor} annotations on a repeatable annotation type + * and its containing annotation type (JLS 9.6) will lead to + * compile-time errors and runtime exceptions when using reflection to + * read annotations of a repeatable type. + * + * @see java.lang.annotation.ContainedBy * @since 1.8 * @jls 9.6 Annotation Types * @jls 9.7 Annotations @@ -38,9 +64,10 @@ package java.lang.annotation; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) public @interface ContainerFor { + /** - * The repeating annotation type that the annotation type - * annotated with this annotation is a container for. + * Indicates the repeatable annotation type for the containing + * annotation type. */ Class value(); } diff --git a/src/share/classes/java/lang/annotation/InvalidContainerAnnotationError.java b/src/share/classes/java/lang/annotation/InvalidContainerAnnotationError.java new file mode 100644 index 0000000000000000000000000000000000000000..b24e3034179ae7c417c42f3586a11e6e87454d6f --- /dev/null +++ b/src/share/classes/java/lang/annotation/InvalidContainerAnnotationError.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.lang.annotation; + +import java.util.Objects; + +/** + * Thrown to indicate that an annotation type whose declaration is + * (meta-)annotated with a {@link ContainerFor} annotation is not, in + * fact, the containing annotation type of the type named by {@link + * ContainerFor}. + * + * @see java.lang.reflect.AnnotatedElement + * @since 1.8 + * @jls 9.6 Annotation Types + * @jls 9.7 Annotations + */ +public class InvalidContainerAnnotationError extends AnnotationFormatError { + private static final long serialVersionUID = 5023L; + + /** + * The instance of the erroneous container. + */ + private transient Annotation container; + + /** + * The type of the annotation that should be contained in the + * container. + */ + private transient Class annotationType; + + /** + * Constructs a new InvalidContainerAnnotationError with the + * specified detail message. + * + * @param message the detail message. + */ + public InvalidContainerAnnotationError(String message) { + super(message); + } + + /** + * Constructs a new InvalidContainerAnnotationError with the specified + * detail message and cause. Note that the detail message associated + * with {@code cause} is not automatically incorporated in + * this error's detail message. + * + * @param message the detail message + * @param cause the cause, may be {@code null} + */ + public InvalidContainerAnnotationError(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructs a new InvalidContainerAnnotationError with the + * specified cause and a detail message of {@code (cause == null ? + * null : cause.toString())} (which typically contains the class + * and detail message of {@code cause}). + * + * @param cause the cause, may be {@code null} + */ + public InvalidContainerAnnotationError(Throwable cause) { + super(cause); + } + + /** + * Constructs InvalidContainerAnnotationError for the specified + * container instance and contained annotation type. + * + * @param message the detail message + * @param cause the cause, may be {@code null} + * @param container the erroneous container instance, may be + * {@code null} + * @param annotationType the annotation type intended to be + * contained, may be {@code null} + */ + public InvalidContainerAnnotationError(String message, + Throwable cause, + Annotation container, + Class annotationType) { + super(message, cause); + this.container = container; + this.annotationType = annotationType; + } + + /** + * Returns the erroneous container. + * + * @return the erroneous container, may return {@code null} + */ + public Annotation getContainer() { + return container; + } + + /** + * Returns the annotation type intended to be contained. Returns + * {@code null} if the annotation type intended to be contained + * could not be determined. + * + * @return the annotation type intended to be contained, or {@code + * null} if unknown + */ + public Class getAnnotationType() { + return annotationType; + } +} diff --git a/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java b/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java index d41a62d395269a8f21b567e68ed0e2cc919898a9..9e786e8f5b980af59ed529898aa976b6dd5581f5 100644 --- a/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java +++ b/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java @@ -30,8 +30,7 @@ import java.io.IOException; import java.lang.reflect.Method; import java.security.ProtectionDomain; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; +import sun.util.logging.PlatformLogger; import jdk.internal.org.objectweb.asm.*; import static jdk.internal.org.objectweb.asm.Opcodes.*; import sun.misc.Unsafe; @@ -192,7 +191,7 @@ import sun.misc.Unsafe; try (FileOutputStream fos = new FileOutputStream(lambdaClassName.replace('/', '.') + ".class")) { fos.write(classBytes); } catch (IOException ex) { - Logger.getLogger(InnerClassLambdaMetafactory.class.getName()).log(Level.SEVERE, null, ex); + PlatformLogger.getLogger(InnerClassLambdaMetafactory.class.getName()).severe(ex.getMessage(), ex); } } diff --git a/src/share/classes/java/lang/invoke/MethodHandleNatives.java b/src/share/classes/java/lang/invoke/MethodHandleNatives.java index 06a9ba20e697e60d573f4deaef9f424fc1659a11..fcc928a327d874e86ce575da71745df1eebaf47b 100644 --- a/src/share/classes/java/lang/invoke/MethodHandleNatives.java +++ b/src/share/classes/java/lang/invoke/MethodHandleNatives.java @@ -448,7 +448,7 @@ class MethodHandleNatives { case "getDriver": case "getDrivers": case "deregisterDriver": - return defc == java.sql.DriverManager.class; + return defc == getClass("java.sql.DriverManager"); case "newUpdater": if (defc == java.util.concurrent.atomic.AtomicIntegerFieldUpdater.class) return true; if (defc == java.util.concurrent.atomic.AtomicLongFieldUpdater.class) return true; @@ -482,4 +482,14 @@ class MethodHandleNatives { } return false; } + + // avoid static dependency to a class in other modules + private static Class getClass(String cn) { + try { + return Class.forName(cn, false, + MethodHandleNatives.class.getClassLoader()); + } catch (ClassNotFoundException e) { + throw new InternalError(e); + } + } } diff --git a/src/share/classes/java/lang/reflect/AccessibleObject.java b/src/share/classes/java/lang/reflect/AccessibleObject.java index adbf8dbe76be1aff2f02fea9cf3a478056e6175d..baaec298a8555f4ee160a0d9d87af87667783866 100644 --- a/src/share/classes/java/lang/reflect/AccessibleObject.java +++ b/src/share/classes/java/lang/reflect/AccessibleObject.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 @@ -184,11 +184,18 @@ public class AccessibleObject implements AnnotatedElement { * @throws NullPointerException {@inheritDoc} * @since 1.5 */ - public boolean isAnnotationPresent( - Class annotationClass) { + public boolean isAnnotationPresent(Class annotationClass) { return getAnnotation(annotationClass) != null; } + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public T[] getAnnotations(Class annotationClass) { + throw new AssertionError("All subclasses should override this method"); + } + /** * @since 1.5 */ @@ -196,6 +203,28 @@ public class AccessibleObject implements AnnotatedElement { return getDeclaredAnnotations(); } + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public T getDeclaredAnnotation(Class annotationClass) { + // Only annotations on classes are inherited, for all other + // objects getDeclaredAnnotation is the same as + // getAnnotation. + return getAnnotation(annotationClass); + } + + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public T[] getDeclaredAnnotations(Class annotationClass) { + // Only annotations on classes are inherited, for all other + // objects getDeclaredAnnotations is the same as + // getAnnotations. + return getAnnotations(annotationClass); + } + /** * @since 1.5 */ diff --git a/src/share/classes/java/lang/reflect/AnnotatedElement.java b/src/share/classes/java/lang/reflect/AnnotatedElement.java index dc24483167661ad1f90b14eb36bf3775302b34ba..58a07350f363951307c9b8b8793250488893249c 100644 --- a/src/share/classes/java/lang/reflect/AnnotatedElement.java +++ b/src/share/classes/java/lang/reflect/AnnotatedElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. 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 @@ -45,6 +45,11 @@ import java.lang.annotation.Annotation; * a {@link EnumConstantNotPresentException} if the enum constant in the * annotation is no longer present in the enum type. * + *

Attempting to read annotations of a repeatable annotation type T + * that are contained in an annotation whose type is not, in fact, the + * containing annotation type of T will result in an + * InvalidContainerAnnotationError. + * *

Finally, Attempting to read a member whose definition has evolved * incompatibly will result in a {@link * java.lang.annotation.AnnotationTypeMismatchException} or an @@ -55,6 +60,7 @@ import java.lang.annotation.Annotation; * @see java.lang.annotation.AnnotationFormatError * @see java.lang.annotation.AnnotationTypeMismatchException * @see java.lang.annotation.IncompleteAnnotationException + * @see java.lang.annotation.InvalidContainerAnnotationError * @since 1.5 * @author Josh Bloch */ @@ -86,6 +92,23 @@ public interface AnnotatedElement { */ T getAnnotation(Class annotationClass); + /** + * Returns an array of all this element's annotations for the + * specified type if one or more of such annotation is present, + * else an array of length zero. + * + * The caller of this method is free to modify the returned array; + * it will have no effect on the arrays returned to other callers. + * + * @param annotationClass the Class object corresponding to the + * annotation type + * @return all this element's annotations for the specified annotation type if + * present on this element, else an array of length zero + * @throws NullPointerException if the given annotation class is null + * @since 1.8 + */ + T[] getAnnotations(Class annotationClass); + /** * Returns all annotations present on this element. (Returns an array * of length zero if this element has no annotations.) The caller of @@ -97,13 +120,49 @@ public interface AnnotatedElement { */ Annotation[] getAnnotations(); + /** + * Returns this element's annotation for the specified type if + * such an annotation is present, else null. + * + * This method ignores inherited annotations. (Returns null if no + * annotations are directly present on this element.) + * + * @param annotationClass the Class object corresponding to the + * annotation type + * @return this element's annotation for the specified annotation type if + * present on this element, else null + * @throws NullPointerException if the given annotation class is null + * @since 1.8 + */ + T getDeclaredAnnotation(Class annotationClass); + + /** + * Returns an array of all this element's annotations for the + * specified type if one or more of such annotation is directly + * present, else an array of length zero. + * + * This method ignores inherited annotations. (Returns + * an array of length zero if no annotations are directly present + * on this element.) The caller of this method is free to modify + * the returned array; it will have no effect on the arrays + * returned to other callers. + * + * @param annotationClass the Class object corresponding to the + * annotation type + * @return all this element's annotations for the specified annotation type if + * present on this element, else an array of length zero + * @throws NullPointerException if the given annotation class is null + * @since 1.8 + */ + T[] getDeclaredAnnotations(Class annotationClass); + /** * Returns all annotations that are directly present on this - * element. Unlike the other methods in this interface, this method - * ignores inherited annotations. (Returns an array of length zero if - * no annotations are directly present on this element.) The caller of - * this method is free to modify the returned array; it will have no - * effect on the arrays returned to other callers. + * element. This method ignores inherited annotations. (Returns + * an array of length zero if no annotations are directly present + * on this element.) The caller of this method is free to modify + * the returned array; it will have no effect on the arrays + * returned to other callers. * * @return All annotations directly present on this element * @since 1.5 diff --git a/src/share/classes/java/lang/reflect/Executable.java b/src/share/classes/java/lang/reflect/Executable.java index bec1a72a1e7a94cd995d08a9870d812c91e6e840..6948d96e8a0077a0b8d423cb0c3a9db364096002 100644 --- a/src/share/classes/java/lang/reflect/Executable.java +++ b/src/share/classes/java/lang/reflect/Executable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, Oracle and/or its affiliates. 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 @@ -26,8 +26,11 @@ package java.lang.reflect; import java.lang.annotation.*; +import java.util.Collections; import java.util.Map; +import java.util.Objects; import sun.reflect.annotation.AnnotationParser; +import sun.reflect.annotation.AnnotationSupport; import sun.reflect.generics.repository.ConstructorRepository; /** @@ -363,19 +366,28 @@ public abstract class Executable extends AccessibleObject * {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - @SuppressWarnings("unchecked") public T getAnnotation(Class annotationClass) { - if (annotationClass == null) - throw new NullPointerException(); + Objects.requireNonNull(annotationClass); - return (T) declaredAnnotations().get(annotationClass); + return AnnotationSupport.getOneAnnotation(declaredAnnotations(), annotationClass); + } + + /** + * {@inheritDoc} + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public T[] getAnnotations(Class annotationClass) { + Objects.requireNonNull(annotationClass); + + return AnnotationSupport.getMultipleAnnotations(declaredAnnotations(), annotationClass); } /** * {@inheritDoc} */ public Annotation[] getDeclaredAnnotations() { - return AnnotationParser.toArray(declaredAnnotations()); + return AnnotationSupport.unpackToArray(declaredAnnotations()); } private transient Map, Annotation> declaredAnnotations; diff --git a/src/share/classes/java/lang/reflect/Field.java b/src/share/classes/java/lang/reflect/Field.java index 5e24f228f841a64962dcb3248cdac5208bbb3754..ded3689c419672424a126b483ee0c4fb96dd4e3a 100644 --- a/src/share/classes/java/lang/reflect/Field.java +++ b/src/share/classes/java/lang/reflect/Field.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. 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,7 +33,9 @@ import sun.reflect.generics.factory.GenericsFactory; import sun.reflect.generics.scope.ClassScope; import java.lang.annotation.Annotation; import java.util.Map; +import java.util.Objects; import sun.reflect.annotation.AnnotationParser; +import sun.reflect.annotation.AnnotationSupport; /** @@ -1012,19 +1014,28 @@ class Field extends AccessibleObject implements Member { * @throws NullPointerException {@inheritDoc} * @since 1.5 */ - @SuppressWarnings("unchecked") public T getAnnotation(Class annotationClass) { - if (annotationClass == null) - throw new NullPointerException(); + Objects.requireNonNull(annotationClass); - return (T) declaredAnnotations().get(annotationClass); + return AnnotationSupport.getOneAnnotation(declaredAnnotations(), annotationClass); } /** - * @since 1.5 + * {@inheritDoc} + * @throws NullPointerException {@inheritDoc} + * @since 1.8 + */ + public T[] getAnnotations(Class annotationClass) { + Objects.requireNonNull(annotationClass); + + return AnnotationSupport.getMultipleAnnotations(declaredAnnotations(), annotationClass); + } + + /** + * {@inheritDoc} */ public Annotation[] getDeclaredAnnotations() { - return AnnotationParser.toArray(declaredAnnotations()); + return AnnotationSupport.unpackToArray(declaredAnnotations()); } private transient Map, Annotation> declaredAnnotations; diff --git a/src/share/classes/java/net/AbstractPlainSocketImpl.java b/src/share/classes/java/net/AbstractPlainSocketImpl.java index b649b18ae907b654ceb25d750e8cb4d17d5a959e..be9ac509731725f43449e0392f5fc49d4b625ae7 100644 --- a/src/share/classes/java/net/AbstractPlainSocketImpl.java +++ b/src/share/classes/java/net/AbstractPlainSocketImpl.java @@ -411,14 +411,13 @@ abstract class AbstractPlainSocketImpl extends SocketImpl * Gets an InputStream for this socket. */ protected synchronized InputStream getInputStream() throws IOException { - if (isClosedOrPending()) { - throw new IOException("Socket Closed"); - } - if (shut_rd) { - throw new IOException("Socket input is shutdown"); - } - if (socketInputStream == null) { - socketInputStream = new SocketInputStream(this); + synchronized (fdLock) { + if (isClosedOrPending()) + throw new IOException("Socket Closed"); + if (shut_rd) + throw new IOException("Socket input is shutdown"); + if (socketInputStream == null) + socketInputStream = new SocketInputStream(this); } return socketInputStream; } @@ -431,14 +430,13 @@ abstract class AbstractPlainSocketImpl extends SocketImpl * Gets an OutputStream for this socket. */ protected synchronized OutputStream getOutputStream() throws IOException { - if (isClosedOrPending()) { - throw new IOException("Socket Closed"); - } - if (shut_wr) { - throw new IOException("Socket output is shutdown"); - } - if (socketOutputStream == null) { - socketOutputStream = new SocketOutputStream(this); + synchronized (fdLock) { + if (isClosedOrPending()) + throw new IOException("Socket Closed"); + if (shut_wr) + throw new IOException("Socket output is shutdown"); + if (socketOutputStream == null) + socketOutputStream = new SocketOutputStream(this); } return socketOutputStream; } diff --git a/src/share/classes/java/net/NetPermission.java b/src/share/classes/java/net/NetPermission.java index f22e04f717adddf27f7cd6a7adad8cac50342bf7..f11337e5b9ef76fa92474384e02a54239cdcb63c 100644 --- a/src/share/classes/java/net/NetPermission.java +++ b/src/share/classes/java/net/NetPermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 @@ -40,8 +40,8 @@ import java.util.StringTokenizer; * convention follows the hierarchical property naming convention. * Also, an asterisk * may appear at the end of the name, following a ".", or by itself, to - * signify a wildcard match. For example: "foo.*" or "*" is valid, - * "*foo" or "a*b" is not valid. + * signify a wildcard match. For example: "foo.*" and "*" signify a wildcard + * match, while "*foo" and "a*b" do not. *

* The following table lists all the possible NetPermission target names, * and for each provides a description of what the permission allows diff --git a/src/share/classes/java/security/BasicPermission.java b/src/share/classes/java/security/BasicPermission.java index 08fa34c8f57741425063ff8db2e547df8b5263e5..439eefa83f1948b0e45bda4f658b1b12d586a014 100644 --- a/src/share/classes/java/security/BasicPermission.java +++ b/src/share/classes/java/security/BasicPermission.java @@ -46,8 +46,8 @@ import java.io.IOException; * convention follows the hierarchical property naming convention. * An asterisk may appear by itself, or if immediately preceded by a "." * may appear at the end of the name, to signify a wildcard match. - * For example, "*" and "java.*" are valid, while "*java", "a*b", - * and "java*" are not valid. + * For example, "*" and "java.*" signify a wildcard match, while "*java", "a*b", + * and "java*" do not. *

* The action string (inherited from Permission) is unused. * Thus, BasicPermission is commonly used as the base class for diff --git a/src/share/classes/java/sql/SQLPermission.java b/src/share/classes/java/sql/SQLPermission.java index fe5bfc5a1a183a65a9c229c5c79789478b36bc1c..e2207db326282492008682de58345aca56178f8d 100644 --- a/src/share/classes/java/sql/SQLPermission.java +++ b/src/share/classes/java/sql/SQLPermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. 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 @@ -49,8 +49,8 @@ import java.security.*; * In addition, an asterisk * may appear at the end of the name, following a ".", or by itself, to * signify a wildcard match. For example: loadLibrary.* - * or * is valid, - * but *loadLibrary or a*b is not valid. + * and * signify a wildcard match, + * while *loadLibrary and a*b do not. *

* The following table lists all the possible SQLPermission target names. * The table gives a description of what the permission allows diff --git a/src/share/classes/java/util/Base64.java b/src/share/classes/java/util/Base64.java new file mode 100644 index 0000000000000000000000000000000000000000..db46a3e4b5a91a07dec9ee584143ecee21557c40 --- /dev/null +++ b/src/share/classes/java/util/Base64.java @@ -0,0 +1,1316 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.util; + +import java.io.FilterOutputStream; +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + +/** + * This class consists exclusively of static methods for obtaining + * encoders and decoders for the Base64 encoding scheme. The + * implementation of this class supports the following types of Base64 + * as specified in + * RFC 4648 and + * RFC 2045. + * + *

+ *

+ * + *

Unless otherwise noted, passing a {@code null} argument to a + * method of this class will cause a {@link java.lang.NullPointerException + * NullPointerException} to be thrown. + * + * @author Xueming Shen + * @since 1.8 + */ + +public class Base64 { + + private Base64() {} + + /** + * Returns a {@link Encoder} that encodes using the + * Basic type base64 encoding scheme. + * + * @return A Base64 encoder. + */ + public static Encoder getEncoder() { + return Encoder.RFC4648; + } + + /** + * Returns a {@link Encoder} that encodes using the + * URL and Filename safe type base64 + * encoding scheme. + * + * @return A Base64 encoder. + */ + public static Encoder getUrlEncoder() { + return Encoder.RFC4648_URLSAFE; + } + + /** + * Returns a {@link Encoder} that encodes using the + * MIME type base64 encoding scheme. + * + * @return A Base64 encoder. + */ + public static Encoder getMimeEncoder() { + return Encoder.RFC2045; + } + + /** + * Returns a {@link Encoder} that encodes using the + * MIME type base64 encoding scheme + * with specified line length and line separators. + * + * @param lineLength + * the length of each output line (rounded down to nearest multiple + * of 4). If {@code lineLength <= 0} the output will not be separated + * in lines + * @param lineSeparator + * the line separator for each output line + * + * @return A Base64 encoder. + * + * @throws IllegalArgumentException if {@code lineSeparator} includes any + * character of "The Base64 Alphabet" as specified in Table 1 of + * RFC 2045. + */ + public static Encoder getEncoder(int lineLength, byte[] lineSeparator) { + Objects.requireNonNull(lineSeparator); + int[] base64 = Decoder.fromBase64; + for (byte b : lineSeparator) { + if (base64[b & 0xff] != -1) + throw new IllegalArgumentException( + "Illegal base64 line separator character 0x" + Integer.toString(b, 16)); + } + return new Encoder(false, lineSeparator, lineLength >> 2 << 2); + } + + /** + * Returns a {@link Decoder} that decodes using the + * Basic type base64 encoding scheme. + * + * @return A Base64 decoder. + */ + public static Decoder getDecoder() { + return Decoder.RFC4648; + } + + /** + * Returns a {@link Decoder} that decodes using the + * URL and Filename safe type base64 + * encoding scheme. + * + * @return A Base64 decoder. + */ + public static Decoder getUrlDecoder() { + return Decoder.RFC4648_URLSAFE; + } + + /** + * Returns a {@link Decoder} that decodes using the + * MIME type base64 decoding scheme. + * + * @return A Base64 decoder. + */ + public static Decoder getMimeDecoder() { + return Decoder.RFC2045; + } + + /** + * This class implements an encoder for encoding byte data using + * the Base64 encoding scheme as specified in RFC 4648 and RFC 2045. + * + *

Instances of {@link Encoder} class are safe for use by + * multiple concurrent threads. + * + *

Unless otherwise noted, passing a {@code null} argument to + * a method of this class will cause a + * {@link java.lang.NullPointerException NullPointerException} to + * be thrown. + * + * @see Decoder + * @since 1.8 + */ + public static class Encoder { + + private final byte[] newline; + private final int linemax; + private final boolean isURL; + + private Encoder(boolean isURL, byte[] newline, int linemax) { + this.isURL = isURL; + this.newline = newline; + this.linemax = linemax; + } + + /** + * This array is a lookup table that translates 6-bit positive integer + * index values into their "Base64 Alphabet" equivalents as specified + * in "Table 1: The Base64 Alphabet" of RFC 2045 (and RFC 4648). + */ + private static final char[] toBase64 = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' + }; + + /** + * It's the lookup table for "URL and Filename safe Base64" as specified + * in Table 2 of the RFC 4648, with the '+' and '/' changed to '-' and + * '_'. This table is used when BASE64_URL is specified. + */ + private static final char[] toBase64URL = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' + }; + + private static final int MIMELINEMAX = 76; + private static final byte[] CRLF = new byte[] {'\r', '\n'}; + + static final Encoder RFC4648 = new Encoder(false, null, -1); + static final Encoder RFC4648_URLSAFE = new Encoder(true, null, -1); + static final Encoder RFC2045 = new Encoder(false, CRLF, MIMELINEMAX); + + /** + * Encodes all bytes from the specified byte array into a newly-allocated + * byte array using the {@link Base64} encoding scheme. The returned byte + * array is of the length of the resulting bytes. + * + * @param src + * the byte array to encode + * @return A newly-allocated byte array containing the resulting + * encoded bytes. + */ + public byte[] encode(byte[] src) { + int len = 4 * ((src.length + 2) / 3); // dst array size + if (linemax > 0) // line separators + len += (len - 1) / linemax * newline.length; + byte[] dst = new byte[len]; + int ret = encode0(src, 0, src.length, dst); + if (ret != dst.length) + return Arrays.copyOf(dst, ret); + return dst; + } + + /** + * Encodes all bytes from the specified byte array using the + * {@link Base64} encoding scheme, writing the resulting bytes to the + * given output byte array, starting at offset 0. + * + *

It is the responsibility of the invoker of this method to make + * sure the output byte array {@code dst} has enough space for encoding + * all bytes from the input byte array. No bytes will be written to the + * output byte array if the output byte array is not big enough. + * + * @param src + * the byte array to encode + * @param dst + * the output byte array + * @return The number of bytes written to the output byte array + * + * @throws IllegalArgumentException if {@code dst} does not have enough + * space for encoding all input bytes. + */ + public int encode(byte[] src, byte[] dst) { + int len = 4 * ((src.length + 2) / 3); // dst array size + if (linemax > 0) { + len += (len - 1) / linemax * newline.length; + } + if (dst.length < len) + throw new IllegalArgumentException( + "Output byte array is too small for encoding all input bytes"); + return encode0(src, 0, src.length, dst); + } + + /** + * Encodes the specified byte array into a String using the {@link Base64} + * encoding scheme. + * + *

This method first encodes all input bytes into a base64 encoded + * byte array and then constructs a new String by using the encoded byte + * array and the {@link java.nio.charset.StandardCharsets.ISO_8859_1 ISO-8859-1} + * charset. + * + *

In other words, an invocation of this method has exactly the same + * effect as invoking + * {@code new String(encode(src), StandardCharsets.ISO_8859_1)}. + * + * @param src + * the byte array to encode + * @return A String containing the resulting Base64 encoded characters + */ + @SuppressWarnings("deprecation") + public String encodeToString(byte[] src) { + byte[] encoded = encode(src); + return new String(encoded, 0, 0, encoded.length); + } + + /** + * Encodes all remaining bytes from the specified byte buffer into + * a newly-allocated ByteBuffer using the {@link Base64} encoding + * scheme. + * + * Upon return, the source buffer's position will be updated to + * its limit; its limit will not have been changed. The returned + * output buffer's position will be zero and its limit will be the + * number of resulting encoded bytes. + * + * @param buffer + * the source ByteBuffer to encode + * @return A newly-allocated byte buffer containing the encoded bytes. + */ + public ByteBuffer encode(ByteBuffer buffer) { + int len = 4 * ((buffer.remaining() + 2) / 3); + if (linemax > 0) + len += (len - 1) / linemax * newline.length; + byte[] dst = new byte[len]; + int ret = 0; + if (buffer.hasArray()) { + ret = encode0(buffer.array(), + buffer.arrayOffset() + buffer.position(), + buffer.arrayOffset() + buffer.limit(), + dst); + buffer.position(buffer.limit()); + } else { + byte[] src = new byte[buffer.remaining()]; + buffer.get(src); + ret = encode0(src, 0, src.length, dst); + } + if (ret != dst.length) + dst = Arrays.copyOf(dst, ret); + return ByteBuffer.wrap(dst); + } + + /** + * Encodes as many bytes as possible from the input byte buffer + * using the {@link Base64} encoding scheme, writing the resulting + * bytes to the given output byte buffer. + * + *

The buffers are read from, and written to, starting at their + * current positions. Upon return, the input and output buffers' + * positions will be advanced to reflect the bytes read and written, + * but their limits will not be modified. + * + *

The encoding operation will stop and return if either all + * remaining bytes in the input buffer have been encoded and written + * to the output buffer, or the output buffer has insufficient space + * to encode any more input bytes. The encoding operation can be + * continued, if there is more bytes in input buffer to be encoded, + * by invoking this method again with an output buffer that has more + * {@linkplain Buffer#remaining remaining} bytes. This is typically + * done by draining any encoded bytes from the output buffer. The + * value returned from last invocation needs to be passed in as the + * third parameter {@code bytesOut} if it is to continue an unfinished + * encoding, 0 otherwise. + * + *

Recommended Usage Example + *

+         *    ByteBuffer src = ...;
+         *    ByteBuffer dst = ...;
+         *    Base64.Encoder enc = Base64.getMimeDecoder();
+         *
+         *    int bytesOut = 0;
+         *    while (src.hasRemaining()) {
+         *        // clear output buffer for decoding
+         *        dst.clear();
+         *        bytesOut = enc.encode(src, dst, bytesOut);
+         *
+         *        // read encoded bytes out of "dst"
+         *        dst.flip();
+         *        ...
+         *    }
+         * 
+ * + * @param src + * the input byte buffer to encode + * @param dst + * the output byte buffer + * @param bytesOut + * the return value of last invocation if this is to continue + * an unfinished encoding operation, 0 otherwise + * @return The sum total of {@code bytesOut} and the number of bytes + * written to the output ByteBuffer during this invocation. + */ + public int encode(ByteBuffer src, ByteBuffer dst, int bytesOut) { + if (src.hasArray() && dst.hasArray()) + return encodeArray(src, dst, bytesOut); + return encodeBuffer(src, dst, bytesOut); + } + + /** + * Wraps an output stream for encoding byte data using the {@link Base64} + * encoding scheme. + * + *

It is recommended to promptly close the returned output stream after + * use, during which it will flush all possible leftover bytes to the underlying + * output stream. Closing the returned output stream will close the underlying + * output stream. + * + * @param os + * the output stream. + * @return the output stream for encoding the byte data into the + * specified Base64 encoded format + */ + public OutputStream wrap(OutputStream os) { + return new EncOutputStream(os, isURL ? toBase64URL : toBase64, + newline, linemax); + } + + private int encodeArray(ByteBuffer src, ByteBuffer dst, int bytesOut) { + char[] base64 = isURL? toBase64URL : toBase64; + byte[] sa = src.array(); + int sp = src.arrayOffset() + src.position(); + int sl = src.arrayOffset() + src.limit(); + byte[] da = dst.array(); + int dp = dst.arrayOffset() + dst.position(); + int dl = dst.arrayOffset() + dst.limit(); + int dp00 = dp; + int dpos = 0; // dp of each line + if (linemax > 0 && bytesOut > 0) + dpos = bytesOut % (linemax + newline.length); + try { + if (dpos == linemax && sp < src.limit()) { + if (dp + newline.length > dl) + return dp - dp00 + bytesOut; + for (byte b : newline){ + dst.put(dp++, b); + } + dpos = 0; + } + sl = sp + (sl - sp) / 3 * 3; + while (sp < sl) { + int slen = (linemax > 0) ? (linemax - dpos) / 4 * 3 + : sl - sp; + int sl0 = Math.min(sp + slen, sl); + for (int sp0 = sp, dp0 = dp ; sp0 < sl0; ) { + if (dp0 + 4 > dl) { + sp = sp0; dp = dp0; + return dp0 - dp00 + bytesOut; + } + int bits = (sa[sp0++] & 0xff) << 16 | + (sa[sp0++] & 0xff) << 8 | + (sa[sp0++] & 0xff); + da[dp0++] = (byte)base64[(bits >>> 18) & 0x3f]; + da[dp0++] = (byte)base64[(bits >>> 12) & 0x3f]; + da[dp0++] = (byte)base64[(bits >>> 6) & 0x3f]; + da[dp0++] = (byte)base64[bits & 0x3f]; + } + int n = (sl0 - sp) / 3 * 4; + dpos += n; + dp += n; + sp = sl0; + if (dpos == linemax && sp < src.limit()) { + if (dp + newline.length > dl) + return dp - dp00 + bytesOut; + for (byte b : newline){ + da[dp++] = b; + } + dpos = 0; + } + } + sl = src.arrayOffset() + src.limit(); + if (sp < sl && dl >= dp + 4) { // 1 or 2 leftover bytes + int b0 = sa[sp++] & 0xff; + da[dp++] = (byte)base64[b0 >> 2]; + if (sp == sl) { + da[dp++] = (byte)base64[(b0 << 4) & 0x3f]; + da[dp++] = '='; + da[dp++] = '='; + } else { + int b1 = sa[sp++] & 0xff; + da[dp++] = (byte)base64[(b0 << 4) & 0x3f | (b1 >> 4)]; + da[dp++] = (byte)base64[(b1 << 2) & 0x3f]; + da[dp++] = '='; + } + } + return dp - dp00 + bytesOut; + } finally { + src.position(sp - src.arrayOffset()); + dst.position(dp - dst.arrayOffset()); + } + } + + private int encodeBuffer(ByteBuffer src, ByteBuffer dst, int bytesOut) { + char[] base64 = isURL? toBase64URL : toBase64; + int sp = src.position(); + int sl = src.limit(); + int dp = dst.position(); + int dl = dst.limit(); + int dp00 = dp; + + int dpos = 0; // dp of each line + if (linemax > 0 && bytesOut > 0) + dpos = bytesOut % (linemax + newline.length); + try { + if (dpos == linemax && sp < src.limit()) { + if (dp + newline.length > dl) + return dp - dp00 + bytesOut; + for (byte b : newline){ + dst.put(dp++, b); + } + dpos = 0; + } + sl = sp + (sl - sp) / 3 * 3; + while (sp < sl) { + int slen = (linemax > 0) ? (linemax - dpos) / 4 * 3 + : sl - sp; + int sl0 = Math.min(sp + slen, sl); + for (int sp0 = sp, dp0 = dp ; sp0 < sl0; ) { + if (dp0 + 4 > dl) { + sp = sp0; dp = dp0; + return dp0 - dp00 + bytesOut; + } + int bits = (src.get(sp0++) & 0xff) << 16 | + (src.get(sp0++) & 0xff) << 8 | + (src.get(sp0++) & 0xff); + dst.put(dp0++, (byte)base64[(bits >>> 18) & 0x3f]); + dst.put(dp0++, (byte)base64[(bits >>> 12) & 0x3f]); + dst.put(dp0++, (byte)base64[(bits >>> 6) & 0x3f]); + dst.put(dp0++, (byte)base64[bits & 0x3f]); + } + int n = (sl0 - sp) / 3 * 4; + dpos += n; + dp += n; + sp = sl0; + if (dpos == linemax && sp < src.limit()) { + if (dp + newline.length > dl) + return dp - dp00 + bytesOut; + for (byte b : newline){ + dst.put(dp++, b); + } + dpos = 0; + } + } + if (sp < src.limit() && dl >= dp + 4) { // 1 or 2 leftover bytes + int b0 = src.get(sp++) & 0xff; + dst.put(dp++, (byte)base64[b0 >> 2]); + if (sp == src.limit()) { + dst.put(dp++, (byte)base64[(b0 << 4) & 0x3f]); + dst.put(dp++, (byte)'='); + dst.put(dp++, (byte)'='); + } else { + int b1 = src.get(sp++) & 0xff; + dst.put(dp++, (byte)base64[(b0 << 4) & 0x3f | (b1 >> 4)]); + dst.put(dp++, (byte)base64[(b1 << 2) & 0x3f]); + dst.put(dp++, (byte)'='); + } + } + return dp - dp00 + bytesOut; + } finally { + src.position(sp); + dst.position(dp); + } + } + + private int encode0(byte[] src, int off, int end, byte[] dst) { + char[] base64 = isURL ? toBase64URL : toBase64; + int sp = off; + int slen = (end - off) / 3 * 3; + int sl = off + slen; + if (linemax > 0 && slen > linemax / 4 * 3) + slen = linemax / 4 * 3; + int dp = 0; + while (sp < sl) { + int sl0 = Math.min(sp + slen, sl); + for (int sp0 = sp, dp0 = dp ; sp0 < sl0; ) { + int bits = (src[sp0++] & 0xff) << 16 | + (src[sp0++] & 0xff) << 8 | + (src[sp0++] & 0xff); + dst[dp0++] = (byte)base64[(bits >>> 18) & 0x3f]; + dst[dp0++] = (byte)base64[(bits >>> 12) & 0x3f]; + dst[dp0++] = (byte)base64[(bits >>> 6) & 0x3f]; + dst[dp0++] = (byte)base64[bits & 0x3f]; + } + int dlen = (sl0 - sp) / 3 * 4; + dp += dlen; + sp = sl0; + if (dlen == linemax && sp < end) { + for (byte b : newline){ + dst[dp++] = b; + } + } + } + if (sp < end) { // 1 or 2 leftover bytes + int b0 = src[sp++] & 0xff; + dst[dp++] = (byte)base64[b0 >> 2]; + if (sp == end) { + dst[dp++] = (byte)base64[(b0 << 4) & 0x3f]; + dst[dp++] = '='; + dst[dp++] = '='; + } else { + int b1 = src[sp++] & 0xff; + dst[dp++] = (byte)base64[(b0 << 4) & 0x3f | (b1 >> 4)]; + dst[dp++] = (byte)base64[(b1 << 2) & 0x3f]; + dst[dp++] = '='; + } + } + return dp; + } + } + + /** + * This class implements a decoder for decoding byte data using the + * Base64 encoding scheme as specified in RFC 4648 and RFC 2045. + * + *

Instances of {@link Decoder} class are safe for use by + * multiple concurrent threads. + * + *

Unless otherwise noted, passing a {@code null} argument to + * a method of this class will cause a + * {@link java.lang.NullPointerException NullPointerException} to + * be thrown. + * + * @see Encoder + * @since 1.8 + */ + public static class Decoder { + + private final boolean isURL; + private final boolean isMIME; + + private Decoder(boolean isURL, boolean isMIME) { + this.isURL = isURL; + this.isMIME = isMIME; + } + + /** + * Lookup table for decoding unicode characters drawn from the + * "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into + * their 6-bit positive integer equivalents. Characters that + * are not in the Base64 alphabet but fall within the bounds of + * the array are encoded to -1. + * + */ + private static final int[] fromBase64 = new int[256]; + static { + Arrays.fill(fromBase64, -1); + for (int i = 0; i < Encoder.toBase64.length; i++) + fromBase64[Encoder.toBase64[i]] = i; + fromBase64['='] = -2; + } + + /** + * Lookup table for decoding "URL and Filename safe Base64 Alphabet" + * as specified in Table2 of the RFC 4648. + */ + private static final int[] fromBase64URL = new int[256]; + + static { + Arrays.fill(fromBase64URL, -1); + for (int i = 0; i < Encoder.toBase64URL.length; i++) + fromBase64URL[Encoder.toBase64URL[i]] = i; + fromBase64URL['='] = -2; + } + + static final Decoder RFC4648 = new Decoder(false, false); + static final Decoder RFC4648_URLSAFE = new Decoder(true, false); + static final Decoder RFC2045 = new Decoder(false, true); + + /** + * Decodes all bytes from the input byte array using the {@link Base64} + * encoding scheme, writing the results into a newly-allocated output + * byte array. The returned byte array is of the length of the resulting + * bytes. + * + * @param src + * the byte array to decode + * + * @return A newly-allocated byte array containing the decoded bytes. + * + * @throws IllegalArgumentException + * if {@code src} is not in valid Base64 scheme + */ + public byte[] decode(byte[] src) { + byte[] dst = new byte[outLength(src, 0, src.length)]; + int ret = decode0(src, 0, src.length, dst); + if (ret != dst.length) { + dst = Arrays.copyOf(dst, ret); + } + return dst; + } + + /** + * Decodes a Base64 encoded String into a newly-allocated byte array + * using the {@link Base64} encoding scheme. + * + *

An invocation of this method has exactly the same effect as invoking + * {@code return decode(src.getBytes(StandardCharsets.ISO_8859_1))} + * + * @param src + * the string to decode + * + * @return A newly-allocated byte array containing the decoded bytes. + * + * @throws IllegalArgumentException + * if {@code src} is not in valid Base64 scheme + */ + public byte[] decode(String src) { + return decode(src.getBytes(StandardCharsets.ISO_8859_1)); + } + + /** + * Decodes all bytes from the input byte array using the {@link Base64} + * encoding scheme, writing the results into the given output byte array, + * starting at offset 0. + * + *

It is the responsibility of the invoker of this method to make + * sure the output byte array {@code dst} has enough space for decoding + * all bytes from the input byte array. No bytes will be be written to + * the output byte array if the output byte array is not big enough. + * + *

If the input byte array is not in valid Base64 encoding scheme + * then some bytes may have been written to the output byte array before + * IllegalargumentException is thrown. + * + * @param src + * the byte array to decode + * @param dst + * the output byte array + * + * @return The number of bytes written to the output byte array + * + * @throws IllegalArgumentException + * if {@code src} is not in valid Base64 scheme, or {@code dst} + * does not have enough space for decoding all input bytes. + */ + public int decode(byte[] src, byte[] dst) { + int len = outLength(src, 0, src.length); + if (dst.length < len) + throw new IllegalArgumentException( + "Output byte array is too small for decoding all input bytes"); + return decode0(src, 0, src.length, dst); + } + + /** + * Decodes all bytes from the input byte buffer using the {@link Base64} + * encoding scheme, writing the results into a newly-allocated ByteBuffer. + * + *

Upon return, the source buffer's position will be updated to + * its limit; its limit will not have been changed. The returned + * output buffer's position will be zero and its limit will be the + * number of resulting decoded bytes + * + * @param buffer + * the ByteBuffer to decode + * + * @return A newly-allocated byte buffer containing the decoded bytes + * + * @throws IllegalArgumentException + * if {@code src} is not in valid Base64 scheme. + */ + public ByteBuffer decode(ByteBuffer buffer) { + int pos0 = buffer.position(); + try { + byte[] src; + int sp, sl; + if (buffer.hasArray()) { + src = buffer.array(); + sp = buffer.arrayOffset() + buffer.position(); + sl = buffer.arrayOffset() + buffer.limit(); + buffer.position(buffer.limit()); + } else { + src = new byte[buffer.remaining()]; + buffer.get(src); + sp = 0; + sl = src.length; + } + byte[] dst = new byte[outLength(src, sp, sl)]; + return ByteBuffer.wrap(dst, 0, decode0(src, sp, sl, dst)); + } catch (IllegalArgumentException iae) { + buffer.position(pos0); + throw iae; + } + } + + /** + * Decodes as many bytes as possible from the input byte buffer + * using the {@link Base64} encoding scheme, writing the resulting + * bytes to the given output byte buffer. + * + *

The buffers are read from, and written to, starting at their + * current positions. Upon return, the input and output buffers' + * positions will be advanced to reflect the bytes read and written, + * but their limits will not be modified. + * + *

If the input buffer is not in valid Base64 encoding scheme + * then some bytes may have been written to the output buffer + * before IllegalArgumentException is thrown. The positions of + * both input and output buffer will not be advanced in this case. + * + *

The decoding operation will end and return if all remaining + * bytes in the input buffer have been decoded and written to the + * output buffer. + * + *

The decoding operation will stop and return if the output + * buffer has insufficient space to decode any more input bytes. + * The decoding operation can be continued, if there is more bytes + * in input buffer to be decoded, by invoking this method again with + * an output buffer that has more {@linkplain Buffer#remaining remaining} + * bytes.This is typically done by draining any decoded bytes from the + * output buffer. + * + *

Recommended Usage Example + *

+         *    ByteBuffer src = ...;
+         *    ByteBuffer dst = ...;
+         *    Base64.Decoder dec = Base64.getDecoder();
+         *
+         *    while (src.hasRemaining()) {
+         *
+         *        // prepare the output byte buffer
+         *        dst.clear();
+         *        dec.decode(src, dst);
+         *
+         *        // read bytes from the output buffer
+         *        dst.flip();
+         *        ...
+         *    }
+         * 
+ * + * @param src + * the input byte buffer to decode + * @param dst + * the output byte buffer + * + * @return The number of bytes written to the output byte buffer during + * this decoding invocation + * + * @throws IllegalArgumentException + * if {@code src} is not in valid Base64 scheme. + */ + public int decode(ByteBuffer src, ByteBuffer dst) { + int sp0 = src.position(); + int dp0 = dst.position(); + try { + if (src.hasArray() && dst.hasArray()) + return decodeArray(src, dst); + return decodeBuffer(src, dst); + } catch (IllegalArgumentException iae) { + src.position(sp0); + dst.position(dp0); + throw iae; + } + } + + /** + * Returns an input stream for decoding {@link Base64} encoded byte stream. + * + *

Closing the returned input stream will close the underlying + * input stream. + * + * @param is + * the input stream + * + * @return the input stream for decoding the specified Base64 encoded + * byte stream + */ + public InputStream wrap(InputStream is) { + return new DecInputStream(is, isURL ? fromBase64URL : fromBase64, isMIME); + } + + private int decodeArray(ByteBuffer src, ByteBuffer dst) { + int[] base64 = isURL ? fromBase64URL : fromBase64; + int bits = 0; + int shiftto = 18; // pos of first byte of 4-byte atom + byte[] sa = src.array(); + int sp = src.arrayOffset() + src.position(); + int sl = src.arrayOffset() + src.limit(); + byte[] da = dst.array(); + int dp = dst.arrayOffset() + dst.position(); + int dl = dst.arrayOffset() + dst.limit(); + int dp0 = dp; + int mark = sp; + boolean padding = false; + try { + while (sp < sl) { + int b = sa[sp++] & 0xff; + if ((b = base64[b]) < 0) { + if (b == -2) { // padding byte + padding = true; + break; + } + if (isMIME) // skip if for rfc2045 + continue; + else + throw new IllegalArgumentException( + "Illegal base64 character " + + Integer.toString(sa[sp - 1], 16)); + } + bits |= (b << shiftto); + shiftto -= 6; + if (shiftto < 0) { + if (dl < dp + 3) + return dp; + da[dp++] = (byte)(bits >> 16); + da[dp++] = (byte)(bits >> 8); + da[dp++] = (byte)(bits); + shiftto = 18; + bits = 0; + mark = sp; + } + } + if (shiftto == 6) { + if (dl - dp < 1) + return dp; + if (padding && (sp + 1 != sl || sa[sp++] != '=')) + throw new IllegalArgumentException( + "Input buffer has wrong 4-byte ending unit"); + da[dp++] = (byte)(bits >> 16); + mark = sp; + } else if (shiftto == 0) { + if (dl - dp < 2) + return dp; + if (padding && sp != sl) + throw new IllegalArgumentException( + "Input buffer has wrong 4-byte ending unit"); + da[dp++] = (byte)(bits >> 16); + da[dp++] = (byte)(bits >> 8); + mark = sp; + } else if (padding || shiftto != 18) { + throw new IllegalArgumentException( + "Last unit does not have enough valid bits"); + } + return dp - dp0; + } finally { + src.position(mark); + dst.position(dp); + } + } + + private int decodeBuffer(ByteBuffer src, ByteBuffer dst) { + int[] base64 = isURL ? fromBase64URL : fromBase64; + int bits = 0; + int shiftto = 18; // pos of first byte of 4-byte atom + int sp = src.position(); + int sl = src.limit(); + int dp = dst.position(); + int dl = dst.limit(); + int dp0 = dp; + int mark = sp; + boolean padding = false; + + try { + while (sp < sl) { + int b = src.get(sp++) & 0xff; + if ((b = base64[b]) < 0) { + if (b == -2) { // padding byte + padding = true; + break; + } + if (isMIME) // skip if for rfc2045 + continue; + else + throw new IllegalArgumentException( + "Illegal base64 character " + + Integer.toString(src.get(sp - 1), 16)); + } + bits |= (b << shiftto); + shiftto -= 6; + if (shiftto < 0) { + if (dl < dp + 3) + return dp; + dst.put(dp++, (byte)(bits >> 16)); + dst.put(dp++, (byte)(bits >> 8)); + dst.put(dp++, (byte)(bits)); + shiftto = 18; + bits = 0; + mark = sp; + } + } + if (shiftto == 6) { + if (dl - dp < 1) + return dp; + if (padding && (sp + 1 != sl || src.get(sp++) != '=')) + throw new IllegalArgumentException( + "Input buffer has wrong 4-byte ending unit"); + dst.put(dp++, (byte)(bits >> 16)); + mark = sp; + } else if (shiftto == 0) { + if (dl - dp < 2) + return dp; + if (padding && sp != sl) + throw new IllegalArgumentException( + "Input buffer has wrong 4-byte ending unit"); + dst.put(dp++, (byte)(bits >> 16)); + dst.put(dp++, (byte)(bits >> 8)); + mark = sp; + } else if (padding || shiftto != 18) { + throw new IllegalArgumentException( + "Last unit does not have enough valid bits"); + } + return dp - dp0; + } finally { + src.position(mark); + dst.position(dp); + } + } + + private int outLength(byte[] src, int sp, int sl) { + int[] base64 = isURL ? fromBase64URL : fromBase64; + int paddings = 0; + int len = sl - sp; + if (len == 0) + return 0; + if (len < 2) + throw new IllegalArgumentException( + "Input byte[] should at least have 2 bytes for base64 bytes"); + if (src[sl - 1] == '=') { + paddings++; + if (src[sl - 2] == '=') + paddings++; + } + if (isMIME) { + // scan all bytes to fill out all non-alphabet. a performance + // trade-off of pre-scan or Arrays.copyOf + int n = 0; + while (sp < sl) { + int b = src[sp++] & 0xff; + if (b == '=') + break; + if ((b = base64[b]) == -1) + n++; + } + len -= n; + } + if (paddings == 0 && (len & 0x3) != 0) + paddings = 4 - (len & 0x3); + return 3 * ((len + 3) / 4) - paddings; + } + + private int decode0(byte[] src, int sp, int sl, byte[] dst) { + int[] base64 = isURL ? fromBase64URL : fromBase64; + int dp = 0; + int bits = 0; + int shiftto = 18; // pos of first byte of 4-byte atom + boolean padding = false; + while (sp < sl) { + int b = src[sp++] & 0xff; + if ((b = base64[b]) < 0) { + if (b == -2) { // padding byte + padding = true; + break; + } + if (isMIME) // skip if for rfc2045 + continue; + else + throw new IllegalArgumentException( + "Illegal base64 character " + + Integer.toString(src[sp - 1], 16)); + } + bits |= (b << shiftto); + shiftto -= 6; + if (shiftto < 0) { + dst[dp++] = (byte)(bits >> 16); + dst[dp++] = (byte)(bits >> 8); + dst[dp++] = (byte)(bits); + shiftto = 18; + bits = 0; + } + } + // reach end of byte arry or hit padding '=' characters. + // if '=' presents, they must be the last one or two. + if (shiftto == 6) { // xx== + if (padding && (sp + 1 != sl || src[sp] != '=')) + throw new IllegalArgumentException( + "Input byte array has wrong 4-byte ending unit"); + dst[dp++] = (byte)(bits >> 16); + } else if (shiftto == 0) { // xxx= + if (padding && sp != sl) + throw new IllegalArgumentException( + "Input byte array has wrong 4-byte ending unit"); + dst[dp++] = (byte)(bits >> 16); + dst[dp++] = (byte)(bits >> 8); + } else if (padding || shiftto != 18) { + throw new IllegalArgumentException( + "last unit does not have enough bytes"); + } + return dp; + } + } + + /* + * An output stream for encoding bytes into the Base64. + */ + private static class EncOutputStream extends FilterOutputStream { + + private int leftover = 0; + private int b0, b1, b2; + private boolean closed = false; + + private final char[] base64; // byte->base64 mapping + private final byte[] newline; // line separator, if needed + private final int linemax; + private int linepos = 0; + + EncOutputStream(OutputStream os, + char[] base64, byte[] newline, int linemax) { + super(os); + this.base64 = base64; + this.newline = newline; + this.linemax = linemax; + } + + @Override + public void write(int b) throws IOException { + byte[] buf = new byte[1]; + buf[0] = (byte)(b & 0xff); + write(buf, 0, 1); + } + + private void checkNewline() throws IOException { + if (linepos == linemax) { + out.write(newline); + linepos = 0; + } + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + if (closed) + throw new IOException("Stream is closed"); + if (off < 0 || len < 0 || off + len > b.length) + throw new ArrayIndexOutOfBoundsException(); + if (len == 0) + return; + if (leftover != 0) { + if (leftover == 1) { + b1 = b[off++] & 0xff; + len--; + if (len == 0) { + leftover++; + return; + } + } + b2 = b[off++] & 0xff; + len--; + checkNewline(); + out.write(base64[b0 >> 2]); + out.write(base64[(b0 << 4) & 0x3f | (b1 >> 4)]); + out.write(base64[(b1 << 2) & 0x3f | (b2 >> 6)]); + out.write(base64[b2 & 0x3f]); + linepos += 4; + } + int nBits24 = len / 3; + leftover = len - (nBits24 * 3); + while (nBits24-- > 0) { + checkNewline(); + int bits = (b[off++] & 0xff) << 16 | + (b[off++] & 0xff) << 8 | + (b[off++] & 0xff); + out.write(base64[(bits >>> 18) & 0x3f]); + out.write(base64[(bits >>> 12) & 0x3f]); + out.write(base64[(bits >>> 6) & 0x3f]); + out.write(base64[bits & 0x3f]); + linepos += 4; + } + if (leftover == 1) { + b0 = b[off++] & 0xff; + } else if (leftover == 2) { + b0 = b[off++] & 0xff; + b1 = b[off++] & 0xff; + } + } + + @Override + public void close() throws IOException { + if (!closed) { + closed = true; + if (leftover == 1) { + checkNewline(); + out.write(base64[b0 >> 2]); + out.write(base64[(b0 << 4) & 0x3f]); + out.write('='); + out.write('='); + } else if (leftover == 2) { + checkNewline(); + out.write(base64[b0 >> 2]); + out.write(base64[(b0 << 4) & 0x3f | (b1 >> 4)]); + out.write(base64[(b1 << 2) & 0x3f]); + out.write('='); + } + leftover = 0; + out.close(); + } + } + } + + /* + * An input stream for decoding Base64 bytes + */ + private static class DecInputStream extends InputStream { + + private final InputStream is; + private final boolean isMIME; + private final int[] base64; // base64 -> byte mapping + private int bits = 0; // 24-bit buffer for decoding + private int nextin = 18; // next available "off" in "bits" for input; + // -> 18, 12, 6, 0 + private int nextout = -8; // next available "off" in "bits" for output; + // -> 8, 0, -8 (no byte for output) + private boolean eof = false; + private boolean closed = false; + + DecInputStream(InputStream is, int[] base64, boolean isMIME) { + this.is = is; + this.base64 = base64; + this.isMIME = isMIME; + } + + private byte[] sbBuf = new byte[1]; + + @Override + public int read() throws IOException { + return read(sbBuf, 0, 1) == -1 ? -1 : sbBuf[0] & 0xff; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (closed) + throw new IOException("Stream is closed"); + if (eof && nextout < 0) // eof and no leftover + return -1; + if (off < 0 || len < 0 || len > b.length - off) + throw new IndexOutOfBoundsException(); + int oldOff = off; + if (nextout >= 0) { // leftover output byte(s) in bits buf + do { + if (len == 0) + return off - oldOff; + b[off++] = (byte)(bits >> nextout); + len--; + nextout -= 8; + } while (nextout >= 0); + bits = 0; + } + while (len > 0) { + int v = is.read(); + if (v == -1) { + eof = true; + if (nextin != 18) + throw new IOException("Base64 stream has un-decoded dangling byte(s)."); + if (off == oldOff) + return -1; + else + return off - oldOff; + } + if (v == '=') { // padding byte(s) + if (nextin != 6 && nextin != 0) { + throw new IOException("Illegal base64 ending sequence:" + nextin); + } + b[off++] = (byte)(bits >> (16)); + len--; + if (nextin == 0) { // only one padding byte + if (len == 0) { // no enough output space + bits >>= 8; // shift to lowest byte + nextout = 0; + } else { + b[off++] = (byte) (bits >> 8); + } + } + eof = true; + break; + } + if ((v = base64[v]) == -1) { + if (isMIME) // skip if for rfc2045 + continue; + else + throw new IOException("Illegal base64 character " + + Integer.toString(v, 16)); + } + bits |= (v << nextin); + if (nextin == 0) { + nextin = 18; // clear for next + nextout = 16; + while (nextout >= 0) { + b[off++] = (byte)(bits >> nextout); + len--; + nextout -= 8; + if (len == 0 && nextout >= 0) { // don't clean "bits" + return off - oldOff; + } + } + bits = 0; + } else { + nextin -= 6; + } + } + return off - oldOff; + } + + @Override + public int available() throws IOException { + if (closed) + throw new IOException("Stream is closed"); + return is.available(); // TBD: + } + + @Override + public void close() throws IOException { + if (!closed) { + closed = true; + is.close(); + } + } + } +} diff --git a/src/share/classes/java/util/PropertyPermission.java b/src/share/classes/java/util/PropertyPermission.java index f41418e1723e8c810576f920c45a689b831fd08e..7a7700a486e55ff2337c7fda07435ed65a98f0d6 100644 --- a/src/share/classes/java/util/PropertyPermission.java +++ b/src/share/classes/java/util/PropertyPermission.java @@ -48,8 +48,8 @@ import sun.security.util.SecurityConstants; * convention follows the hierarchical property naming convention. * Also, an asterisk * may appear at the end of the name, following a ".", or by itself, to - * signify a wildcard match. For example: "java.*" or "*" is valid, - * "*java" or "a*b" is not valid. + * signify a wildcard match. For example: "java.*" and "*" signify a wildcard + * match, while "*java" and "a*b" do not. *

*

* The actions to be granted are passed to the constructor in a string containing diff --git a/src/share/classes/java/util/function/BinaryOperator.java b/src/share/classes/java/util/function/BinaryOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..929a2de687ad93d69a8a9b9c8aa2e1989fef2823 --- /dev/null +++ b/src/share/classes/java/util/function/BinaryOperator.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2010, 2012 Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation upon two operands yielding a result. The operands and the result + * are all of the same type. + * + * @param the type of operands to {@code operate} and of the result + * + * @since 1.8 + */ +public interface BinaryOperator { + + /** + * Returns the result of the operation upon the operands. + * The operands are named {@code left} and {@code right} for operations + * where the order of operands matters. + * + * @param left the left operand + * @param right the right operand + * @return the result of the operation + */ + public T operate(T left, T right); +} diff --git a/src/share/classes/java/util/function/Block.java b/src/share/classes/java/util/function/Block.java new file mode 100644 index 0000000000000000000000000000000000000000..6b28d186824a265df081ee5a7725b9d43c5f9ac4 --- /dev/null +++ b/src/share/classes/java/util/function/Block.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2010, 2012 Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation upon an input object. The operation may modify that object or + * external state (other objects). + * + * @param The type of input objects to {@code accept} + * + * @since 1.8 + */ +public interface Block { + + /** + * Use the input object in operations which may modify that object or + * external state (other objects). + * + * @param t the input object + */ + public void accept(T t); +} diff --git a/src/share/classes/java/util/function/DoubleBinaryOperator.java b/src/share/classes/java/util/function/DoubleBinaryOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..07ff741be965c77b86abfd5333d4766a5e7b121a --- /dev/null +++ b/src/share/classes/java/util/function/DoubleBinaryOperator.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation on two {@code double} operands yielding a {@code double} result. + * + * @since 1.8 + */ +public interface DoubleBinaryOperator /* extends BinaryOperator */ { +// +// @Override +// public default Double operate(Double left, Double right) { return operateAsDouble((double) left, (double) right); } + + /** + * Returns the {@code double} result of the operation upon the + * {@code double} operands. The parameters are named {@code left} and + * {@code right} for operations where the order of parameters matters. + * + * @param left the left operand value + * @param right the right operand value + * @return the result of the operation + */ + public double operateAsDouble(double left, double right); +} diff --git a/src/share/classes/java/util/function/DoubleBlock.java b/src/share/classes/java/util/function/DoubleBlock.java new file mode 100644 index 0000000000000000000000000000000000000000..80574de096fa9fbfe5577769813c3fe024f5d8ae --- /dev/null +++ b/src/share/classes/java/util/function/DoubleBlock.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010, 2012 Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation upon a {@code double} input value. The operation may modify + * external state. + * + *

This is the primitive type specialization of {@link Block} for + * {@code double} and also may be used as a {@code Block}. + * + * @since 1.8 + */ +public interface DoubleBlock { + + /** + * Use the {@code double} input value in an operation which may modify + * external state. + * + * @param t the input value + */ + public void accept(double t); +} diff --git a/src/share/classes/java/util/function/DoubleFunction.java b/src/share/classes/java/util/function/DoubleFunction.java new file mode 100644 index 0000000000000000000000000000000000000000..06c405e6d8c2ba4cac965fd4f2ae7907a2033ec5 --- /dev/null +++ b/src/share/classes/java/util/function/DoubleFunction.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * Apply a function to the input object yielding an appropriate {@code double} + * value; this is the {@code double}-bearing specialization for {@link Function}. + * + * @param the type of input objects to the function + * + * @since 1.8 + */ +public interface DoubleFunction { + + /** + * Apply a function to the input object yielding an appropriate + * {@code double} value. + * + * @param t the input object + * @return the function result value + */ + public double applyAsDouble(T t); +} diff --git a/src/share/classes/java/util/function/DoubleSupplier.java b/src/share/classes/java/util/function/DoubleSupplier.java new file mode 100644 index 0000000000000000000000000000000000000000..7e718a3c141ac6cd16f830bf58628e0d7fcde81d --- /dev/null +++ b/src/share/classes/java/util/function/DoubleSupplier.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * A supplier of {@code double} values. + * + *

This is the primitive type specialization of {@link Supplier} for + * {@code double} and also may be used as a {@code Supplier}. + * + * @since 1.8 + */ +public interface DoubleSupplier { + + /** + * Returns a {@code double} value. + * + * @return a {@code double} value + */ + public double getAsDouble(); +} diff --git a/src/share/classes/java/util/function/DoubleUnaryOperator.java b/src/share/classes/java/util/function/DoubleUnaryOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..b9ac7f6fda7473dd42cf3df7ba28e3747cdda793 --- /dev/null +++ b/src/share/classes/java/util/function/DoubleUnaryOperator.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation on a single {@code double} operand yielding a {@code double} + * result. + * + * @since 1.8 + */ +public interface DoubleUnaryOperator { + + /** + * Returns the {@code double} result of the operation upon the + * {@code double} operand. + * + * @param operand the operand value + * @return the operation result value + */ + public double operateAsDouble(double operand); +} diff --git a/src/share/classes/java/util/function/Function.java b/src/share/classes/java/util/function/Function.java new file mode 100644 index 0000000000000000000000000000000000000000..a651362494c9a36f761cc6fd1c5c80262f46c8b7 --- /dev/null +++ b/src/share/classes/java/util/function/Function.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2010, 2012 Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * Apply a function to the input object yielding an appropriate result object. A + * function may variously provide a mapping between types, object instances or + * keys and values or any other form of transformation upon the input. + * + * @param the type of input objects to the {@code apply} operation + * @param the type of result objects from the {@code apply} operation. May + * be the same type as {@code }. + * + * @since 1.8 + */ +public interface Function { + + /** + * Yield an appropriate result object for the input object. + * + * @param t the input object + * @return the function result + */ + public R apply(T t); +} diff --git a/src/share/classes/java/util/function/IntBinaryOperator.java b/src/share/classes/java/util/function/IntBinaryOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..312fb2db046c62485e27c0947ff4946f93234f63 --- /dev/null +++ b/src/share/classes/java/util/function/IntBinaryOperator.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation on two {@code int} operands yielding an {@code int} result. + * + * @since 1.8 + */ +public interface IntBinaryOperator { + + /** + * Returns the {@code int} result of the operation upon the {@code int} + * operands. The parameters are named {@code left} and {@code right} for + * operations where the order of parameters matters. + * + * @param left the left operand value + * @param right the right operand value + * @return the result of the operation + */ + public int operateAsInt(int left, int right); +} diff --git a/src/share/classes/java/util/function/IntBlock.java b/src/share/classes/java/util/function/IntBlock.java new file mode 100644 index 0000000000000000000000000000000000000000..27f44d6cd9bb3332e463cb264feae94ad5b841d2 --- /dev/null +++ b/src/share/classes/java/util/function/IntBlock.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010, 2012 Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation upon an {@code int} input value. The operation may modify + * external state. + * + *

This is the primitive type specialization of {@link Block} for + * {@code int} and also may be used as a {@code Block}. + * + * @since 1.8 + */ +public interface IntBlock { + + /** + * Use the {@code int} input value in an operation which may modify external + * state. + * + * @param t the input value + */ + public void accept(int t); +} diff --git a/src/share/classes/java/util/function/IntFunction.java b/src/share/classes/java/util/function/IntFunction.java new file mode 100644 index 0000000000000000000000000000000000000000..af8d44862540e8dc64421c1e0ad8767ca7b59819 --- /dev/null +++ b/src/share/classes/java/util/function/IntFunction.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * Apply a function to the input object yielding an appropriate {@code int} + * value; this is the {@code int}-bearing specialization for {@link Function}. + * + * @param the type of input objects to the function + * + * @since 1.8 + */ +public interface IntFunction { + + /** + * Apply a function to the input object yielding an appropriate {@code int} + * value. + * + * @param t the input object + * @return the function result value + */ + public int applyAsInt(T t); +} diff --git a/src/share/classes/java/util/function/IntSupplier.java b/src/share/classes/java/util/function/IntSupplier.java new file mode 100644 index 0000000000000000000000000000000000000000..e930e0bc4078df9670fd42d818ed76edb2627401 --- /dev/null +++ b/src/share/classes/java/util/function/IntSupplier.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * A supplier of {@code int} values. + * + *

This is the primitive type specialization of {@link Supplier} for + * {@code int} and also may be used as a {@code Supplier}. + * + * @since 1.8 + */ +public interface IntSupplier { + + /** + * Returns an {@code int} value. + * + * @return an {@code int} value + */ + public int getAsInt(); +} diff --git a/src/share/classes/java/util/function/IntUnaryOperator.java b/src/share/classes/java/util/function/IntUnaryOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..315619dcab16744c5a44dc2c48830dfb381a6fd8 --- /dev/null +++ b/src/share/classes/java/util/function/IntUnaryOperator.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation on a single {@code int} operand yielding an {@code int} result. + * + * @since 1.8 + */ +public interface IntUnaryOperator { + + /** + * Returns the {@code int} result of the operation upon the {@code int} + * operand. + * + * @param operand the operand value + * @return the operation result value + */ + public int operateAsInt(int operand); +} diff --git a/src/share/classes/java/util/function/LongBinaryOperator.java b/src/share/classes/java/util/function/LongBinaryOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..07056784e344e78ccbc28d5dcddf24c8c30adaba --- /dev/null +++ b/src/share/classes/java/util/function/LongBinaryOperator.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation on two {@code long} operands yielding a {@code long} result. + * + * @since 1.8 + */ +public interface LongBinaryOperator { + + /** + * Returns the {@code long} result of the operation upon the {@code long} + * operands. The parameters are named {@code left} and {@code right} for + * operations where the order of parameters matters. + * + * @param left the left operand value + * @param right the right operand value + * @return the result of the operation + */ + public long operateAsLong(long left, long right); +} diff --git a/src/share/classes/java/util/function/LongBlock.java b/src/share/classes/java/util/function/LongBlock.java new file mode 100644 index 0000000000000000000000000000000000000000..fe1ef6508790b70d2827502199292d1490f8837e --- /dev/null +++ b/src/share/classes/java/util/function/LongBlock.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010, 2012 Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation upon a {@code long} input value. The operation may modify + * external state. + * + *

This is the primitive type specialization of {@link Block} for + * {@code long} and also may be used as a {@code Block}. + * + * @since 1.8 + */ +public interface LongBlock { + + /** + * Use the {@code long} input value in an operation which may modify + * external state. + * + * @param t the input value + */ + public void accept(long t); +} diff --git a/src/share/classes/java/util/function/LongFunction.java b/src/share/classes/java/util/function/LongFunction.java new file mode 100644 index 0000000000000000000000000000000000000000..449543d0764264492e1961a544037a1bde42d608 --- /dev/null +++ b/src/share/classes/java/util/function/LongFunction.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * Apply a function to the input object yielding an appropriate {@code long} + * value; this is the {@code long}-bearing specialization for {@link Function}. + * + * @param the type of input objects to the function + * + * @since 1.8 + */ +public interface LongFunction { + + /** + * Apply a function to the input object yielding an appropriate {@code long} + * value. + * + * @param t the input object + * @return the function result value + */ + public long applyAsLong(T t); +} diff --git a/src/share/classes/java/util/function/LongSupplier.java b/src/share/classes/java/util/function/LongSupplier.java new file mode 100644 index 0000000000000000000000000000000000000000..fb76068c9701836715caa07529e0489931227784 --- /dev/null +++ b/src/share/classes/java/util/function/LongSupplier.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * A supplier of {@code long} values. + * + *

This is the primitive type specialization of {@link Supplier} for + * {@code long} and also may be used as a {@code Supplier}. + * + * @since 1.8 + */ +public interface LongSupplier { + + /** + * Returns a {@code long} value. + * + * @return a {@code long} value. + */ + public long getAsLong(); +} diff --git a/src/share/classes/java/util/function/LongUnaryOperator.java b/src/share/classes/java/util/function/LongUnaryOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..ea2c1fc7338e0d09d27058ef010d9ba4321d3bd6 --- /dev/null +++ b/src/share/classes/java/util/function/LongUnaryOperator.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation on a single {@code long} operand yielding a {@code long} result. + * + * @since 1.8 + */ +public interface LongUnaryOperator { + + /** + * Returns the {@code long} result of the operation upon the {@code long} + * operand. + * + * @param operand the operand value + * @return the operation result value + */ + public long operateAsLong(long operand); +} diff --git a/src/share/classes/java/util/function/Predicate.java b/src/share/classes/java/util/function/Predicate.java new file mode 100644 index 0000000000000000000000000000000000000000..4fea49c5ac1d5b8cbff43f81c54e819c6fe71a52 --- /dev/null +++ b/src/share/classes/java/util/function/Predicate.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2010, 2012 Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * Determines if the input object matches some criteria. + * + * @param the type of input objects to {@code test} + * + * @since 1.8 + */ +public interface Predicate { + + /** + * Returns {@code true} if the input object matches some criteria. + * + * @param t the input object + * @return {@code true} if the input object matches some criteria, otherwise + * {@code false} + */ + public boolean test(T t); +} diff --git a/src/share/classes/java/util/function/Supplier.java b/src/share/classes/java/util/function/Supplier.java new file mode 100644 index 0000000000000000000000000000000000000000..404af55af99d03691bbca8ab9bc46897340ba704 --- /dev/null +++ b/src/share/classes/java/util/function/Supplier.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * A supplier of objects. The result objects are either created during the + * invocation of {@link #get} or by some prior action. + * + * @param The type of objects returned by {@code get} + * + * @since 1.8 + */ +public interface Supplier { + + /** + * Returns an object. + * + * @return an object + */ + public T get(); +} diff --git a/src/share/classes/java/util/function/UnaryOperator.java b/src/share/classes/java/util/function/UnaryOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..9fa99c8d96a983a25230d8882d499a3e32e92e45 --- /dev/null +++ b/src/share/classes/java/util/function/UnaryOperator.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * An operation upon a single operand yielding a result. The operand and the + * result are of the same type. + * + * @param the type of operand to {@code operate} and of the result + * + * @since 1.8 + */ +public interface UnaryOperator { + + /** + * Returns the result of the operation upon the operand. + * + * @param operand the operand + * @return the operation result + */ + public T operate(T operand); +} diff --git a/src/share/classes/java/util/function/package-info.java b/src/share/classes/java/util/function/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..0d1eecf5139693533c87c2b70e66d4286be82c8f --- /dev/null +++ b/src/share/classes/java/util/function/package-info.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * Functional interfaces provide typing for lambda expressions. Each + * functional interface provides a single abstract method to which the lambda + * expression's parameter and return types are matched. + * + *

The interfaces in this package are all functional interfaces used with the + * collections and streams frameworks. The operation identified by each + * interface is generally applied to a collection or stream of objects. + * + *

All functional interface implementations are expected to ensure that: + *

    + *
  • When used for aggregate operations upon many elements it should not be + * assumed that the operation will be called upon elements in any specific order. + *
  • + *
  • {@code null} values are accepted and returned by these functional + * interfaces according to the constraints of the specification in which the + * functional interfaces are used. The functional interfaces themselves do not + * constrain or mandate use of {@code null} values. Most usages of the + * functional interfaces will define the role, if any, of {@code null} for that + * context. + *
  • + *
+ */ +package java.util.function; diff --git a/src/share/classes/javax/net/ssl/HostnameVerifier.java b/src/share/classes/javax/net/ssl/HostnameVerifier.java index 402a8cd66a2ea2665f601778179050974762d0ec..49b3163a00d48e864a761f4b5b9b8108248e1f20 100644 --- a/src/share/classes/javax/net/ssl/HostnameVerifier.java +++ b/src/share/classes/javax/net/ssl/HostnameVerifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2012, Oracle and/or its affiliates. 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 @@ -40,7 +40,6 @@ package javax.net.ssl; * verification fail. * * @author Brad R. Wetmore - * @see HostnameVerifierFactory * @since 1.4 */ diff --git a/src/share/classes/javax/net/ssl/SNIHostName.java b/src/share/classes/javax/net/ssl/SNIHostName.java index 6f2092c662fa96fd2ddfb1de42dbdab01566d5e6..1d02104e1724d0f05f5c5393de707edf80565afb 100644 --- a/src/share/classes/javax/net/ssl/SNIHostName.java +++ b/src/share/classes/javax/net/ssl/SNIHostName.java @@ -135,7 +135,8 @@ public final class SNIHostName extends SNIServerName { * RFC 3490, * RFC 1122, * RFC 1123) - * for {@code encoded} argument, or use {@link SNIHostName(String)} instead. + * for {@code encoded} argument, or use + * {@link SNIHostName#SNIHostName(String)} instead. *

* The {@code encoded} argument is illegal if it: *