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 255193 - @StaticResource does not work if searchClasspath=true
Summary: @StaticResource does not work if searchClasspath=true
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 8.0.2
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Hurka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-10 19:34 UTC by matvei
Modified: 2015-09-16 01:26 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 matvei 2015-09-10 19:34:50 UTC
If searchClasspath parameter of @StaticResource annotation is set to true, then the annotation allows any string to pass the check, including missing and invalid paths. This behavior happens in both NetBeans Platform 8.0.2 and 8.1beta.


Examples of correct behavior (with serachClasspath defaulting to false):

@StaticResource
public static final String MISSING_FILE1 = "missing_file";
// compile time error: cannot find resource missing_file

@StaticResource
public static final String MISSING_FILE2 = "\\#!#!#:::feiuesgfafwaeadawdawdaw$$";
// compile time error: java.lang.IllegalArgumentException: Invalid relative name: \#!#!#:::feiuesgfafwaeadawdawdaw$$


Examples of incorrect behavior (with serachClasspath changed to true):

@StaticResource(searchClasspath = true)
public static final String MISSING_FILE1 = "missing_file";
// compiles without errors or warnings

@StaticResource(searchClasspath = true)
public static final String MISSING_FILE2 = "\\#!#!#:::feiuesgfafwaeadawdawdaw$$";
// compiles without errors or warnings


System information:
Product Version: NetBeans IDE 8.1 Beta (Build 201508041349)
Java: 1.8.0_60; Java HotSpot(TM) 64-Bit Server VM 25.60-b23
Runtime: Java(TM) SE Runtime Environment 1.8.0_60-b27
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
Comment 1 matvei 2015-09-10 19:45:12 UTC
Current implementation (org.netbeans.api.annotations.common.proc.StaticResourceProcessor) assumes that as long as processingEnv.getFiler().getResource(...) does not throw any exception for at least one JavaFileManager.Location, than the given file path is valid: http://hg.netbeans.org/main/file/8f9e7a4227a5/api.annotations.common/src/org/netbeans/api/annotations/common/proc/StaticResourceProcessor.java#l97

Filer.getResource() documentation seems to imply that it would indeed throw exceptions if the given file was not valid: http://docs.oracle.com/javase/7/docs/api/javax/annotation/processing/Filer.html#getResource%28javax.tools.JavaFileManager.Location,%20java.lang.CharSequence,%20java.lang.CharSequence%29

However, current implementation demonstrably does not work correctly.
Comment 2 Tomas Hurka 2015-09-11 11:31:36 UTC
This issue has nothing to do with module-system.
Comment 3 Tomas Hurka 2015-09-11 11:37:28 UTC
Fixed in profiler-main

changeset:   291365:d579e368aa64
user:        Tomas Hurka <thurka@netbeans.org>
date:        Fri Sep 11 13:36:15 2015 +0200
summary:     bugfix #255193, test for resource validity fixed
Comment 4 Quality Engineering 2015-09-16 01:26:00 UTC
Integrated into 'main-silver', will be available in build *201509160002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/d579e368aa64
User: Tomas Hurka <thurka@netbeans.org>
Log: bugfix #255193, test for resource validity fixed