Changeset fb4fb47 for core


Ignore:
Timestamp:
Nov 26, 2017 2:16:16 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
6a48910
Parents:
7a36b07
Message:

Context: Hopefully fix rare NPE on Android (ticket #2092)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/I2PAppContext.java

    r7a36b07 rfb4fb47  
    151151   
    152152    /**
     153     * Sets the default context, unless there is one already.
     154     * NOT a public API, for use by RouterContext only, NOT for external use.
     155     *
     156     * @param ctx context constructed with doInit = false
     157     * @return success (false if previously set)
     158     * @since 0.9.33
     159     */
     160    protected static boolean setGlobalContext(I2PAppContext ctx) {
     161        synchronized (I2PAppContext.class) {
     162            if (_globalAppContext == null) {
     163                _globalAppContext = ctx;
     164                return true;
     165            }
     166        }
     167        System.out.println("Warning - New context not replacing old one, you now have a second one");
     168        (new Exception("I did it")).printStackTrace();
     169        return false;
     170    }
     171
     172    /**
    153173     * Pull the default context, WITHOUT creating a new one.
    154174     * Use this in static methods used early in router initialization,
     
    191211     * problems or hard-to-isolate bugs.
    192212     *
     213     * NOT a public API, for use by RouterContext only, NOT for external use.
     214     *
    193215     * @param doInit should this context be used as the global one (if necessary)?
    194216     *               Will only apply if there is no global context now.
    195      */
    196     private I2PAppContext(boolean doInit, Properties envProps) {
     217     * @since protected since 0.9.33, NOT for external use
     218     */
     219    protected I2PAppContext(boolean doInit, Properties envProps) {
    197220      synchronized (I2PAppContext.class) {
    198221        _overrideProps = new I2PProperties();
     
    312335
    313336        if (doInit) {
    314             if (_globalAppContext == null) {
    315                 _globalAppContext = this;
    316             } else {
    317                 System.out.println("Warning - New context not replacing old one, you now have a second one");
    318                 (new Exception("I did it")).printStackTrace();
    319             }
     337            // Bad practice, sets a static field to this in constructor.
     338            // doInit will be false when instantiated via Router.
     339            setGlobalContext(this);
    320340        }
    321341      } // synch
Note: See TracChangeset for help on using the changeset viewer.