diff options
author | Brian Carlstrom <bdc@google.com> | 2010-09-28 21:58:53 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-09-28 21:58:53 -0700 |
commit | d7212c5d3cde17ca20fc33cd294da2c5744df44a (patch) | |
tree | dee2b67a57e6dc3d536ecf1bdcfd63d1660b9709 | |
parent | 2a275f0640bf3fdbd9dd6336b4f195a5a6e9a109 (diff) | |
parent | e2f58c9501eac730d048199906dc41fe8e4cd6e9 (diff) | |
download | libcore-d7212c5d3cde17ca20fc33cd294da2c5744df44a.zip libcore-d7212c5d3cde17ca20fc33cd294da2c5744df44a.tar.gz libcore-d7212c5d3cde17ca20fc33cd294da2c5744df44a.tar.bz2 |
Merge "Scrub missing calls to super.finalize()" into gingerbread
29 files changed, 398 insertions, 307 deletions
diff --git a/dalvik/src/main/java/dalvik/system/DexFile.java b/dalvik/src/main/java/dalvik/system/DexFile.java index 8f9aec7..3ceefeb 100644 --- a/dalvik/src/main/java/dalvik/system/DexFile.java +++ b/dalvik/src/main/java/dalvik/system/DexFile.java @@ -253,8 +253,12 @@ public final class DexFile { * if an I/O error occurs during closing the file, which * normally should not happen */ - protected void finalize() throws IOException { - close(); + @Override protected void finalize() throws Throwable { + try { + close(); + } finally { + super.finalize(); + } } /* diff --git a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java b/luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java index f2d7889..6ab0b22 100644 --- a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java +++ b/luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java @@ -235,10 +235,13 @@ public final class CharsetDecoderICU extends CharsetDecoder { * Releases the system resources by cleanly closing ICU converter opened * @stable ICU 2.4 */ - protected void finalize() throws Throwable{ - NativeConverter.closeConverter(converterHandle); - super.finalize(); - converterHandle = 0; + @Override protected void finalize() throws Throwable { + try { + NativeConverter.closeConverter(converterHandle); + converterHandle = 0; + } finally { + super.finalize(); + } } //------------------------------------------ diff --git a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java b/luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java index cba44c7..6704b1a 100644 --- a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java +++ b/luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java @@ -311,10 +311,13 @@ public final class CharsetEncoderICU extends CharsetEncoder { * @exception Throwable exception thrown by super class' finalize method * @stable ICU 2.4 */ - protected void finalize() throws Throwable { - NativeConverter.closeConverter(converterHandle); - super.finalize(); - converterHandle=0; + @Override protected void finalize() throws Throwable { + try { + NativeConverter.closeConverter(converterHandle); + converterHandle=0; + } finally { + super.finalize(); + } } //------------------------------------------ diff --git a/luni/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java b/luni/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java index b054b6c..e84e438 100644 --- a/luni/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java +++ b/luni/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java @@ -38,193 +38,183 @@ import java.text.CharacterIterator; * @stable ICU 2.4 */ -public final class CollationElementIterator -{ - // public data member ------------------------------------------- - - /** - * @stable ICU 2.4 - */ - public static final int NULLORDER = 0xFFFFFFFF; - - // public methods ----------------------------------------------- - - /** - * Reset the collation elements to their initial state. - * This will move the 'cursor' to the beginning of the text. - * @stable ICU 2.4 - */ - public void reset() - { - NativeCollation.reset(m_collelemiterator_); - } - - /** - * Get the ordering priority of the next collation element in the text. - * A single character may contain more than one collation element. - * @return next collation elements ordering, or NULLORDER if the end of the - * text is reached. - * @stable ICU 2.4 - */ - public int next() - { - return NativeCollation.next(m_collelemiterator_); - } - - /** - * Get the ordering priority of the previous collation element in the text. - * A single character may contain more than one collation element. - * @return previous collation element ordering, or NULLORDER if the end of - * the text is reached. - * @stable ICU 2.4 - */ - public int previous() - { - return NativeCollation.previous(m_collelemiterator_); - } - - /** - * Get the maximum length of any expansion sequences that end with the - * specified comparison order. - * @param order collation order returned by previous or next. - * @return maximum size of the expansion sequences ending with the collation - * element or 1 if collation element does not occur at the end of - * any expansion sequence - * @stable ICU 2.4 - */ - public int getMaxExpansion(int order) - { - return NativeCollation.getMaxExpansion(m_collelemiterator_, order); - } - - /** - * Set the text containing the collation elements. - * @param source text containing the collation elements. - * @stable ICU 2.4 - */ - public void setText(String source) - { - NativeCollation.setText(m_collelemiterator_, source); - } - - // BEGIN android-added - public void setText(CharacterIterator source) - { - NativeCollation.setText(m_collelemiterator_, source.toString()); - } - // END android-added - - /** - * Get the offset of the current source character. - * This is an offset into the text of the character containing the current - * collation elements. - * @return offset of the current source character. - * @stable ICU 2.4 - */ - public int getOffset() - { - return NativeCollation.getOffset(m_collelemiterator_); - } - - /** - * Set the offset of the current source character. - * This is an offset into the text of the character to be processed. - * @param offset The desired character offset. - * @stable ICU 2.4 - */ - public void setOffset(int offset) - { - NativeCollation.setOffset(m_collelemiterator_, offset); - } - - /** - * Gets the primary order of a collation order. - * @param order the collation order - * @return the primary order of a collation order. - * @stable ICU 2.4 - */ - public static int primaryOrder(int order) - { - return ((order & PRIMARY_ORDER_MASK_) >> PRIMARY_ORDER_SHIFT_) & - UNSIGNED_16_BIT_MASK_; - } - - /** - * Gets the secondary order of a collation order. - * @param order the collation order - * @return the secondary order of a collation order. - * @stable ICU 2.4 - */ - public static int secondaryOrder(int order) - { - return (order & SECONDARY_ORDER_MASK_) >> SECONDARY_ORDER_SHIFT_; - } - - /** - * Gets the tertiary order of a collation order. - * @param order the collation order - * @return the tertiary order of a collation order. - * @stable ICU 2.4 - */ - public static int tertiaryOrder(int order) - { - return order & TERTIARY_ORDER_MASK_; - } - - // protected constructor ---------------------------------------- - - /** - * CollationElementIteratorJNI constructor. - * The only caller of this class should be - * RuleBasedCollator.getCollationElementIterator(). - * @param collelemiteratoraddress address of C collationelementiterator - */ - CollationElementIterator(int collelemiteratoraddress) - { - m_collelemiterator_ = collelemiteratoraddress; - } - - // protected methods -------------------------------------------- - - /** - * Garbage collection. - * Close C collator and reclaim memory. - * @stable ICU 2.4 - */ - protected void finalize() - { - NativeCollation.closeElements(m_collelemiterator_); - } - - // private data members ----------------------------------------- - - /** - * C collator - */ - private int m_collelemiterator_; - - /** - * ICU constant primary order mask for collation elements - */ - private static final int PRIMARY_ORDER_MASK_ = 0xffff0000; - /** - * ICU constant secondary order mask for collation elements - */ - private static final int SECONDARY_ORDER_MASK_ = 0x0000ff00; - /** - * ICU constant tertiary order mask for collation elements - */ - private static final int TERTIARY_ORDER_MASK_ = 0x000000ff; - /** - * ICU constant primary order shift for collation elements - */ - private static final int PRIMARY_ORDER_SHIFT_ = 16; - /** - * ICU constant secondary order shift for collation elements - */ - private static final int SECONDARY_ORDER_SHIFT_ = 8; - /** - * Unsigned 16 bit mask - */ - private static final int UNSIGNED_16_BIT_MASK_ = 0x0000FFFF; +public final class CollationElementIterator { + // public data member ------------------------------------------- + + /** + * @stable ICU 2.4 + */ + public static final int NULLORDER = 0xFFFFFFFF; + + // public methods ----------------------------------------------- + + /** + * Reset the collation elements to their initial state. + * This will move the 'cursor' to the beginning of the text. + * @stable ICU 2.4 + */ + public void reset() { + NativeCollation.reset(m_collelemiterator_); + } + + /** + * Get the ordering priority of the next collation element in the text. + * A single character may contain more than one collation element. + * @return next collation elements ordering, or NULLORDER if the end of the + * text is reached. + * @stable ICU 2.4 + */ + public int next() { + return NativeCollation.next(m_collelemiterator_); + } + + /** + * Get the ordering priority of the previous collation element in the text. + * A single character may contain more than one collation element. + * @return previous collation element ordering, or NULLORDER if the end of + * the text is reached. + * @stable ICU 2.4 + */ + public int previous() { + return NativeCollation.previous(m_collelemiterator_); + } + + /** + * Get the maximum length of any expansion sequences that end with the + * specified comparison order. + * @param order collation order returned by previous or next. + * @return maximum size of the expansion sequences ending with the collation + * element or 1 if collation element does not occur at the end of + * any expansion sequence + * @stable ICU 2.4 + */ + public int getMaxExpansion(int order) { + return NativeCollation.getMaxExpansion(m_collelemiterator_, order); + } + + /** + * Set the text containing the collation elements. + * @param source text containing the collation elements. + * @stable ICU 2.4 + */ + public void setText(String source) { + NativeCollation.setText(m_collelemiterator_, source); + } + + // BEGIN android-added + public void setText(CharacterIterator source) { + NativeCollation.setText(m_collelemiterator_, source.toString()); + } + // END android-added + + /** + * Get the offset of the current source character. + * This is an offset into the text of the character containing the current + * collation elements. + * @return offset of the current source character. + * @stable ICU 2.4 + */ + public int getOffset() { + return NativeCollation.getOffset(m_collelemiterator_); + } + + /** + * Set the offset of the current source character. + * This is an offset into the text of the character to be processed. + * @param offset The desired character offset. + * @stable ICU 2.4 + */ + public void setOffset(int offset) { + NativeCollation.setOffset(m_collelemiterator_, offset); + } + + /** + * Gets the primary order of a collation order. + * @param order the collation order + * @return the primary order of a collation order. + * @stable ICU 2.4 + */ + public static int primaryOrder(int order) { + return ((order & PRIMARY_ORDER_MASK_) >> PRIMARY_ORDER_SHIFT_) & + UNSIGNED_16_BIT_MASK_; + } + + /** + * Gets the secondary order of a collation order. + * @param order the collation order + * @return the secondary order of a collation order. + * @stable ICU 2.4 + */ + public static int secondaryOrder(int order) { + return (order & SECONDARY_ORDER_MASK_) >> SECONDARY_ORDER_SHIFT_; + } + + /** + * Gets the tertiary order of a collation order. + * @param order the collation order + * @return the tertiary order of a collation order. + * @stable ICU 2.4 + */ + public static int tertiaryOrder(int order) { + return order & TERTIARY_ORDER_MASK_; + } + + // protected constructor ---------------------------------------- + + /** + * CollationElementIteratorJNI constructor. + * The only caller of this class should be + * RuleBasedCollator.getCollationElementIterator(). + * @param collelemiteratoraddress address of C collationelementiterator + */ + CollationElementIterator(int collelemiteratoraddress) { + m_collelemiterator_ = collelemiteratoraddress; + } + + // protected methods -------------------------------------------- + + /** + * Garbage collection. + * Close C collator and reclaim memory. + * @stable ICU 2.4 + */ + @Override protected void finalize() throws Throwable { + try { + NativeCollation.closeElements(m_collelemiterator_); + } finally { + super.finalize(); + } + } + + // private data members ----------------------------------------- + + /** + * C collator + */ + private int m_collelemiterator_; + + /** + * ICU constant primary order mask for collation elements + */ + private static final int PRIMARY_ORDER_MASK_ = 0xffff0000; + /** + * ICU constant secondary order mask for collation elements + */ + private static final int SECONDARY_ORDER_MASK_ = 0x0000ff00; + /** + * ICU constant tertiary order mask for collation elements + */ + private static final int TERTIARY_ORDER_MASK_ = 0x000000ff; + /** + * ICU constant primary order shift for collation elements + */ + private static final int PRIMARY_ORDER_SHIFT_ = 16; + /** + * ICU constant secondary order shift for collation elements + */ + private static final int SECONDARY_ORDER_SHIFT_ = 8; + /** + * Unsigned 16 bit mask + */ + private static final int UNSIGNED_16_BIT_MASK_ = 0x0000FFFF; } diff --git a/luni/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java b/luni/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java index 272d525..bbe45af 100644 --- a/luni/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java +++ b/luni/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java @@ -64,9 +64,12 @@ public final class NativeBreakIterator implements Cloneable { return 42; // No-one uses BreakIterator as a hash key. } - @Override - protected void finalize() { - closeBreakIteratorImpl(this.addr); + @Override protected void finalize() throws Throwable { + try { + closeBreakIteratorImpl(this.addr); + } finally { + super.finalize(); + } } public int current() { diff --git a/luni/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java b/luni/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java index c847bdb..b2397bf 100644 --- a/luni/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java +++ b/luni/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java @@ -532,9 +532,12 @@ public final class RuleBasedCollator extends Collator { m_collator_ = NativeCollation.openCollator(locale.toString()); } - @Override - protected void finalize() { - NativeCollation.closeCollator(m_collator_); + @Override protected void finalize() throws Throwable { + try { + NativeCollation.closeCollator(m_collator_); + } finally { + super.finalize(); + } } private RuleBasedCollator(int addr) { diff --git a/luni/src/main/java/java/io/FileInputStream.java b/luni/src/main/java/java/io/FileInputStream.java index 9e36231..bb8829d 100644 --- a/luni/src/main/java/java/io/FileInputStream.java +++ b/luni/src/main/java/java/io/FileInputStream.java @@ -166,9 +166,16 @@ public class FileInputStream extends InputStream implements Closeable { * @throws IOException * if an error occurs attempting to finalize this stream. */ - @Override - protected void finalize() throws IOException { - close(); + @Override protected void finalize() throws IOException { + try { + close(); + } finally { + try { + super.finalize(); + } catch (Throwable t) { + throw new AssertionError(t); + } + } } /** diff --git a/luni/src/main/java/java/io/FileOutputStream.java b/luni/src/main/java/java/io/FileOutputStream.java index f10e455..7c73c2e 100644 --- a/luni/src/main/java/java/io/FileOutputStream.java +++ b/luni/src/main/java/java/io/FileOutputStream.java @@ -202,9 +202,16 @@ public class FileOutputStream extends OutputStream implements Closeable { * @throws IOException * if an error occurs attempting to finalize this stream. */ - @Override - protected void finalize() throws IOException { - close(); + @Override protected void finalize() throws IOException { + try { + close(); + } finally { + try { + super.finalize(); + } catch (Throwable t) { + throw new AssertionError(t); + } + } } /** diff --git a/luni/src/main/java/java/lang/Enum.java b/luni/src/main/java/java/lang/Enum.java index 5031fc5..e70c198 100644 --- a/luni/src/main/java/java/lang/Enum.java +++ b/luni/src/main/java/java/lang/Enum.java @@ -185,6 +185,7 @@ public abstract class Enum<E extends Enum<E>> implements Serializable, Comparabl * @since 1.6 */ @Override + @SuppressWarnings("FinalizeDoesntCallSuperFinalize") protected final void finalize() { } diff --git a/luni/src/main/java/java/math/BigInt.java b/luni/src/main/java/java/math/BigInt.java index 1b42416..9955a1d 100644 --- a/luni/src/main/java/java/math/BigInt.java +++ b/luni/src/main/java/java/math/BigInt.java @@ -33,10 +33,12 @@ class BigInt { } } - @Override - protected void finalize() throws Throwable { - super.finalize(); - dispose(); + @Override protected void finalize() throws Throwable { + try { + dispose(); + } finally { + super.finalize(); + } } @Override diff --git a/luni/src/main/java/java/text/DecimalFormat.java b/luni/src/main/java/java/text/DecimalFormat.java index 27aced6..cdc064f 100644 --- a/luni/src/main/java/java/text/DecimalFormat.java +++ b/luni/src/main/java/java/text/DecimalFormat.java @@ -504,7 +504,11 @@ public class DecimalFormat extends NumberFormat { private transient NativeDecimalFormat dform; private final Object finalizerGuardian = new Object() { @Override protected void finalize() throws Throwable { - dform.close(); + try { + dform.close(); + } finally { + super.finalize(); + } } }; diff --git a/luni/src/main/java/java/util/Timer.java b/luni/src/main/java/java/util/Timer.java index 06857d4..15b71c0 100644 --- a/luni/src/main/java/java/util/Timer.java +++ b/luni/src/main/java/java/util/Timer.java @@ -328,11 +328,14 @@ public class Timer { this.impl = impl; } - @Override - protected void finalize() { - synchronized (impl) { - impl.finished = true; - impl.notify(); + @Override protected void finalize() throws Throwable { + try { + synchronized (impl) { + impl.finished = true; + impl.notify(); + } + } finally { + super.finalize(); } } } diff --git a/luni/src/main/java/java/util/concurrent/Executors.java b/luni/src/main/java/java/util/concurrent/Executors.java index 9b0f08b..5c407b0 100644 --- a/luni/src/main/java/java/util/concurrent/Executors.java +++ b/luni/src/main/java/java/util/concurrent/Executors.java @@ -642,8 +642,12 @@ public class Executors { FinalizableDelegatedExecutorService(ExecutorService executor) { super(executor); } - protected void finalize() { - super.shutdown(); + @Override protected void finalize() throws Throwable { + try { + super.shutdown(); + } finally { + super.finalize(); + } } } diff --git a/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java b/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java index d360ad3..9bddc8d 100644 --- a/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java +++ b/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java @@ -1419,8 +1419,16 @@ public class ThreadPoolExecutor extends AbstractExecutorService { * Invokes {@code shutdown} when this executor is no longer * referenced and it has no threads. */ - protected void finalize() { - shutdown(); + @Override protected void finalize() { + try { + shutdown(); + } finally { + try { + super.finalize(); + } catch (Throwable t) { + throw new AssertionError(t); + } + } } /** diff --git a/luni/src/main/java/java/util/regex/Matcher.java b/luni/src/main/java/java/util/regex/Matcher.java index bb23b17..39548bb 100644 --- a/luni/src/main/java/java/util/regex/Matcher.java +++ b/luni/src/main/java/java/util/regex/Matcher.java @@ -672,8 +672,7 @@ public final class Matcher implements MatchResult { return hitEndImpl(address); } - @Override - protected void finalize() throws Throwable { + @Override protected void finalize() throws Throwable { try { closeImpl(address); } finally { diff --git a/luni/src/main/java/java/util/regex/Pattern.java b/luni/src/main/java/java/util/regex/Pattern.java index 1b724dd..325286f 100644 --- a/luni/src/main/java/java/util/regex/Pattern.java +++ b/luni/src/main/java/java/util/regex/Pattern.java @@ -433,8 +433,7 @@ public final class Pattern implements Serializable { return sb.append(string.substring(apos)).append("\\E").toString(); } - @Override - protected void finalize() throws Throwable { + @Override protected void finalize() throws Throwable { try { closeImpl(address); } finally { diff --git a/luni/src/main/java/java/util/zip/Deflater.java b/luni/src/main/java/java/util/zip/Deflater.java index c0c62d9..4ac5c47 100644 --- a/luni/src/main/java/java/util/zip/Deflater.java +++ b/luni/src/main/java/java/util/zip/Deflater.java @@ -262,11 +262,18 @@ public class Deflater { } } - @Override - protected void finalize() { - synchronized (this) { - end(); // to allow overriding classes to clean up - endImpl(); // in case those classes don't call super.end() + @Override protected void finalize() { + try { + synchronized (this) { + end(); // to allow overriding classes to clean up + endImpl(); // in case those classes don't call super.end() + } + } finally { + try { + super.finalize(); + } catch (Throwable t) { + throw new AssertionError(t); + } } } diff --git a/luni/src/main/java/java/util/zip/Inflater.java b/luni/src/main/java/java/util/zip/Inflater.java index ec151d0..9dd56f3 100644 --- a/luni/src/main/java/java/util/zip/Inflater.java +++ b/luni/src/main/java/java/util/zip/Inflater.java @@ -83,9 +83,16 @@ public class Inflater { private native synchronized void endImpl(long handle); - @Override - protected void finalize() { - end(); + @Override protected void finalize() { + try { + end(); + } finally { + try { + super.finalize(); + } catch (Throwable t) { + throw new AssertionError(t); + } + } } /** diff --git a/luni/src/main/java/java/util/zip/ZipFile.java b/luni/src/main/java/java/util/zip/ZipFile.java index f5bf832..8f70aeb 100644 --- a/luni/src/main/java/java/util/zip/ZipFile.java +++ b/luni/src/main/java/java/util/zip/ZipFile.java @@ -147,9 +147,16 @@ public class ZipFile implements ZipConstants { this(new File(name), OPEN_READ); } - @Override - protected void finalize() throws IOException { - close(); + @Override protected void finalize() throws IOException { + try { + close(); + } finally { + try { + super.finalize(); + } catch (Throwable t) { + throw new AssertionError(t); + } + } } /** diff --git a/luni/src/main/java/javax/crypto/ExemptionMechanism.java b/luni/src/main/java/javax/crypto/ExemptionMechanism.java index 5bd994f..fe7e553 100644 --- a/luni/src/main/java/javax/crypto/ExemptionMechanism.java +++ b/luni/src/main/java/javax/crypto/ExemptionMechanism.java @@ -367,10 +367,13 @@ public class ExemptionMechanism { } /** - * Frees the references to the key used to initialize this instance. + * Override to clear any key state in the instance. */ - @Override - protected void finalize() { - initKey = null; + @Override protected void finalize() { + try { + super.finalize(); + } catch (Throwable t) { + throw new AssertionError(t); + } } } diff --git a/luni/src/main/java/libcore/icu/NativePluralRules.java b/luni/src/main/java/libcore/icu/NativePluralRules.java index 5547038..a11224e 100644 --- a/luni/src/main/java/libcore/icu/NativePluralRules.java +++ b/luni/src/main/java/libcore/icu/NativePluralRules.java @@ -38,8 +38,12 @@ public final class NativePluralRules { this.address = address; } - @Override public void finalize() { - finalizeImpl(address); + @Override public void finalize() throws Throwable { + try { + finalizeImpl(address); + } finally { + super.finalize(); + } } public static NativePluralRules forLocale(Locale locale) { diff --git a/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java b/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java index 3ebf562..a210a0b 100644 --- a/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java +++ b/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java @@ -110,9 +110,12 @@ public class PlainDatagramSocketImpl extends DatagramSocketImpl { netImpl.socket(fd, false); } - @Override - protected void finalize() { - close(); + @Override protected void finalize() throws Throwable { + try { + close(); + } finally { + super.finalize(); + } } public Object getOption(int optID) throws SocketException { diff --git a/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java b/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java index 0807af6..2a36fee 100644 --- a/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java +++ b/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java @@ -216,9 +216,12 @@ public class PlainSocketImpl extends SocketImpl { netImpl.socket(fd, streaming); } - @Override - protected void finalize() throws IOException { - close(); + @Override protected void finalize() throws Throwable { + try { + close(); + } finally { + super.finalize(); + } } @Override diff --git a/luni/src/main/java/org/apache/harmony/xml/ExpatParser.java b/luni/src/main/java/org/apache/harmony/xml/ExpatParser.java index 4826095..9eb89e9 100644 --- a/luni/src/main/java/org/apache/harmony/xml/ExpatParser.java +++ b/luni/src/main/java/org/apache/harmony/xml/ExpatParser.java @@ -144,8 +144,7 @@ class ExpatParser { contentHandler.startElement( uri, localName, qName, this.attributes); - } - finally { + } finally { inStartElement = false; this.attributeCount = -1; this.attributePointer = 0; @@ -552,12 +551,14 @@ class ExpatParser { } } - @Override - @SuppressWarnings("FinalizeDoesntCallSuperFinalize") - protected synchronized void finalize() throws Throwable { - if (this.pointer != 0) { - release(this.pointer); - this.pointer = 0; + @Override protected synchronized void finalize() throws Throwable { + try { + if (this.pointer != 0) { + release(this.pointer); + this.pointer = 0; + } + } finally { + super.finalize(); } } @@ -658,12 +659,14 @@ class ExpatParser { return length; } - @Override - @SuppressWarnings("FinalizeDoesntCallSuperFinalize") - protected synchronized void finalize() throws Throwable { - if (pointer != 0) { - freeAttributes(pointer); - pointer = 0; + @Override protected synchronized void finalize() throws Throwable { + try { + if (pointer != 0) { + freeAttributes(pointer); + pointer = 0; + } + } finally { + super.finalize(); } } } diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java index bd0bd75..90035d4 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java @@ -285,8 +285,12 @@ abstract class AbstractSessionContext implements SSLSessionContext { "Error converting session.", t); } - protected void finalize() throws IOException { - NativeCrypto.SSL_CTX_free(sslCtxNativePointer); + @Override protected void finalize() throws Throwable { + try { + NativeCrypto.SSL_CTX_free(sslCtxNativePointer); + } finally { + super.finalize(); + } } /** diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLMessageDigestJDK.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLMessageDigestJDK.java index b01670d..3118a02 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLMessageDigestJDK.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLMessageDigestJDK.java @@ -94,11 +94,13 @@ public class OpenSSLMessageDigestJDK extends MessageDigest implements Cloneable return d; } - @Override - protected void finalize() throws Throwable { - super.finalize(); - NativeCrypto.EVP_MD_CTX_destroy(ctx); - ctx = 0; + @Override protected void finalize() throws Throwable { + try { + NativeCrypto.EVP_MD_CTX_destroy(ctx); + ctx = 0; + } finally { + super.finalize(); + } } public static class MD5 extends OpenSSLMessageDigestJDK { diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java index 5d617ad..70cccc0 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java @@ -499,7 +499,11 @@ public class OpenSSLSessionImpl implements SSLSession { } } - protected void finalize() { - NativeCrypto.SSL_SESSION_free(sslSessionNativePointer); + @Override protected void finalize() throws Throwable { + try { + NativeCrypto.SSL_SESSION_free(sslSessionNativePointer); + } finally { + super.finalize(); + } } } diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSignature.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSignature.java index 02cbb26..8a460a4 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSignature.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSignature.java @@ -232,20 +232,21 @@ public class OpenSSLSignature extends Signature { } - @Override - protected void finalize() throws Throwable { - super.finalize(); - - if (dsa != 0) { - NativeCrypto.EVP_PKEY_free(dsa); - } + @Override protected void finalize() throws Throwable { + try { + if (dsa != 0) { + NativeCrypto.EVP_PKEY_free(dsa); + } - if (rsa != 0) { - NativeCrypto.EVP_PKEY_free(rsa); - } + if (rsa != 0) { + NativeCrypto.EVP_PKEY_free(rsa); + } - if (ctx != 0) { - NativeCrypto.EVP_MD_CTX_destroy(ctx); + if (ctx != 0) { + NativeCrypto.EVP_MD_CTX_destroy(ctx); + } + } finally { + super.finalize(); } } diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java index ad21f7b..0d487ca 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java @@ -1253,25 +1253,28 @@ public class OpenSSLSocketImpl sslNativePointer = 0; } - @Override - protected void finalize() throws IOException { - /* - * Just worry about our own state. Notably we do not try and - * close anything. The SocketImpl, either our own - * PlainSocketImpl, or the Socket we are wrapping, will do - * that. This might mean we do not properly SSL_shutdown, but - * if you want to do that, properly close the socket yourself. - * - * The reason why we don't try to SSL_shutdown, is that there - * can be a race between finalizers where the PlainSocketImpl - * finalizer runs first and closes the socket. However, in the - * meanwhile, the underlying file descriptor could be reused - * for another purpose. If we call SSL_shutdown, the - * underlying socket BIOs still have the old file descriptor - * and will write the close notify to some unsuspecting - * reader. - */ - updateInstanceCount(-1); - free(); + @Override protected void finalize() throws Throwable { + try { + /* + * Just worry about our own state. Notably we do not try and + * close anything. The SocketImpl, either our own + * PlainSocketImpl, or the Socket we are wrapping, will do + * that. This might mean we do not properly SSL_shutdown, but + * if you want to do that, properly close the socket yourself. + * + * The reason why we don't try to SSL_shutdown, is that there + * can be a race between finalizers where the PlainSocketImpl + * finalizer runs first and closes the socket. However, in the + * meanwhile, the underlying file descriptor could be reused + * for another purpose. If we call SSL_shutdown, the + * underlying socket BIOs still have the old file descriptor + * and will write the close notify to some unsuspecting + * reader. + */ + updateInstanceCount(-1); + free(); + } finally { + super.finalize(); + } } } |