View | Details | Raw Unified | Return to bug 313870 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 519-525 Link Here
519
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
519
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
520
					}
520
					}
521
				}
521
				}
522
			} else if (this.upstreamNullFlowInfo.isDefinitelyNonNull(local) && !flowInfo.isPotentiallyNull(local)) {    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291418
522
			} else if (this.upstreamNullFlowInfo.isDefinitelyNonNull(local) && !flowInfo.isPotentiallyNull(local) && !flowInfo.isPotentiallyUnknown(local)) {    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291418
523
				flowInfo.markAsDefinitelyNonNull(local);
523
				flowInfo.markAsDefinitelyNonNull(local);
524
				if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
524
				if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
525
					recordNullReference(local, reference, checkType);
525
					recordNullReference(local, reference, checkType);
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+78 lines)
Lines 13947-13950 Link Here
13947
		},
13947
		},
13948
		"SUCCESS");
13948
		"SUCCESS");
13949
}
13949
}
13950
13951
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=313870
13952
public void testBug313870() {
13953
	this.runConformTest(
13954
		new String[] {
13955
			"X.java",
13956
			"public class X {\n" + 
13957
			"	public static void main(String[] args) {\n" +
13958
			"		String s = \"\";\n" +
13959
			"		for (int i = 0; i < 2; i++) {\n" +
13960
            "			if (i != 0) { \n" +
13961
            "    			s = test();\n" +
13962
            "			}\n" +
13963
            "			if (s == null) {\n" +
13964
            "    			System.out.println(\"null\");\n" +
13965
            "			}\n" +
13966
            "		}\n" + 
13967
			"	}\n" + 
13968
			"	public static String test() {\n" +
13969
            "		return null;\n" +
13970
			"	}\n" + 
13971
			"}"
13972
		},
13973
		"null");
13974
}
13975
13976
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=313870
13977
public void testBug313870b() {
13978
	this.runConformTest(
13979
		new String[] {
13980
			"X.java",
13981
			"import java.io.BufferedReader;\n" +
13982
			"import java.io.IOException;\n" +
13983
			"public class X {\n" + 
13984
			"	public void main(BufferedReader bufReader) throws IOException {\n" +
13985
			"		String line = \"\";\n" +
13986
			"		boolean doRead = false;\n" +
13987
			"		while (true) {\n" +
13988
            "			if (doRead) { \n" +
13989
            "    		   line = bufReader.readLine();\n" +
13990
            "			}\n" +
13991
            "			if (line == null) {\n" +
13992
            "    			return;\n" +
13993
            "			}\n" +
13994
            "			doRead = true;\n" +
13995
            "		}\n" +
13996
			"	}\n" + 
13997
			"}"
13998
		},
13999
		"");
14000
}
14001
14002
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=313870
14003
public void testBug313870c() {
14004
	this.runConformTest(
14005
		new String[] {
14006
			"X.java",
14007
			"import java.io.File;\n" +
14008
			"public class X {\n" + 
14009
			"	public static void main(String[] args) {\n" +
14010
			"		boolean sometimes = (System.currentTimeMillis() & 1L) != 0L;\n" +
14011
			"		File file = new File(\"myfile\");\n" +
14012
			"		for (int i = 0; i < 2; i++) {\n" +
14013
            "			if (sometimes) { \n" +
14014
            "    		 	file = getNewFile();\n" +
14015
            "			}\n" +
14016
            "			if (file == null) { \n" +
14017
            "    			System.out.println(\"\");\n" +
14018
            "			}\n" +
14019
            "		}\n" +
14020
			"	}\n" +
14021
			"	private static File getNewFile() {\n" +
14022
			"		return null;\n" +
14023
			"	}\n" + 
14024
			"}"
14025
		},
14026
		"");
14027
}
13950
}
14028
}

Return to bug 313870