bugged
stringlengths 6
599k
| fixed
stringlengths 10
599k
| __index_level_0__
int64 0
1.13M
|
---|---|---|
public void returnObject(Object key, Object obj) throws Exception { // grab the pool (list) of objects associated with the given key CursorableLinkedList pool = null; synchronized(this) { pool = (CursorableLinkedList)(_poolMap.get(key)); // if it doesn't exist, create it if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key, pool); _poolList.add(key); } } // if we need to validate this object, do so boolean success = true; // whether or not this object passed validation if((_testOnReturn && !_factory.validateObject(key, obj))) { success = false; try { _factory.destroyObject(key, obj); } catch(Exception e) { // ignored } } else { try { _factory.passivateObject(key, obj); } catch(Exception e) { success = false; } } boolean shouldDestroy = false; synchronized(this) { // subtract one from the total and keyed active counts _totalActive--; Integer active = (Integer)(_activeMap.get(key)); if(null == active) { // do nothing, either null or zero is OK } else if(active.intValue() <= 1) { _activeMap.remove(key); } else { _activeMap.put(key, new Integer(active.intValue() - 1)); } // if there's no space in the pool, flag the object // for destruction // else if we passivated succesfully, return it to the pool if(_maxIdle >= 0 && (pool.size() >= _maxIdle)) { shouldDestroy = true; } else if(success) { pool.addFirst(new ObjectTimestampPair(obj)); _totalIdle++; } notifyAll(); } if(shouldDestroy) { try { _factory.destroyObject(key, obj); } catch(Exception e) { // ignored? } } } | public void returnObject(Object key, Object obj) throws Exception { // grab the pool (list) of objects associated with the given key CursorableLinkedList pool = null; synchronized(this) { pool = (CursorableLinkedList)(_poolMap.get(key)); // if it doesn't exist, create it if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key, pool); _poolList.add(key); } } // if we need to validate this object, do so boolean success = true; // whether or not this object passed validation if((_testOnReturn && !_factory.validateObject(key, obj))) { success = false; try { _factory.destroyObject(key, obj); } catch(Exception e) { // ignored } } else { try { _factory.passivateObject(key, obj); } catch(Exception e) { success = false; } } boolean shouldDestroy = false; synchronized(this) { // subtract one from the total and keyed active counts _totalActive--; Integer active = (Integer)(_activeMap.get(key)); if(null == active) { // do nothing, either null or zero is OK } else if(active.intValue() <= 1) { _activeMap.remove(key); } else { _activeMap.put(key, new Integer(active.intValue() - 1)); } // if there's no space in the pool, flag the object // for destruction // else if we passivated succesfully, return it to the pool if(_maxIdle >= 0 && (pool.size() >= _maxIdle)) { shouldDestroy = true; } else if(success) { pool.addFirst(new ObjectTimestampPair(obj)); _totalIdle++; } notifyAll(); } if(shouldDestroy) { try { _factory.destroyObject(key, obj); } catch(Exception e) { // ignored? } } } | 1,125,588 |
private void readFiles() { File file = new File( _graphmlFileName ); if ( file.isFile() ) { _graph = parseFile( _graphmlFileName ); } else if ( file.isDirectory() ) { // Only accpets files which suffix is .graphml FilenameFilter filter = new FilenameFilter() { public boolean accept( File dir, String name ) { return name.endsWith( ".graphml" ); } }; File [] allChildren = file.listFiles( filter ); for ( int i = 0; i < allChildren.length; ++i ) { _graphList.add( parseFile( allChildren[ i ].getAbsolutePath() ) ); } analyseSubGraphs(); } else { throw new RuntimeException( "\"" + _graphmlFileName + "\" is not a file or a directory. Please specify a valid .graphml file or a directory containing .graphml files" ); } } | private void readFiles() { File file = new File( _graphmlFileName ); if ( file.isFile() ) { _graphList.add( parseFile( _graphmlFileName ) ); } else if ( file.isDirectory() ) { // Only accpets files which suffix is .graphml FilenameFilter filter = new FilenameFilter() { public boolean accept( File dir, String name ) { return name.endsWith( ".graphml" ); } }; File [] allChildren = file.listFiles( filter ); for ( int i = 0; i < allChildren.length; ++i ) { _graphList.add( parseFile( allChildren[ i ].getAbsolutePath() ) ); } analyseSubGraphs(); } else { throw new RuntimeException( "\"" + _graphmlFileName + "\" is not a file or a directory. Please specify a valid .graphml file or a directory containing .graphml files" ); } } | 1,125,590 |
private void readFiles() { File file = new File( _graphmlFileName ); if ( file.isFile() ) { _graph = parseFile( _graphmlFileName ); } else if ( file.isDirectory() ) { // Only accpets files which suffix is .graphml FilenameFilter filter = new FilenameFilter() { public boolean accept( File dir, String name ) { return name.endsWith( ".graphml" ); } }; File [] allChildren = file.listFiles( filter ); for ( int i = 0; i < allChildren.length; ++i ) { _graphList.add( parseFile( allChildren[ i ].getAbsolutePath() ) ); } analyseSubGraphs(); } else { throw new RuntimeException( "\"" + _graphmlFileName + "\" is not a file or a directory. Please specify a valid .graphml file or a directory containing .graphml files" ); } } | private void readFiles() { File file = new File( _graphmlFileName ); if ( file.isFile() ) { _graph = parseFile( _graphmlFileName ); } else if ( file.isDirectory() ) { // Only accpets files which suffix is .graphml FilenameFilter filter = new FilenameFilter() { public boolean accept( File dir, String name ) { return name.endsWith( ".graphml" ); } }; File [] allChildren = file.listFiles( filter ); for ( int i = 0; i < allChildren.length; ++i ) { _graphList.add( parseFile( allChildren[ i ].getAbsolutePath() ) ); } } else { throw new RuntimeException( "\"" + _graphmlFileName + "\" is not a file or a directory. Please specify a valid .graphml file or a directory containing .graphml files" ); } } | 1,125,591 |
public synchronized Object borrowObject(Object key) throws Exception { long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key,pool); _poolList.add(key); } ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(pool.removeFirst()); if(null != pair) { _totalIdle--; } } catch(NoSuchElementException e) { /* ignored */ } // otherwise if(null == pair) { // if there is a totalMaxActive and we are at the limit then // we have to make room // TODO: this could be improved by only removing the oldest object if ((_maxTotal > 0) && (_totalActive + _totalIdle >= _maxTotal)) { clear(); } // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) int active = getActiveCount(key); if ((_maxActive <= 0 || active < _maxActive) && (_maxTotal <= 0 || _totalActive + _totalIdle < _maxTotal)) { Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _factory.activateObject(key,pair.value); if(_testOnBorrow && !_factory.validateObject(key,pair.value)) { _factory.destroyObject(key,pair.value); if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } // else keep looping } else { incrementActiveCount(key); return pair.value; } } } | public synchronized Object borrowObject(Object key) throws Exception { long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key,pool); _poolList.add(key); } ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(pool.removeFirst()); if(null != pair) { _totalIdle--; } } catch(NoSuchElementException e) { /* ignored */ } // otherwise if(null == pair) { // if there is a totalMaxActive and we are at the limit then // we have to make room // TODO: this could be improved by only removing the oldest object if ((_maxTotal > 0) && (_totalActive + _totalIdle >= _maxTotal)) { clearOldest(); } // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) int active = getActiveCount(key); if ((_maxActive <= 0 || active < _maxActive) && (_maxTotal <= 0 || _totalActive + _totalIdle < _maxTotal)) { Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _factory.activateObject(key,pair.value); if(_testOnBorrow && !_factory.validateObject(key,pair.value)) { _factory.destroyObject(key,pair.value); if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } // else keep looping } else { incrementActiveCount(key); return pair.value; } } } | 1,125,593 |
public boolean validateObject(Object obj) { return true; } | public boolean validateObject(Object obj) { return valid; } | 1,125,594 |
public synchronized Object borrowObject() throws Exception { assertOpen(); Object obj = null; try { obj = _pool.pop(); } catch(EmptyStackException e) { if(null == _factory) { throw new NoSuchElementException(); } else { obj = _factory.makeObject(); } } if(null != _factory && null != obj) { _factory.activateObject(obj); } _numActive++; return obj; } | public synchronized Object borrowObject() throws Exception { assertOpen(); Object obj = null; if (!_pool.empty()) { obj = _pool.pop(); } catch(EmptyStackException e) { if(null == _factory) { throw new NoSuchElementException(); } else { obj = _factory.makeObject(); } } if(null != _factory && null != obj) { _factory.activateObject(obj); } _numActive++; return obj; } | 1,125,595 |
public synchronized Object borrowObject() throws Exception { assertOpen(); Object obj = null; try { obj = _pool.pop(); } catch(EmptyStackException e) { if(null == _factory) { throw new NoSuchElementException(); } else { obj = _factory.makeObject(); } } if(null != _factory && null != obj) { _factory.activateObject(obj); } _numActive++; return obj; } | public synchronized Object borrowObject() throws Exception { assertOpen(); Object obj = null; try { obj = _pool.pop(); } else { if(null == _factory) { throw new NoSuchElementException(); } else { obj = _factory.makeObject(); } } if(null != _factory && null != obj) { _factory.activateObject(obj); } _numActive++; return obj; } | 1,125,596 |
public void run() { while(!_cancelled) { long sleeptime = 0L; synchronized(GenericKeyedObjectPool.this) { sleeptime = _timeBetweenEvictionRunsMillis; } try { Thread.sleep(sleeptime); } catch(Exception e) { ; // ignored } //Evict from the pool try { evict(); } catch(Exception e) { ; // ignored } //Re-create the connections. try { ensureMinIdle(); } catch (Exception e) { ; // ignored } } } | public void run() { while(!_cancelled) { long sleeptime = 0L; synchronized(GenericKeyedObjectPool.this) { sleeptime = _timeBetweenEvictionRunsMillis; } try { Thread.sleep(sleeptime); } catch(Exception e) { ; // ignored } //Evict from the pool try { evict(); } catch(Exception e) { ; // ignored } //Re-create the connections. try { ensureMinIdle(); } catch (Exception e) { ; // ignored } } } | 1,125,597 |
protected synchronized void startEvictor(long delay) { if(null != _evictor) { _evictor.cancel(); _evictor = null; } if(delay > 0) { _evictor = new Evictor(delay); Thread t = new Thread(_evictor); t.setDaemon(true); t.start(); } } | protected synchronized void startEvictor(long delay) { if(null != _evictor) { _evictor.cancel(); _evictor = null; } if(delay > 0) { _evictor = new Evictor(delay); Thread t = new Thread(_evictor); t.setDaemon(true); t.start(); } } | 1,125,598 |