diff options
Diffstat (limited to 'testplugins')
-rw-r--r-- | testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java7.java | 94 |
1 files changed, 88 insertions, 6 deletions
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java7.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java7.java index f3575cb66..8e5cf9815 100644 --- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java7.java +++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java7.java @@ -15,8 +15,13 @@ **********************************************************************/ package org.eclipse.objectteams.otdt.tests.otjld.other; +import java.io.File; +import java.util.Map; + import junit.framework.Test; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.objectteams.otdt.tests.otjld.AbstractOTJLDTest; public class Java7 extends AbstractOTJLDTest { @@ -46,7 +51,11 @@ public class Java7 extends AbstractOTJLDTest { // Bug 355007 - Using role as resource in try-with-resources creates bogus byte code public void testA01_tryWithResources01() { + String fileName = OUTPUT_DIR+"/p1/data.txt"; + new File(OUTPUT_DIR+"/p1").mkdirs(); + Util.writeToFile("Hello Reader", fileName); runConformTest( + false, // should not flush new String[] { "p1/TeamA01twr01.java", "package p1;\n" + @@ -54,8 +63,8 @@ public class Java7 extends AbstractOTJLDTest { "public team class TeamA01twr01 {\n" + " protected class ReaderRole implements AutoCloseable playedBy TA01twr01 {\n" + " public char[] content;\n" + - " protected void read16() throws IOException {\n" + - " content = new char[16];\n" + + " protected void read12() throws IOException {\n" + + " content = new char[12];\n" + " read(content);\n" + " }\n" + " void read(char[] chars) -> int read(char[] chars);\n" + @@ -63,12 +72,75 @@ public class Java7 extends AbstractOTJLDTest { " }\n" + " void test(TA01twr01 bfr) throws Exception {\n" + " try (ReaderRole r = new ReaderRole(bfr)) {\n" + - " r.read16();\n" + + " r.read12();\n" + + " System.out.println(String.valueOf(r.content));\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) throws Exception {\n" + + " new TeamA01twr01().test(new TA01twr01(\""+fileName+"\"));\n" + + " }\n" + + "}", + "p1/TA01twr01.java", + "package p1;\n" + + "import java.io.*;\n" + + "public class TA01twr01 extends FileReader {\n" + + " public TA01twr01(String fileName) throws IOException {\n" + + " super(fileName);\n" + + " }\n" + + " @Override\n" + + " public void close() {\n" + + " try {\n" + + " super.close();\n" + + " System.out.println(\"closed\");\n" + + " } catch (IOException ioe) {\n" + + " ioe.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in p1\\TeamA01twr01.java (at line 14)\n" + + " try (ReaderRole r = new ReaderRole(bfr)) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Argument to lifting constructor ReaderRole(TA01twr01) is not a freshly created base object (of type p1.TA01twr01); may cause a DuplicateRoleException at runtime (OTJLD 2.4.1(c)).\n" + + "----------\n", + "Hello Reader\n" + + "closed", + "", + null); + } + + // Bug 388060 - [compiler] closeable role triggers resource warning from lift method + @SuppressWarnings("unchecked") + public void testA01_tryWithResources02() { + String fileName = OUTPUT_DIR+"/p1/data.txt"; + new File(OUTPUT_DIR+"/p1").mkdirs(); + Util.writeToFile("Hello Reader", fileName); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, JavaCore.ERROR); + runTest( + new String[] { + "p1/TeamA01twr01.java", + "package p1;\n" + + "import java.io.*;\n" + + "public team class TeamA01twr01 {\n" + + " protected class ReaderRole implements AutoCloseable playedBy TA01twr01 {\n" + + " public char[] content;\n" + + " protected void read12() throws IOException {\n" + + " content = new char[12];\n" + + " read(content);\n" + + " }\n" + + " void read(char[] chars) -> int read(char[] chars);\n" + + " close -> close;\n" + + " }\n" + + " void test(String filename) throws Exception {\n" + + " try (ReaderRole r = new ReaderRole(new TA01twr01(filename))) {\n" + + " r.read12();\n" + " System.out.println(String.valueOf(r.content));\n" + " }\n" + " } \n" + " public static void main(String[] args) throws Exception {\n" + - " new TeamA01twr01().test(new TA01twr01(\"META-INF/MANIFEST.MF\"));\n" + + " new TeamA01twr01().test(\""+fileName+"\");\n" + " }\n" + "}", "p1/TA01twr01.java", @@ -89,7 +161,17 @@ public class Java7 extends AbstractOTJLDTest { " }\n" + "}", }, - "Manifest-Version\n" + - "closed"); + false, // no comp err + "", + "Hello Reader\n" + + "closed", + "", + true, // force exec + null, // libs + false, // should not flush + null, // vm args + options, + null, // requestor + true);// skip javac } } |