I am having a problem changing a List that has a set-size in Java.
I understand that I can't add or remove from this list but why can't I use set? When I use set the UnsupportedOperationException is thrown as well as when I use add and remove which is expected.
set
public Object set(int index,
Object element)
Replaces the element at the specified position in this list with the specified element (optional operation).
I understand its an optional operation its just that want to replace that one element of the list with another element. Is there any way I can do this?
EDIT: I am using a LinkedList
Here is the stack trace of my issue.
java.lang.UnsupportedOperationException: Add to an immutable TypedListIterator
at polyglot.util.TypedList.tryIns(TypedList.java:195)
at polyglot.util.TypedList.set(TypedList.java:148)
at itype.visit.ItypeChecker.enter(ItypeChecker.java:114)
at polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:245)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:217)
at polyglot.ast.Node_c.visitChild(Node_c.java:173)
at polyglot.ast.Node_c.visitList(Node_c.java:233)
at polyglot.ast.ClassBody_c.visitChildren(ClassBody_c.java:63)
at polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:251)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:217)
at polyglot.ast.Node_c.visitChild(Node_c.java:173)
at polyglot.ast.ClassDecl_c.visitChildren(ClassDecl_c.java:159)
at polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:251)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:217)
at polyglot.ast.Node_c.visitChild(Node_c.java:173)
at polyglot.ast.Node_c.visitList(Node_c.java:233)
at polyglot.ast.SourceFile_c.visitChildren(SourceFile_c.java:121)
at polyglot.visit.NodeVisitor.visitEdgeNoOverride(NodeVisitor.java:251)
at polyglot.visit.NodeVisitor.visitEdge(NodeVisitor.java:217)
at polyglot.ast.Node_c.visit(Node_c.java:177)
at polyglot.frontend.VisitorPass.run(VisitorPass.java:56)
at polyglot.frontend.Scheduler.runPass(Scheduler.java:596)
at polyglot.frontend.Scheduler.runGoal(Scheduler.java:499)
at polyglot.frontend.Scheduler.attemptGoal(Scheduler.java:440)
at polyglot.frontend.Scheduler.attemptGoal(Scheduler.java:412)
at polyglot.frontend.Scheduler.attemptGoal(Scheduler.java:412)
at polyglot.frontend.Scheduler.attemptGoal(Scheduler.java:412)
at polyglot.frontend.Scheduler.attemptGoal(Scheduler.java:364)
at polyglot.frontend.Scheduler.runToCompletion(Scheduler.java:297)
at polyglot.frontend.Compiler.compile(Compiler.java:171)
at polyglot.frontend.Compiler.compileFiles(Compiler.java:138)
at polyglot.main.Main.start(Main.java:119)
at polyglot.main.Main.start(Main.java:82)
at polyglot.pth.SourceFileTest.invokePolyglot(SourceFileTest.java:162)
at polyglot.pth.SourceFileTest.runTest(SourceFileTest.java:60)
at polyglot.pth.AbstractTest.run(AbstractTest.java:32)
at polyglot.pth.TestSuite.runTest(TestSuite.java:64)
at polyglot.pth.ScriptTestSuite.runTest(ScriptTestSuite.java:55)
at polyglot.pth.AbstractTest.run(AbstractTest.java:32)
at polyglot.pth.Main.start(Main.java:41)
at polyglot.pth.Main.main(Main.java:11)