Bug 233800 - [1.5][compiler] Internal compiler NPE on checkUnsafeCast
Summary: [1.5][compiler] Internal compiler NPE on checkUnsafeCast
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows Server 2003
: P3 normal with 1 vote (vote)
Target Milestone: 3.4 RC3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-24 05:37 EDT by Tadas CLA
Modified: 2008-05-31 08:42 EDT (History)
3 users (show)

See Also:
kent_johnson: review+
jerome_lanneluc: review+
Olivier_Thomann: review+


Attachments
Proposed patch (4.55 KB, patch)
2008-05-27 13:12 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tadas CLA 2008-05-24 05:37:57 EDT
Build ID: I20080516-1333

Steps To Reproduce:
    public final Object valueOf(Record record) {
        return ((FastMap.Entry<Object, Object>) record).getKey();
    }

    public final void delete(Record record) {
        remove(((FastMap.Entry<Object, Object>) record).getKey());
    }

More information:
Internal compiler error java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.ast.CastExpression.checkUnsafeCast(CastExpression.java:335) at org.eclipse.jdt.internal.compiler.ast.Expression.checkCastTypesCompatibility(Expression.java:416) at 
 org.eclipse.jdt.internal.compiler.ast.CastExpression.resolveType(CastExpression.java:495) at 
 org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:344) at 
 org.eclipse.jdt.internal.compiler.ast.ReturnStatement.resolve(ReturnStatement.java:220) at 
 org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclara
 tion.java:444) at 
 org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:191) at 
 org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:
 403) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1096) at 
 org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1184) at 
 org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:
 535) at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:743) at 
 org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:137) at 
 java.lang.Thread.run(Thread.java:619)
Comment 1 Jerome Lanneluc CLA 2008-05-24 14:45:53 EDT
We're missing some context to reproduce. Can you please provide the types Record and FastMap?
Comment 2 Tadas CLA 2008-05-25 03:38:38 EDT
@Override
public synchronized boolean remove(Object key)
{
    _cache.remove(key);
    _mruList.remove(key);
    return _map.remove(key) == key;
}

private FastMap<K,CacheNode> _cache = new FastMap<K,CacheNode>().setKeyComparator(FastComparator.DIRECT);
private FastMap<K,V> _map;
private FastList<K> _mruList = new FastList<K>();
Comment 3 Philipe Mulet CLA 2008-05-26 07:16:00 EDT
Please provide a self-contained and complete testcase,
e.g.
import java.util.*;

public class X {
	public final Object valueOf(Record record) {
		return ((FastMap.Entry<Object, Object>) record).getKey();
	}
	public final void delete(Record record) {
		remove(((FastMap.Entry<Object, Object>) record).getKey());
	}
	public synchronized boolean remove(Object key) {
		return false;
	}
}
class Record {}
abstract class FastMap implements Map {
}


The program above does NOT reproduce any problem.
Comment 4 Philipe Mulet CLA 2008-05-26 09:09:26 EDT
The trace indicates a bound parameterized type for which arguments would be null... this shouldn't occur ever.
Comment 5 Philipe Mulet CLA 2008-05-27 05:12:58 EDT
Tadas - can you pls provide a self-contained and complete testcase ?

Comment 6 Andy Carroll CLA 2008-05-27 11:50:45 EDT
The following java code below doesn't compile under Eclipse 3.4RC2 build I20080523-0100 due to a NullPointerException in CastExpression.checkUnsafeCase:335.

Note that line#382 of Expression.java explicitly passes null as the match argument to the method checkUnsafeCase, which is subsequently dereferenced, resulting in a NullPointerException.

Hope this helps.

- Andy


public class Bug233800<T>
{
   
   public void doesNotCompile(SomeInterface i)
   {
      T t = ((SomeDerivedInterface<T>)i).getItem();
   }
   
   static interface SomeInterface
   {
      
   }
   
   static interface SomeDerivedInterface<T> extends SomeInterface
   {
      T getItem();
   }
}

Comment 7 Philipe Mulet CLA 2008-05-27 13:06:57 EDT
Excellent ! Thanks
Comment 8 Philipe Mulet CLA 2008-05-27 13:10:02 EDT
Added GenericTypeTest#test1335-1337.

This is a regression from 3.4m7 and 3.3.2 (introduced in 3.4rc1).
Comment 9 Philipe Mulet CLA 2008-05-27 13:12:01 EDT
Created attachment 102193 [details]
Proposed patch

Missing trivial null check. Some parameterized type may have null argument, denoting non generic members of parameterized types.
One thing to ensure is that an unchecked warning is emitted.
Comment 10 Philipe Mulet CLA 2008-05-27 13:14:52 EDT
Regression came from fix for bug 228291 missing one null check.
Also need to backport this fix to 3.3.x maintenance, where bug 228291 was already backported (with this NPE weakness).
Comment 11 Jerome Lanneluc CLA 2008-05-27 13:26:51 EDT
Patch looks good: +1 for RC3
Comment 12 Olivier Thomann CLA 2008-05-27 15:25:52 EDT
+1
Comment 13 Philipe Mulet CLA 2008-05-28 04:21:26 EDT
Released for 3.4RC3.
Fixed
Comment 14 Philipe Mulet CLA 2008-05-28 05:42:48 EDT
Released to 3.3.x maintenance.
Comment 15 David Audel CLA 2008-05-30 11:02:39 EDT
Verified for 3.4RC4 using build I20080530-0100