Changeset fb4fb47


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)

Files:
5 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
  • history.txt

    r7a36b07 rfb4fb47  
     12017-11-26 zzz
     2 * Context: Hopefully fix rare NPE on Android (ticket #2092)
     3
     42017-11-25 zzz
     5 * Console:
     6   - Show full logger.config path on /configlogging
     7   - Don't say 'Plugin downloaded' when installing from file
     8 * Debian:
     9   - Replace glassfish-javaee with libtaglibs-standard-* (ticket #2093)
     10   - Remove libecj-java dependency (ticket #2094)
     11
     122017-11-23 zzz
     13 * i2ptunnel: Add timeout to header reads for CONNECT, HTTP, and SOCKS clients
     14 * Wrapper 3.5.34
     15
    1162017-11-22 zzz
     17 * i2psnark: Fix nbsp in logs on config change (ticket #2082)
    218 * Streaming: Fix bug causing loopback hangs and
    319   preventing desired ack behavior (ticket #1939)
  • router/java/src/net/i2p/router/Router.java

    r7a36b07 rfb4fb47  
    309309        // i2p.dir.pid defaults to i2p.dir.router
    310310        // i2p.dir.base defaults to user.dir == $CWD
    311         _context = new RouterContext(this, envProps);
     311        _context = new RouterContext(this, envProps, false);
     312        RouterContext.setGlobalContext(_context);
    312313        _eventLog = new EventLog(_context, new File(_context.getRouterDir(), EVENTLOG));
    313314
  • router/java/src/net/i2p/router/RouterContext.java

    r7a36b07 rfb4fb47  
    8585     */
    8686    public RouterContext(Router router, Properties envProps) {
    87         super(filterProps(envProps));
     87        this(router, envProps, true);
     88    }
     89
     90    /**
     91     *  Caller MUST call initAll() after instantiation.
     92     *  NOT a public API, for use by Router only, NOT for external use.
     93     *
     94     *  @param doInit should this context be used as the global one (if necessary)?
     95     *                Will only apply if there is no global context now.
     96     *                If false, caller should call setGlobalContext() afterwards.
     97     *  @since 0.9.33
     98     */
     99    RouterContext(Router router, Properties envProps, boolean doInit) {
     100        super(doInit, filterProps(envProps));
    88101        _router = router;
    89102        // Disabled here so that the router can get a context and get the
     
    95108            System.err.println("Warning - More than one router in this JVM");
    96109        _finalShutdownTasks = new CopyOnWriteArraySet<Runnable>();
    97         _contexts.add(this);
     110        if (doInit) {
     111            // Bad practice, adding this to static List in constructor.
     112            // doInit will be false when instantiated via Router.
     113            _contexts.add(this);
     114        }
     115    }
     116   
     117    /**
     118     * Sets the default context, unless there is one already.
     119     * NOT a public API, for use by Router only, NOT for external use.
     120     *
     121     * @param ctx context constructed with doInit = false
     122     * @return success (false if previously set)
     123     * @since 0.9.33
     124     */
     125    static boolean setGlobalContext(RouterContext ctx) {
     126        _contexts.add(ctx);
     127        return I2PAppContext.setGlobalContext(ctx);
    98128    }
    99129
  • router/java/src/net/i2p/router/RouterVersion.java

    r7a36b07 rfb4fb47  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 8;
     21    public final static long BUILD = 9;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.