Advertisement
DulcetAirman

Leaking Constructor 2

Apr 19th, 2013
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.foo;
  2.  
  3. public class SomeClass {
  4.   public static volatile SomeClass leak = null;
  5.   public final byte[] data;
  6.   public final String string;
  7.  
  8.   public SomeClass() {
  9.     leak = this;
  10.     this.data = new byte[Integer.MAX_VALUE];
  11.     this.string = "something";
  12.   }
  13.  
  14.   @Override
  15.   public String toString() {
  16.     return this.string;
  17.   }
  18.  
  19.   public static void main(final String[] args) throws Exception {
  20.     Object object = "nothing";
  21.     try {
  22.       object = new SomeClass();
  23.     } catch (final Throwable e) { }
  24.     System.out.printf("object = %s (%s)\n", object, object.getClass().getSimpleName());
  25.     System.out.printf("leak = %s (%s)\n", leak, leak.getClass().getSimpleName());
  26.   }
  27. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement