1 Reply Latest reply: Apr 3, 2009 6:08 PM by 807557 RSS

    FileOutputStream -> Illegal Assignment Error

      When I try
      FileOutputStream os = new FileOutputStream("filename", true); // true for appending text to an existing file
      from inside a ScopedMemory object, I get an Illegal Assignment Error.

      What kind of illegal assignment happens here internally? And how can I avoid this?

        • 1. Re: FileOutputStream -> Illegal Assignment Error
          The standard libraries (which means anything outside of javax.realtime except for a small handful of special cases) are not scope-aware and their use within scopes is likely to be problematic. The stacktrace (need the try/catch inside the run() method in the scope) will show you exactly where the problem is occuring. Basically IllegalAssignmentError means that an object has been allocated in a scope and now a reference to that object is being attempted to be stored into a field that is longer lived than the current scope - this is either a static field, or a field of an object that is allocated in heap, immortal or an outer scope.Recall that static initialization always occurs in ImmortalMemory, so many of the objects used in the initialization of the main class libraries end up being immortal.

          Avoiding this depends on exactly what is happening and the class involved. For example, sometimes the issue is growing an internal array or similar data structure - the new array is in scope, the reference is static, or in an immortal allocate dobject - and you can avoid the problem by not requiring growth to occur, such as by increasing a collections capacity, for example.

          Otherwise you need to avoid creating such instances in scoped memory.