_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q179400
ThrowableHandler.add
test
public static void add(int type, Throwable t) { // don't add null throwables if (t == null) return; try { fireOnThrowable(type, t); } catch (Throwable bad) { // don't let these propagate, that could introduce unwanted side-effects System.err.println("Unable to handle throwable: " + t + " because of:"); bad.printStackTrace(); } }
java
{ "resource": "" }
q179401
LazyList.createImplementation
test
private List<T> createImplementation() { if (delegate instanceof ArrayList == false) return new ArrayList<T>(delegate); return delegate; }
java
{ "resource": "" }
q179402
TimerTask.compareTo
test
public int compareTo(Object other) { if (other == this) return 0; TimerTask t = (TimerTask) other; long diff = getNextExecutionTime() - t.getNextExecutionTime(); return (int) diff; }
java
{ "resource": "" }
q179403
InetAddressEditor.getValue
test
public Object getValue() { try { String text = getAsText(); if (text == null) { return null; } if (text.startsWith("/")) { // seems like localhost sometimes will look like: // /127.0.0.1 and the getByNames barfs on the slash - JGH text = text.substring(1); } return InetAddress.getByName(StringPropertyReplacer.replaceProperties(text)); } catch (UnknownHostException e) { throw new NestedRuntimeException(e); } }
java
{ "resource": "" }
q179404
CachedList.getObject
test
private Object getObject(final int index) { Object obj = list.get(index); return Objects.deref(obj); }
java
{ "resource": "" }
q179405
CachedList.set
test
public Object set(final int index, final Object obj) { maintain(); SoftObject soft = SoftObject.create(obj, queue); soft = (SoftObject)list.set(index, soft); return Objects.deref(soft); }
java
{ "resource": "" }
q179406
CachedList.maintain
test
private void maintain() { SoftObject obj; int count = 0; while ((obj = (SoftObject)queue.poll()) != null) { count++; list.remove(obj); } if (count != 0) { // some temporary debugging fluff System.err.println("vm reclaimed " + count + " objects"); } }
java
{ "resource": "" }
q179407
CatalogEntry.addEntryType
test
public static int addEntryType(String name, int numArgs) { entryTypes.put(name, new Integer(nextEntry)); entryArgs.add(nextEntry, new Integer(numArgs)); nextEntry++; return nextEntry-1; }
java
{ "resource": "" }
q179408
CatalogEntry.getEntryType
test
public static int getEntryType(String name) throws CatalogException { if (!entryTypes.containsKey(name)) { throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); } Integer iType = (Integer) entryTypes.get(name); if (iType == null) { throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); } return iType.intValue(); }
java
{ "resource": "" }
q179409
CatalogEntry.getEntryArgCount
test
public static int getEntryArgCount(int type) throws CatalogException { try { Integer iArgs = (Integer) entryArgs.get(type); return iArgs.intValue(); } catch (ArrayIndexOutOfBoundsException e) { throw new CatalogException(CatalogException.INVALID_ENTRY_TYPE); } }
java
{ "resource": "" }
q179410
CatalogEntry.getEntryArg
test
public String getEntryArg(int argNum) { try { String arg = (String) args.get(argNum); return arg; } catch (ArrayIndexOutOfBoundsException e) { return null; } }
java
{ "resource": "" }
q179411
ContextClassLoaderSwitcher.setContextClassLoader
test
public void setContextClassLoader(final Thread thread, final ClassLoader cl) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { thread.setContextClassLoader(cl); return null; } }); }
java
{ "resource": "" }
q179412
TimeoutPriorityQueueImpl.swap
test
private void swap(int a, int b) { // INV: assertExpr(a > 0); // INV: assertExpr(a <= size); // INV: assertExpr(b > 0); // INV: assertExpr(b <= size); // INV: assertExpr(queue[a] != null); // INV: assertExpr(queue[b] != null); // INV: assertExpr(queue[a].index == a); // INV: assertExpr(queue[b].index == b); TimeoutExtImpl temp = queue[a]; queue[a] = queue[b]; queue[a].index = a; queue[b] = temp; queue[b].index = b; }
java
{ "resource": "" }
q179413
TimeoutPriorityQueueImpl.removeNode
test
private TimeoutExtImpl removeNode(int index) { // INV: assertExpr(index > 0); // INV: assertExpr(index <= size); TimeoutExtImpl res = queue[index]; // INV: assertExpr(res != null); // INV: assertExpr(res.index == index); if (index == size) { --size; queue[index] = null; return res; } swap(index, size); // Exchange removed node with last leaf node --size; // INV: assertExpr(res.index == size + 1); queue[res.index] = null; if (normalizeUp(index)) return res; // Node moved up, so it shouldn't move down long t = queue[index].time; int c = index << 1; while (c <= size) { // INV: assertExpr(q[index].time == t); TimeoutExtImpl l = queue[c]; // INV: assertExpr(l != null); // INV: assertExpr(l.index == c); if (c + 1 <= size) { // two children, swap with smallest TimeoutExtImpl r = queue[c + 1]; // INV: assertExpr(r != null); // INV: assertExpr(r.index == c+1); if (l.time <= r.time) { if (t <= l.time) break; // done swap(index, c); index = c; } else { if (t <= r.time) break; // done swap(index, c + 1); index = c + 1; } } else { // one child if (t <= l.time) break; // done swap(index, c); index = c; } c = index << 1; } return res; }
java
{ "resource": "" }
q179414
TimeoutPriorityQueueImpl.cleanupTimeoutExtImpl
test
private TimeoutExtImpl cleanupTimeoutExtImpl(TimeoutExtImpl timeout) { if (timeout != null) timeout.target = null; return null; }
java
{ "resource": "" }
q179415
DelegatingClassLoader.loadClass
test
protected Class<?> loadClass(String className, boolean resolve) throws ClassNotFoundException { // Revert to standard rules if (standard) return super.loadClass(className, resolve); // Ask the parent Class<?> clazz = null; try { clazz = parent.loadClass(className); } catch (ClassNotFoundException e) { // Not found in parent, // maybe it is a proxy registered against this classloader? clazz = findLoadedClass(className); if (clazz == null) throw e; } // Link the class if (resolve) resolveClass(clazz); return clazz; }
java
{ "resource": "" }
q179416
URLStreamHandlerFactory.preload
test
@SuppressWarnings("unused") public static void preload() { for (int i = 0; i < PROTOCOLS.length; i ++) { try { URL url = new URL(PROTOCOLS[i], "", -1, ""); log.trace("Loaded protocol: " + PROTOCOLS[i]); } catch (Exception e) { log.warn("Failed to load protocol: " + PROTOCOLS[i], e); } } }
java
{ "resource": "" }
q179417
URLStreamHandlerFactory.createURLStreamHandler
test
public URLStreamHandler createURLStreamHandler(final String protocol) { // Check the handler map URLStreamHandler handler = (URLStreamHandler) handlerMap.get(protocol); if( handler != null ) return handler; // Validate that createURLStreamHandler is not recursing String prevProtocol = (String) createURLStreamHandlerProtocol.get(); if( prevProtocol != null && prevProtocol.equals(protocol) ) return null; createURLStreamHandlerProtocol.set(protocol); // See if the handler pkgs definition has changed checkHandlerPkgs(); // Search the handlerPkgs for a matching protocol handler ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader(); for(int p = 0; p < handlerPkgs.length; p ++) { try { // Form the standard protocol handler class name String classname = handlerPkgs[p] + "." + protocol + ".Handler"; Class<?> type = null; try { type = ctxLoader.loadClass(classname); } catch(ClassNotFoundException e) { // Try our class loader type = Class.forName(classname); } if( type != null ) { handler = (URLStreamHandler) type.newInstance(); handlerMap.put(protocol, handler); log.trace("Found protocol:"+protocol+" handler:"+handler); } } catch (Throwable ignore) { } } createURLStreamHandlerProtocol.set(null); return handler; }
java
{ "resource": "" }
q179418
URLStreamHandlerFactory.checkHandlerPkgs
test
private synchronized void checkHandlerPkgs() { String handlerPkgsProp = System.getProperty("java.protocol.handler.pkgs"); if( handlerPkgsProp != null && handlerPkgsProp.equals(lastHandlerPkgs) == false ) { // Update the handlerPkgs[] from the handlerPkgsProp StringTokenizer tokeninzer = new StringTokenizer(handlerPkgsProp, "|"); ArrayList<String> tmp = new ArrayList<String>(); while( tokeninzer.hasMoreTokens() ) { String pkg = tokeninzer.nextToken().intern(); if( tmp.contains(pkg) == false ) tmp.add(pkg); } // Include the JBoss default protocol handler pkg if( tmp.contains(PACKAGE_PREFIX) == false ) tmp.add(PACKAGE_PREFIX); handlerPkgs = new String[tmp.size()]; tmp.toArray(handlerPkgs); lastHandlerPkgs = handlerPkgsProp; } }
java
{ "resource": "" }
q179419
ClassEditor.getValue
test
public Object getValue() { try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); String classname = getAsText(); Class<?> type = loader.loadClass(classname); return type; } catch (Exception e) { throw new NestedRuntimeException(e); } }
java
{ "resource": "" }
q179420
LazySet.createImplementation
test
private Set<T> createImplementation() { if (delegate instanceof HashSet == false) return new HashSet<T>(delegate); return delegate; }
java
{ "resource": "" }
q179421
LongCounter.makeSynchronized
test
public static LongCounter makeSynchronized(final LongCounter counter) { return new Wrapper(counter) { /** The serialVersionUID */ private static final long serialVersionUID = 8903330696503363758L; public synchronized long increment() { return this.counter.increment(); } public synchronized long decrement() { return this.counter.decrement(); } public synchronized long getCount() { return this.counter.getCount(); } public synchronized void reset() { this.counter.reset(); } public synchronized int hashCode() { return this.counter.hashCode(); } public synchronized boolean equals(final Object obj) { return this.counter.equals(obj); } public synchronized String toString() { return this.counter.toString(); } public synchronized Object clone() { return this.counter.clone(); } }; }
java
{ "resource": "" }
q179422
LongCounter.makeDirectional
test
public static LongCounter makeDirectional(final LongCounter counter, final boolean increasing) { LongCounter temp; if (increasing) { temp = new Wrapper(counter) { /** The serialVersionUID */ private static final long serialVersionUID = -8902748795144754375L; public long decrement() { throw new UnsupportedOperationException(); } public void reset() { throw new UnsupportedOperationException(); } }; } else { temp = new Wrapper(counter) { /** The serialVersionUID */ private static final long serialVersionUID = 2584758778978644599L; public long increment() { throw new UnsupportedOperationException(); } }; } return temp; }
java
{ "resource": "" }
q179423
OASISXMLCatalogReader.inExtensionNamespace
test
protected boolean inExtensionNamespace() { boolean inExtension = false; Enumeration elements = namespaceStack.elements(); while (!inExtension && elements.hasMoreElements()) { String ns = (String) elements.nextElement(); if (ns == null) { inExtension = true; } else { inExtension = (!ns.equals(tr9401NamespaceName) && !ns.equals(namespaceName)); } } return inExtension; }
java
{ "resource": "" }
q179424
NotifyingBufferedOutputStream.checkNotification
test
public void checkNotification(int result) { // Is a notification required? chunk += result; if (chunk >= chunkSize) { if (listener != null) listener.onStreamNotification(this, chunk); // Start a new chunk chunk = 0; } }
java
{ "resource": "" }
q179425
NonSerializableFactory.rebind
test
public static synchronized void rebind(Name name, Object target, boolean createSubcontexts) throws NamingException { String key = name.toString(); InitialContext ctx = new InitialContext(); if (createSubcontexts == true && name.size() > 1) { int size = name.size() - 1; Util.createSubcontext(ctx, name.getPrefix(size)); } rebind(ctx, key, target); }
java
{ "resource": "" }
q179426
NonSerializableFactory.getObjectInstance
test
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws Exception { // Get the nns value from the Reference obj and use it as the map key Reference ref = (Reference) obj; RefAddr addr = ref.get("nns"); String key = (String) addr.getContent(); Object target = wrapperMap.get(key); return target; }
java
{ "resource": "" }
q179427
Strings.subst
test
public static String subst(final StringBuffer buff, final String string, final Map map, final String beginToken, final String endToken) { int begin = 0, rangeEnd = 0; Range range; while ((range = rangeOf(beginToken, endToken, string, rangeEnd)) != null) { // append the first part of the string buff.append(string.substring(begin, range.begin)); // Get the string to replace from the map String key = string.substring(range.begin + beginToken.length(), range.end); Object value = map.get(key); // if mapping does not exist then use empty; if (value == null) value = EMPTY; // append the replaced string buff.append(value); // update positions begin = range.end + endToken.length(); rangeEnd = begin; } // append the rest of the string buff.append(string.substring(begin, string.length())); return buff.toString(); }
java
{ "resource": "" }
q179428
Strings.split
test
public static String[] split(final String string, final String delim, final int limit) { // get the count of delim in string, if count is > limit // then use limit for count. The number of delimiters is less by one // than the number of elements, so add one to count. int count = count(string, delim) + 1; if (limit > 0 && count > limit) { count = limit; } String strings[] = new String[count]; int begin = 0; for (int i = 0; i < count; i++) { // get the next index of delim int end = string.indexOf(delim, begin); // if the end index is -1 or if this is the last element // then use the string's length for the end index if (end == -1 || i + 1 == count) end = string.length(); // if end is 0, then the first element is empty if (end == 0) strings[i] = EMPTY; else strings[i] = string.substring(begin, end); // update the begining index begin = end + 1; } return strings; }
java
{ "resource": "" }
q179429
Strings.join
test
public static String join(final byte array[]) { Byte bytes[] = new Byte[array.length]; for (int i = 0; i < bytes.length; i++) { bytes[i] = new Byte(array[i]); } return join(bytes, null); }
java
{ "resource": "" }
q179430
Strings.defaultToString
test
public static final void defaultToString(JBossStringBuilder buffer, Object object) { if (object == null) buffer.append("null"); else { buffer.append(object.getClass().getName()); buffer.append('@'); buffer.append(Integer.toHexString(System.identityHashCode(object))); } }
java
{ "resource": "" }
q179431
BlockingModeEditor.getValue
test
public Object getValue() { String text = getAsText(); BlockingMode mode = BlockingMode.toBlockingMode(text); return mode; }
java
{ "resource": "" }
q179432
TimedCachePolicy.create
test
public void create() { if( threadSafe ) entryMap = Collections.synchronizedMap(new HashMap()); else entryMap = new HashMap(); now = System.currentTimeMillis(); }
java
{ "resource": "" }
q179433
TimedCachePolicy.get
test
public Object get(Object key) { TimedEntry entry = (TimedEntry) entryMap.get(key); if( entry == null ) return null; if( entry.isCurrent(now) == false ) { // Try to refresh the entry if( entry.refresh() == false ) { // Failed, remove the entry and return null entry.destroy(); entryMap.remove(key); return null; } } Object value = entry.getValue(); return value; }
java
{ "resource": "" }
q179434
TimedCachePolicy.peek
test
public Object peek(Object key) { TimedEntry entry = (TimedEntry) entryMap.get(key); Object value = null; if( entry != null ) value = entry.getValue(); return value; }
java
{ "resource": "" }
q179435
TimedCachePolicy.remove
test
public void remove(Object key) { TimedEntry entry = (TimedEntry) entryMap.remove(key); if( entry != null ) entry.destroy(); }
java
{ "resource": "" }
q179436
TimedCachePolicy.flush
test
public void flush() { Map tmpMap = null; synchronized( this ) { tmpMap = entryMap; if( threadSafe ) entryMap = Collections.synchronizedMap(new HashMap()); else entryMap = new HashMap(); } // Notify the entries of their removal Iterator iter = tmpMap.values().iterator(); while( iter.hasNext() ) { TimedEntry entry = (TimedEntry) iter.next(); entry.destroy(); } tmpMap.clear(); }
java
{ "resource": "" }
q179437
TimedCachePolicy.getValidKeys
test
public List getValidKeys() { ArrayList validKeys = new ArrayList(); synchronized( entryMap ) { Iterator iter = entryMap.entrySet().iterator(); while( iter.hasNext() ) { Map.Entry entry = (Map.Entry) iter.next(); TimedEntry value = (TimedEntry) entry.getValue(); if( value.isCurrent(now) == true ) validKeys.add(entry.getKey()); } } return validKeys; }
java
{ "resource": "" }
q179438
TimedCachePolicy.setResolution
test
public synchronized void setResolution(int resolution) { if( resolution <= 0 ) resolution = 60; if( resolution != this.resolution ) { this.resolution = resolution; theTimer.cancel(); theTimer = new ResolutionTimer(); resolutionTimer.scheduleAtFixedRate(theTimer, 0, 1000*resolution); } }
java
{ "resource": "" }
q179439
TimedCachePolicy.peekEntry
test
public TimedEntry peekEntry(Object key) { TimedEntry entry = (TimedEntry) entryMap.get(key); return entry; }
java
{ "resource": "" }
q179440
XmlHelper.getChildrenByTagName
test
public static Iterator getChildrenByTagName(Element element, String tagName) { if (element == null) return null; // getElementsByTagName gives the corresponding elements in the whole // descendance. We want only children NodeList children = element.getChildNodes(); ArrayList goodChildren = new ArrayList(); for (int i=0; i<children.getLength(); i++) { Node currentChild = children.item(i); if (currentChild.getNodeType() == Node.ELEMENT_NODE && ((Element)currentChild).getTagName().equals(tagName)) { goodChildren.add(currentChild); } } return goodChildren.iterator(); }
java
{ "resource": "" }
q179441
XmlHelper.getUniqueChild
test
public static Element getUniqueChild(Element element, String tagName) throws Exception { Iterator goodChildren = getChildrenByTagName(element, tagName); if (goodChildren != null && goodChildren.hasNext()) { Element child = (Element)goodChildren.next(); if (goodChildren.hasNext()) { throw new Exception ("expected only one " + tagName + " tag"); } return child; } else { throw new Exception ("expected one " + tagName + " tag"); } }
java
{ "resource": "" }
q179442
XmlHelper.getOptionalChild
test
public static Element getOptionalChild(Element element, String tagName) throws Exception { return getOptionalChild(element, tagName, null); }
java
{ "resource": "" }
q179443
XmlHelper.getElementContent
test
public static String getElementContent(Element element, String defaultStr) throws Exception { if (element == null) return defaultStr; NodeList children = element.getChildNodes(); String result = ""; for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.TEXT_NODE || children.item(i).getNodeType() == Node.CDATA_SECTION_NODE) { result += children.item(i).getNodeValue(); } else if( children.item(i).getNodeType() == Node.COMMENT_NODE ) { // Ignore comment nodes } } return result.trim(); }
java
{ "resource": "" }
q179444
XmlHelper.getUniqueChildContent
test
public static String getUniqueChildContent(Element element, String tagName) throws Exception { return getElementContent(getUniqueChild(element, tagName)); }
java
{ "resource": "" }
q179445
XmlHelper.getOptionalChildContent
test
public static String getOptionalChildContent(Element element, String tagName) throws Exception { return getElementContent(getOptionalChild(element, tagName)); }
java
{ "resource": "" }
q179446
BasicThreadPool.setMaximumQueueSize
test
public void setMaximumQueueSize(int size) { // Reset the executor work queue ArrayList tmp = new ArrayList(); queue.drainTo(tmp); queue = new LinkedBlockingQueue(size); queue.addAll(tmp); ThreadFactory tf = executor.getThreadFactory(); RejectedExecutionHandler handler = executor.getRejectedExecutionHandler(); long keepAlive = executor.getKeepAliveTime(TimeUnit.SECONDS); int cs = executor.getCorePoolSize(); int mcs = executor.getMaximumPoolSize(); executor = new ThreadPoolExecutor(cs, mcs, keepAlive, TimeUnit.SECONDS, queue); executor.setThreadFactory(tf); executor.setRejectedExecutionHandler(handler); }
java
{ "resource": "" }
q179447
BasicThreadPool.setBlockingMode
test
public void setBlockingMode(String name) { blockingMode = BlockingMode.toBlockingMode(name); if( blockingMode == null ) blockingMode = BlockingMode.ABORT; }
java
{ "resource": "" }
q179448
BasicThreadPool.setBlockingModeString
test
public void setBlockingModeString(String name) { blockingMode = BlockingMode.toBlockingMode(name); if( blockingMode == null ) blockingMode = BlockingMode.ABORT; }
java
{ "resource": "" }
q179449
BasicThreadPool.execute
test
protected void execute(TaskWrapper wrapper) { if( trace ) log.trace("execute, wrapper="+wrapper); try { executor.execute(wrapper); } catch (Throwable t) { wrapper.rejectTask(new ThreadPoolFullException("Error scheduling work: " + wrapper, t)); } }
java
{ "resource": "" }
q179450
Resolver.resolveSystem
test
public String resolveSystem(String systemId) throws MalformedURLException, IOException { String resolved = super.resolveSystem(systemId); if (resolved != null) { return resolved; } Enumeration enumt = catalogEntries.elements(); while (enumt.hasMoreElements()) { CatalogEntry e = (CatalogEntry) enumt.nextElement(); if (e.getEntryType() == RESOLVER) { resolved = resolveExternalSystem(systemId, e.getEntryArg(0)); if (resolved != null) { return resolved; } } else if (e.getEntryType() == SYSTEMSUFFIX) { String suffix = e.getEntryArg(0); String result = e.getEntryArg(1); if (suffix.length() <= systemId.length() && systemId.substring(systemId.length()-suffix.length()).equals(suffix)) { return result; } } } return resolveSubordinateCatalogs(Catalog.SYSTEM, null, null, systemId); }
java
{ "resource": "" }
q179451
Resolver.resolvePublic
test
public String resolvePublic(String publicId, String systemId) throws MalformedURLException, IOException { String resolved = super.resolvePublic(publicId, systemId); if (resolved != null) { return resolved; } Enumeration enumt = catalogEntries.elements(); while (enumt.hasMoreElements()) { CatalogEntry e = (CatalogEntry) enumt.nextElement(); if (e.getEntryType() == RESOLVER) { if (systemId != null) { resolved = resolveExternalSystem(systemId, e.getEntryArg(0)); if (resolved != null) { return resolved; } } resolved = resolveExternalPublic(publicId, e.getEntryArg(0)); if (resolved != null) { return resolved; } } } return resolveSubordinateCatalogs(Catalog.PUBLIC, null, publicId, systemId); }
java
{ "resource": "" }
q179452
Resolver.resolveExternalSystem
test
protected String resolveExternalSystem(String systemId, String resolver) throws MalformedURLException, IOException { Resolver r = queryResolver(resolver, "i2l", systemId, null); if (r != null) { return r.resolveSystem(systemId); } else { return null; } }
java
{ "resource": "" }
q179453
Resolver.resolveExternalPublic
test
protected String resolveExternalPublic(String publicId, String resolver) throws MalformedURLException, IOException { Resolver r = queryResolver(resolver, "fpi2l", publicId, null); if (r != null) { return r.resolvePublic(publicId, null); } else { return null; } }
java
{ "resource": "" }
q179454
Resolver.queryResolver
test
protected Resolver queryResolver(String resolver, String command, String arg1, String arg2) { String RFC2483 = resolver + "?command=" + command + "&format=tr9401&uri=" + arg1 + "&uri2=" + arg2; try { URL url = new URL(RFC2483); URLConnection urlCon = url.openConnection(); urlCon.setUseCaches(false); Resolver r = (Resolver) newCatalog(); String cType = urlCon.getContentType(); // I don't care about the character set or subtype if (cType.indexOf(";") > 0) { cType = cType.substring(0, cType.indexOf(";")); } r.parseCatalog(cType, urlCon.getInputStream()); return r; } catch (CatalogException cex) { if (cex.getExceptionType() == CatalogException.UNPARSEABLE) { catalogManager.debug.message(1, "Unparseable catalog: " + RFC2483); } else if (cex.getExceptionType() == CatalogException.UNKNOWN_FORMAT) { catalogManager.debug.message(1, "Unknown catalog format: " + RFC2483); } return null; } catch (MalformedURLException mue) { catalogManager.debug.message(1, "Malformed resolver URL: " + RFC2483); return null; } catch (IOException ie) { catalogManager.debug.message(1, "I/O Exception opening resolver: " + RFC2483); return null; } }
java
{ "resource": "" }
q179455
Resolver.appendVector
test
private Vector appendVector(Vector vec, Vector appvec) { if (appvec != null) { for (int count = 0; count < appvec.size(); count++) { vec.addElement(appvec.elementAt(count)); } } return vec; }
java
{ "resource": "" }
q179456
Resolver.resolveAllSystemReverse
test
public Vector resolveAllSystemReverse(String systemId) throws MalformedURLException, IOException { Vector resolved = new Vector(); // If there's a SYSTEM entry in this catalog, use it if (systemId != null) { Vector localResolved = resolveLocalSystemReverse(systemId); resolved = appendVector(resolved, localResolved); } // Otherwise, look in the subordinate catalogs Vector subResolved = resolveAllSubordinateCatalogs(SYSTEMREVERSE, null, null, systemId); return appendVector(resolved, subResolved); }
java
{ "resource": "" }
q179457
Resolver.resolveSystemReverse
test
public String resolveSystemReverse(String systemId) throws MalformedURLException, IOException { Vector resolved = resolveAllSystemReverse(systemId); if (resolved != null && resolved.size() > 0) { return (String) resolved.elementAt(0); } else { return null; } }
java
{ "resource": "" }
q179458
Resolver.resolveAllSystem
test
public Vector resolveAllSystem(String systemId) throws MalformedURLException, IOException { Vector resolutions = new Vector(); // If there are SYSTEM entries in this catalog, start with them if (systemId != null) { Vector localResolutions = resolveAllLocalSystem(systemId); resolutions = appendVector(resolutions, localResolutions); } // Then look in the subordinate catalogs Vector subResolutions = resolveAllSubordinateCatalogs(SYSTEM, null, null, systemId); resolutions = appendVector(resolutions, subResolutions); if (resolutions.size() > 0) { return resolutions; } else { return null; } }
java
{ "resource": "" }
q179459
Resolver.resolveAllLocalSystem
test
private Vector resolveAllLocalSystem(String systemId) { Vector map = new Vector(); String osname = System.getProperty("os.name"); boolean windows = (osname.indexOf("Windows") >= 0); Enumeration enumt = catalogEntries.elements(); while (enumt.hasMoreElements()) { CatalogEntry e = (CatalogEntry) enumt.nextElement(); if (e.getEntryType() == SYSTEM && (e.getEntryArg(0).equals(systemId) || (windows && e.getEntryArg(0).equalsIgnoreCase(systemId)))) { map.addElement(e.getEntryArg(1)); } } if (map.size() == 0) { return null; } else { return map; } }
java
{ "resource": "" }
q179460
Resolver.resolveAllSubordinateCatalogs
test
private synchronized Vector resolveAllSubordinateCatalogs(int entityType, String entityName, String publicId, String systemId) throws MalformedURLException, IOException { Vector resolutions = new Vector(); for (int catPos = 0; catPos < catalogs.size(); catPos++) { Resolver c = null; try { c = (Resolver) catalogs.elementAt(catPos); } catch (ClassCastException e) { String catfile = (String) catalogs.elementAt(catPos); c = (Resolver) newCatalog(); try { c.parseCatalog(catfile); } catch (MalformedURLException mue) { catalogManager.debug.message(1, "Malformed Catalog URL", catfile); } catch (FileNotFoundException fnfe) { catalogManager.debug.message(1, "Failed to load catalog, file not found", catfile); } catch (IOException ioe) { catalogManager.debug.message(1, "Failed to load catalog, I/O error", catfile); } catalogs.setElementAt(c, catPos); } String resolved = null; // Ok, now what are we supposed to call here? if (entityType == DOCTYPE) { resolved = c.resolveDoctype(entityName, publicId, systemId); if (resolved != null) { // Only find one DOCTYPE resolution resolutions.addElement(resolved); return resolutions; } } else if (entityType == DOCUMENT) { resolved = c.resolveDocument(); if (resolved != null) { // Only find one DOCUMENT resolution resolutions.addElement(resolved); return resolutions; } } else if (entityType == ENTITY) { resolved = c.resolveEntity(entityName, publicId, systemId); if (resolved != null) { // Only find one ENTITY resolution resolutions.addElement(resolved); return resolutions; } } else if (entityType == NOTATION) { resolved = c.resolveNotation(entityName, publicId, systemId); if (resolved != null) { // Only find one NOTATION resolution resolutions.addElement(resolved); return resolutions; } } else if (entityType == PUBLIC) { resolved = c.resolvePublic(publicId, systemId); if (resolved != null) { // Only find one PUBLIC resolution resolutions.addElement(resolved); return resolutions; } } else if (entityType == SYSTEM) { Vector localResolutions = c.resolveAllSystem(systemId); resolutions = appendVector(resolutions, localResolutions); break; } else if (entityType == SYSTEMREVERSE) { Vector localResolutions = c.resolveAllSystemReverse(systemId); resolutions = appendVector(resolutions, localResolutions); } } if (resolutions != null) { return resolutions; } else { return null; } }
java
{ "resource": "" }
q179461
SAXCatalogReader.readCatalog
test
public void readCatalog(Catalog catalog, String fileUrl) throws MalformedURLException, IOException, CatalogException { URL url = null; try { url = new URL(fileUrl); } catch (MalformedURLException e) { url = new URL("file:///" + fileUrl); } debug = catalog.getCatalogManager().debug; try { URLConnection urlCon = url.openConnection(); readCatalog(catalog, urlCon.getInputStream()); } catch (FileNotFoundException e) { catalog.getCatalogManager().debug.message(1, "Failed to load catalog, file not found", url.toString()); } }
java
{ "resource": "" }
q179462
SAXCatalogReader.readCatalog
test
public void readCatalog(Catalog catalog, InputStream is) throws IOException, CatalogException { // Create an instance of the parser if (parserFactory == null && parserClass == null) { debug.message(1, "Cannot read SAX catalog without a parser"); throw new CatalogException(CatalogException.UNPARSEABLE); } debug = catalog.getCatalogManager().debug; EntityResolver bResolver = catalog.getCatalogManager().getBootstrapResolver(); this.catalog = catalog; try { if (parserFactory != null) { SAXParser parser = parserFactory.newSAXParser(); SAXParserHandler spHandler = new SAXParserHandler(); spHandler.setContentHandler(this); if (bResolver != null) { spHandler.setEntityResolver(bResolver); } parser.parse(new InputSource(is), spHandler); } else { Parser parser = (Parser) Class.forName(parserClass).newInstance(); parser.setDocumentHandler(this); if (bResolver != null) { parser.setEntityResolver(bResolver); } parser.parse(new InputSource(is)); } } catch (ClassNotFoundException cnfe) { throw new CatalogException(CatalogException.UNPARSEABLE); } catch (IllegalAccessException iae) { throw new CatalogException(CatalogException.UNPARSEABLE); } catch (InstantiationException ie) { throw new CatalogException(CatalogException.UNPARSEABLE); } catch (ParserConfigurationException pce) { throw new CatalogException(CatalogException.UNKNOWN_FORMAT); } catch (SAXException se) { Exception e = se.getException(); // FIXME: there must be a better way UnknownHostException uhe = new UnknownHostException(); FileNotFoundException fnfe = new FileNotFoundException(); if (e != null) { if (e.getClass() == uhe.getClass()) { throw new CatalogException(CatalogException.PARSE_FAILED, e.toString()); } else if (e.getClass() == fnfe.getClass()) { throw new CatalogException(CatalogException.PARSE_FAILED, e.toString()); } } throw new CatalogException(se); } }
java
{ "resource": "" }
q179463
FileURLConnection.connect
test
public void connect() throws IOException { if (connected) return; if (!file.exists()) { throw new FileNotFoundException(file.getPath()); } connected = true; }
java
{ "resource": "" }
q179464
FileURLConnection.getOutputStream
test
public OutputStream getOutputStream() throws IOException { connect(); SecurityManager sm = System.getSecurityManager(); if (sm != null) { // Check for write access FilePermission p = new FilePermission(file.getPath(), "write"); sm.checkPermission(p); } return new FileOutputStream(file); }
java
{ "resource": "" }
q179465
Node.casNext
test
boolean casNext(Node<K,V> cmp, Node<K,V> val) { return nextUpdater.compareAndSet(this, cmp, val); }
java
{ "resource": "" }
q179466
Node.helpDelete
test
void helpDelete(Node<K,V> b, Node<K,V> f) { /* * Rechecking links and then doing only one of the * help-out stages per call tends to minimize CAS * interference among helping threads. */ if (f == next && this == b.next) { if (f == null || f.value != f) // not already marked appendMarker(f); else b.casNext(this, f.next); } }
java
{ "resource": "" }
q179467
Node.getValidValue
test
V getValidValue() { Object v = value; if (v == this || v == BASE_HEADER) return null; return (V)v; }
java
{ "resource": "" }
q179468
Node.createSnapshot
test
SnapshotEntry<K,V> createSnapshot() { V v = getValidValue(); if (v == null) return null; return new SnapshotEntry(key, v); }
java
{ "resource": "" }
q179469
Index.casRight
test
final boolean casRight(Index<K,V> cmp, Index<K,V> val) { return rightUpdater.compareAndSet(this, cmp, val); }
java
{ "resource": "" }
q179470
JBossObject.createLog
test
private Logger createLog() { Class<?> clazz = getClass(); Logger logger = loggers.get(clazz); if (logger == null) { logger = Logger.getLogger(clazz); loggers.put(clazz, logger); } return logger; }
java
{ "resource": "" }
q179471
JBossObject.list
test
public static void list(JBossStringBuilder buffer, Collection objects) { if (objects == null) return; buffer.append('['); if (objects.isEmpty() == false) { for (Iterator i = objects.iterator(); i.hasNext();) { Object object = i.next(); if (object instanceof JBossObject) ((JBossObject) object).toShortString(buffer); else buffer.append(object.toString()); if (i.hasNext()) buffer.append(", "); } } buffer.append(']'); }
java
{ "resource": "" }
q179472
JBossObject.getClassShortName
test
public String getClassShortName() { String longName = getClass().getName(); int dot = longName.lastIndexOf('.'); if (dot != -1) return longName.substring(dot + 1); return longName; }
java
{ "resource": "" }
q179473
JBossObject.toStringImplementation
test
protected String toStringImplementation() { JBossStringBuilder buffer = new JBossStringBuilder(); buffer.append(getClassShortName()).append('@'); buffer.append(Integer.toHexString(System.identityHashCode(this))); buffer.append('{'); toString(buffer); buffer.append('}'); return buffer.toString(); }
java
{ "resource": "" }
q179474
PropertyManager.names
test
public static Iterator names() { SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkPropertiesAccess(); return props.names(); }
java
{ "resource": "" }
q179475
PropertyManager.getPropertyGroup
test
public static PropertyGroup getPropertyGroup(final String basename) { SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkPropertiesAccess(); return props.getPropertyGroup(basename); }
java
{ "resource": "" }
q179476
Objects.getCompatibleConstructor
test
public static Constructor getCompatibleConstructor(final Class type, final Class valueType) { // first try and find a constructor with the exact argument type try { return type.getConstructor(new Class[] { valueType }); } catch (Exception ignore) { // if the above failed, then try and find a constructor with // an compatible argument type // get an array of compatible types Class[] types = type.getClasses(); for (int i=0; i<types.length; i++) { try { return type.getConstructor(new Class[] { types[i] }); } catch (Exception ignore2) {} } } // if we get this far, then we can't find a compatible constructor return null; }
java
{ "resource": "" }
q179477
Objects.copy
test
public static Object copy(final Serializable obj) throws IOException, ClassNotFoundException { ObjectOutputStream out = null; ObjectInputStream in = null; Object copy = null; try { // write the object ByteArrayOutputStream baos = new ByteArrayOutputStream(); out = new ObjectOutputStream(baos); out.writeObject(obj); out.flush(); // read in the copy byte data[] = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(data); in = new ObjectInputStream(bais); copy = in.readObject(); } finally { Streams.close(out); Streams.close(in); } return copy; }
java
{ "resource": "" }
q179478
Objects.deref
test
public static <T> T deref(final Object obj, Class<T> expected) { Object result = deref(obj); if (result == null) return null; return expected.cast(result); }
java
{ "resource": "" }
q179479
PropertyMap.init
test
private void init() { unboundListeners = Collections.synchronizedList(new ArrayList()); boundListeners = Collections.synchronizedMap(new HashMap()); jndiMap = new HashMap(); PrivilegedAction action = new PrivilegedAction() { public Object run() { Object value = System.getProperty(Context.PROVIDER_URL); if (value == null) value = NULL_VALUE; jndiMap.put(Context.PROVIDER_URL, value); value = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); if (value == null) value = NULL_VALUE; jndiMap.put(Context.INITIAL_CONTEXT_FACTORY, value); value = System.getProperty(Context.OBJECT_FACTORIES); if (value == null) value = NULL_VALUE; jndiMap.put(Context.OBJECT_FACTORIES, value); value = System.getProperty(Context.URL_PKG_PREFIXES); if (value == null) value = NULL_VALUE; jndiMap.put(Context.URL_PKG_PREFIXES, value); value = System.getProperty(Context.STATE_FACTORIES); if (value == null) value = NULL_VALUE; jndiMap.put(Context.STATE_FACTORIES, value); value = System.getProperty(Context.DNS_URL); if (value == null) value = NULL_VALUE; jndiMap.put(Context.DNS_URL, value); value = System.getProperty(LdapContext.CONTROL_FACTORIES); if (value == null) value = NULL_VALUE; jndiMap.put(LdapContext.CONTROL_FACTORIES, value); return null; } }; AccessController.doPrivileged(action); }
java
{ "resource": "" }
q179480
PropertyMap.updateJndiCache
test
private void updateJndiCache(String name, String value) { if( name == null ) return; boolean isJndiProperty = name.equals(Context.PROVIDER_URL) || name.equals(Context.INITIAL_CONTEXT_FACTORY) || name.equals(Context.OBJECT_FACTORIES) || name.equals(Context.URL_PKG_PREFIXES) || name.equals(Context.STATE_FACTORIES) || name.equals(Context.DNS_URL) || name.equals(LdapContext.CONTROL_FACTORIES) ; if( isJndiProperty == true ) jndiMap.put(name, value); }
java
{ "resource": "" }
q179481
PropertyMap.keySet
test
public Set keySet(final boolean includeDefaults) { if (includeDefaults) { Set set = new HashSet(); set.addAll(defaults.keySet()); set.addAll(super.keySet()); return Collections.synchronizedSet(set); } return super.keySet(); }
java
{ "resource": "" }
q179482
PropertyMap.entrySet
test
public Set entrySet(final boolean includeDefaults) { if (includeDefaults) { Set set = new HashSet(); set.addAll(defaults.entrySet()); set.addAll(super.entrySet()); return Collections.synchronizedSet(set); } return super.entrySet(); }
java
{ "resource": "" }
q179483
PropertyMap.removePropertyListener
test
public boolean removePropertyListener(PropertyListener listener) { if (listener == null) throw new NullArgumentException("listener"); boolean removed = false; if (listener instanceof BoundPropertyListener) { removed = removePropertyListener((BoundPropertyListener) listener); } else { removed = unboundListeners.remove(listener); } return removed; }
java
{ "resource": "" }
q179484
PropertyMap.firePropertyAdded
test
private void firePropertyAdded(List list, PropertyEvent event) { if (list == null) return; int size = list.size(); for (int i = 0; i < size; i++) { PropertyListener listener = (PropertyListener) list.get(i); listener.propertyAdded(event); } }
java
{ "resource": "" }
q179485
PropertyMap.firePropertyRemoved
test
private void firePropertyRemoved(List list, PropertyEvent event) { if (list == null) return; int size = list.size(); for (int i = 0; i < size; i++) { PropertyListener listener = (PropertyListener) list.get(i); listener.propertyRemoved(event); } }
java
{ "resource": "" }
q179486
PropertyMap.firePropertyChanged
test
private void firePropertyChanged(List list, PropertyEvent event) { if (list == null) return; int size = list.size(); for (int i = 0; i < size; i++) { PropertyListener listener = (PropertyListener) list.get(i); listener.propertyChanged(event); } }
java
{ "resource": "" }
q179487
PropertyMap.firePropertyChanged
test
protected void firePropertyChanged(PropertyEvent event) { // fire all bound listeners (if any) first if (boundListeners != null) { List list = (List) boundListeners.get(event.getPropertyName()); if (list != null) { firePropertyChanged(list, event); } } // next fire all unbound listeners firePropertyChanged(unboundListeners, event); }
java
{ "resource": "" }
q179488
PropertyMap.makePrefixedPropertyName
test
protected String makePrefixedPropertyName(String base, String prefix) { String name = base; if (prefix != null) { StringBuffer buff = new StringBuffer(base); if (prefix != null) { buff.insert(0, PROPERTY_NAME_SEPARATOR); buff.insert(0, prefix); } return buff.toString(); } return name; }
java
{ "resource": "" }
q179489
PropertyMap.load
test
public void load(PropertyReader reader) throws PropertyException, IOException { if (reader == null) throw new NullArgumentException("reader"); load(reader.readProperties()); }
java
{ "resource": "" }
q179490
PropertyMap.load
test
public void load(String className) throws PropertyException, IOException { if (className == null) throw new NullArgumentException("className"); PropertyReader reader = null; try { Class type = Class.forName(className); reader = (PropertyReader) type.newInstance(); } catch (Exception e) { throw new PropertyException(e); } // load the properties from the source load(reader); }
java
{ "resource": "" }
q179491
PropertyMap.getPropertyGroup
test
public PropertyGroup getPropertyGroup(String basename, int index) { String name = makeIndexPropertyName(basename, index); return getPropertyGroup(name); }
java
{ "resource": "" }
q179492
JBossEntityResolver.isEntityResolved
test
public boolean isEntityResolved() { Boolean value = entityResolved.get(); return value != null ? value.booleanValue() : false; }
java
{ "resource": "" }
q179493
JBossEntityResolver.resolveSystemID
test
protected InputSource resolveSystemID(String systemId, boolean trace) { if( systemId == null ) return null; if( trace ) log.trace("resolveSystemID, systemId="+systemId); InputSource inputSource = null; // Try to resolve the systemId as an entity key String filename = null; if( localEntities != null ) filename = (String) localEntities.get(systemId); if( filename == null ) filename = (String) entities.get(systemId); if ( filename != null ) { if( trace ) log.trace("Found entity systemId=" + systemId + " fileName=" + filename); InputStream ins = loadClasspathResource(filename, trace); if( ins != null ) { inputSource = new InputSource(ins); inputSource.setSystemId(systemId); } else { log.warn("Cannot load systemId from resource: " + filename); } } return inputSource; }
java
{ "resource": "" }
q179494
JBossEntityResolver.resolveSystemIDasURL
test
protected InputSource resolveSystemIDasURL(String systemId, boolean trace) { if( systemId == null ) return null; if( trace ) log.trace("resolveSystemIDasURL, systemId="+systemId); InputSource inputSource = null; // Try to use the systemId as a URL to the schema try { if (trace) log.trace("Trying to resolve systemId as a URL"); // Replace any system property refs if isReplaceSystemProperties is true if(isReplaceSystemProperties()) systemId = StringPropertyReplacer.replaceProperties(systemId); URL url = new URL(systemId); if (warnOnNonFileURLs && url.getProtocol().equalsIgnoreCase("file") == false && url.getProtocol().equalsIgnoreCase("vfszip") == false) { log.warn("Trying to resolve systemId as a non-file URL: " + systemId); } InputStream ins = url.openStream(); if (ins != null) { inputSource = new InputSource(ins); inputSource.setSystemId(systemId); } else { log.warn("Cannot load systemId as URL: " + systemId); } if (trace) log.trace("Resolved systemId as a URL"); } catch (MalformedURLException ignored) { if (trace) log.trace("SystemId is not a url: " + systemId, ignored); } catch (IOException e) { if (trace) log.trace("Failed to obtain URL.InputStream from systemId: " + systemId, e); } return inputSource; }
java
{ "resource": "" }
q179495
JBossEntityResolver.resolveClasspathName
test
protected InputSource resolveClasspathName(String systemId, boolean trace) { if( systemId == null ) return null; if( trace ) log.trace("resolveClasspathName, systemId="+systemId); String filename = systemId; // Parse the systemId as a uri to get the final path component try { URI url = new URI(systemId); String path = url.getPath(); if( path == null ) path = url.getSchemeSpecificPart(); int slash = path.lastIndexOf('/'); if( slash >= 0 ) filename = path.substring(slash + 1); else filename = path; if(filename.length() == 0) return null; if (trace) log.trace("Mapped systemId to filename: " + filename); } catch (URISyntaxException e) { if (trace) log.trace("systemId: is not a URI, using systemId as resource", e); } // Resolve the filename as a classpath resource InputStream is = loadClasspathResource(filename, trace); InputSource inputSource = null; if( is != null ) { inputSource = new InputSource(is); inputSource.setSystemId(systemId); } return inputSource; }
java
{ "resource": "" }
q179496
ElementEditor.setAsText
test
public void setAsText(String text) { Document d = getAsDocument(text); setValue(d.getDocumentElement()); }
java
{ "resource": "" }
q179497
PublicId.normalize
test
public static String normalize(String publicId) { String normal = publicId.replace('\t', ' '); normal = normal.replace('\r', ' '); normal = normal.replace('\n', ' '); normal = normal.trim(); int pos; while ((pos = normal.indexOf(" ")) >= 0) { normal = normal.substring(0, pos) + normal.substring(pos+1); } return normal; }
java
{ "resource": "" }
q179498
PublicId.encodeURN
test
public static String encodeURN(String publicId) { String urn = PublicId.normalize(publicId); urn = PublicId.stringReplace(urn, "%", "%25"); urn = PublicId.stringReplace(urn, ";", "%3B"); urn = PublicId.stringReplace(urn, "'", "%27"); urn = PublicId.stringReplace(urn, "?", "%3F"); urn = PublicId.stringReplace(urn, "#", "%23"); urn = PublicId.stringReplace(urn, "+", "%2B"); urn = PublicId.stringReplace(urn, " ", "+"); urn = PublicId.stringReplace(urn, "::", ";"); urn = PublicId.stringReplace(urn, ":", "%3A"); urn = PublicId.stringReplace(urn, "//", ":"); urn = PublicId.stringReplace(urn, "/", "%2F"); return "urn:publicid:" + urn; }
java
{ "resource": "" }
q179499
PublicId.decodeURN
test
public static String decodeURN(String urn) { String publicId = ""; if (urn.startsWith("urn:publicid:")) { publicId = urn.substring(13); } else { return urn; } publicId = PublicId.stringReplace(publicId, "%2F", "/"); publicId = PublicId.stringReplace(publicId, ":", "//"); publicId = PublicId.stringReplace(publicId, "%3A", ":"); publicId = PublicId.stringReplace(publicId, ";", "::"); publicId = PublicId.stringReplace(publicId, "+", " "); publicId = PublicId.stringReplace(publicId, "%2B", "+"); publicId = PublicId.stringReplace(publicId, "%23", "#"); publicId = PublicId.stringReplace(publicId, "%3F", "?"); publicId = PublicId.stringReplace(publicId, "%27", "'"); publicId = PublicId.stringReplace(publicId, "%3B", ";"); publicId = PublicId.stringReplace(publicId, "%25", "%"); return publicId; }
java
{ "resource": "" }