This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 246583 - Type cast to X is too strong. <unknown> should be used instead
Summary: Type cast to X is too strong. <unknown> should be used instead
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-20 13:46 UTC by _ gtzabari
Modified: 2015-05-12 03:24 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ gtzabari 2014-08-20 13:46:21 UTC
Product Version: NetBeans IDE Dev (Build 201408170001)
Java: 1.8.0_20; Java HotSpot(TM) 64-Bit Server VM 25.20-b23
Runtime: Java(TM) SE Runtime Environment 1.8.0_20-b26
System: Windows 7 version 6.1 running on amd64; Cp1252; en_CA (nb)
User directory: C:\Users\Gili\AppData\Roaming\NetBeans\dev
Cache directory: C:\Users\Gili\AppData\Local\NetBeans\Cache\dev

Given:

	private Path relativeToWebapp(String path)
		throws IllegalArgumentException
	{
		Preconditions.requireThat(path, "path").isNotNull().isNotEmpty();
		String trimmedPath = path.trim();
		if (trimmedPath.startsWith("/"))
			throw new IllegalArgumentException("path must be relative: " + trimmedPath);
		ServletContext servletContext = requestScope.getServletContext();
		try
		{
			URI resource = servletContext.getResource("/" + trimmedPath).toURI();
			try
			{
				return Paths.get(resource);
			}
			catch (FileSystemNotFoundException e)
			{
				throw (FileSystemNotFoundException) new FileSystemNotFoundException(resource.toString()).initCause(e);
			}
		}
		catch (MalformedURLException | URISyntaxException e)
		{
			throw new AssertionError(e);
		}
	}

2. Netbeans hints "Type cast to FileSystemNotFoundException is too strong. <unknown> should be used instead" on the line that invokes initCause().

I expect:

1. This hint to not occur since the cast is not too strong.
2. Netbeans to assert that the proposed type is never <unknown> (so the Exception Reporter will pick up such cases).
Comment 1 Svata Dedic 2014-09-22 06:50:48 UTC
re. 1/ assuming that FileSystemNotFoundException extends IllegalArgumentException(?), wouldn't it be sufficient to cat to IllegalArgumentException instead of FSNFE ?
Comment 2 _ gtzabari 2014-09-22 17:26:16 UTC
Svata,

Yes, in this case (since the method always declares throwing IllegalArgumentException, and initCause() is declared on that superclass) then that cast would be sufficient.

You'd need to fix #2 and check that for #1 the hint suggests IllegalArgumentException.
Comment 3 Svata Dedic 2015-04-24 15:24:44 UTC
I've found a stupid code completion typo in expected type resolution code. Fixed in jet-main#20fc504e826d
Comment 4 Quality Engineering 2015-05-12 03:24:39 UTC
Integrated into 'main-silver', will be available in build *201505120001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/20fc504e826d
User: Svata Dedic <sdedic@netbeans.org>
Log: #246583: fixed typo - wrong processing of union types in catch clauses