Bug 229042 - [buildpath] could create build path error in case of invalid external JAR format
Summary: [buildpath] could create build path error in case of invalid external JAR format
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.7 M3   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 337500 (view as bug list)
Depends on:
Blocks: 229038 321170
  Show dependency tree
 
Reported: 2008-04-28 09:56 EDT by Dani Megert CLA
Modified: 2021-08-14 03:20 EDT (History)
6 users (show)

See Also:
Olivier_Thomann: review+


Attachments
Proposed patch (22.21 KB, patch)
2010-10-20 14:24 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Updated patch (46.96 KB, patch)
2010-10-22 14:59 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Updated patch (48.26 KB, patch)
2010-10-25 04:50 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Patch with modified error message (3.04 KB, patch)
2010-10-26 09:40 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Updated tests (4.09 KB, patch)
2010-10-26 10:16 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2008-04-28 09:56:06 EDT
I20080427-2000.

Currently JDT Core allows to add JARs to the build path that aren't valid ZIPs. Only when accessing it a CoreException is thrown (see bug 229038 for details).

It would be nice if a build path error would be added at the time the JAR is added to the build path.
Comment 1 Philipe Mulet CLA 2008-04-28 15:07:52 EDT
Could be made part of classpath validation.
Comment 2 Jerome Lanneluc CLA 2008-05-07 07:52:45 EDT
We could re-use org.eclipse.jdt.internal.core.util.Messages.classpath_illegalLibraryArchive. However see bug 171136 (the message would need to be corrected)
Comment 3 Jay Arthanareeswaran CLA 2010-10-20 14:24:26 EDT
Created attachment 181326 [details]
Proposed patch

New warning added for invalid/unsupported archive content. New validation added in ClasspathEntry for this, which checks for the validity/support of the archive and raises the warning. The code could be improved by caching the invalid archive files, just like the JavaModelManager#nonChainingJars. I intend to do this along with the fix for bug 321170, as it's even more relevant there.
Comment 4 Jay Arthanareeswaran CLA 2010-10-22 14:59:50 EDT
Created attachment 181536 [details]
Updated patch

Added a cache (just like JavaModelManager#nonChainingJars) to keep track of the invalid archive files. Once an archive has been marked invalid, further calls to JavaModelManager#getZipFile(IPath) do not make any attempt to open the zip file. I.e. until the cache is reset, which typically happens during a resource change.

Another change worth mentioning is the change to the following method: DeltaProcessor.validateClasspaths(IResourceDelta, HashSet)

This change is necessary to invoke validation of a particular project (and its libraries) when a library that has contributed to the project has changed. This will ensure that a resource change event (of a contributing library) is enough to validate the project's libraries. Earlier, only a project close/open or reset of project's classpath would trigger this.

Several tests that were benefiting from the fact that we didn't bother about the validity of the archive content have been modified to accommodate this change. Note that we still allow any extensions for archives.

Olivier, please review.
Comment 5 Olivier Thomann CLA 2010-10-24 20:21:56 EDT
Patch looks good.
My only comment is about the logging of the error.
If we report a build path error, do we really need to log the error ?
Comment 6 Dani Megert CLA 2010-10-25 02:51:26 EDT
(In reply to comment #5)
> Patch looks good.
> My only comment is about the logging of the error.
> If we report a build path error, do we really need to log the error ?

I agree with Olivier.
Comment 7 Jay Arthanareeswaran CLA 2010-10-25 04:50:12 EDT
Created attachment 181618 [details]
Updated patch

Replaced the exception logging by a simple error logging. This was an already existing message and all I have done is just removed the exception to be passed to the logger. This gets logged only when the user tries to open the invalid archive file. This fixes bug 321170 too.

Will release after rerunning the tests.
Comment 8 Jay Arthanareeswaran CLA 2010-10-25 06:39:37 EDT
Released in HEAD for 3.7M3.
Comment 9 Dani Megert CLA 2010-10-26 07:00:45 EDT
Verified in I20101025-1800: it works but the message:

  Illegal type of archive for required library: {0} in project {1}

is not very intuitive as has already been noted in comment 2 and in bug 171136.

The problem is not about the "type" but rather the "content".
Comment 10 Jay Arthanareeswaran CLA 2010-10-26 07:55:40 EDT
(In reply to comment #9)
> Verified in I20101025-1800: it works but the message:
> 
>   Illegal type of archive for required library: {0} in project {1}
> 
> is not very intuitive as has already been noted in comment 2 and in bug 171136.
> 
> The problem is not about the "type" but rather the "content".

How about this:

Unsupported archive content in library: {0} in project {1}
Comment 11 Jay Arthanareeswaran CLA 2010-10-26 08:38:11 EDT
(In reply to comment #10)
> How about this:
> 
> Unsupported archive content in library: {0} in project {1}

Perhaps this sounds better:
Unsupported archive format: {0} in project {1}
Comment 12 Dani Megert CLA 2010-10-26 09:06:50 EDT
(In reply to comment #11)
> (In reply to comment #10)
> > How about this:
> > 
> > Unsupported archive content in library: {0} in project {1}
> 
> Perhaps this sounds better:
> Unsupported archive format: {0} in project {1}

Nope: {0} is not an archive format ;-)

The reported problem not only covers invalid format issues but also the case where the file cannot be read for whatever reason.
==>
Archive for required library: ''{0}'' in project ''{1}'' cannot be read or is not a valid ZIP file
Comment 13 Jay Arthanareeswaran CLA 2010-10-26 09:40:03 EDT
Created attachment 181725 [details]
Patch with modified error message

New error introduced as suggested in comment #12.
Comment 14 Jay Arthanareeswaran CLA 2010-10-26 10:16:28 EDT
Created attachment 181732 [details]
Updated tests

Test cases have been updated too. Will release after running all tests.
Comment 15 Jay Arthanareeswaran CLA 2010-10-26 11:00:22 EDT
As Olivier mentioned, I think I can remove the error message we printing in the log file too at this point. 

Dani, what do you think about this?
Comment 16 Dani Megert CLA 2010-10-26 11:27:28 EDT
(In reply to comment #15)
> As Olivier mentioned, I think I can remove the error message we printing in the
> log file too at this point. 
> 
> Dani, what do you think about this?
In comment 6 I agreed to it but given that the reported problem covers several scenarios, it might be good to log the error.
Comment 17 Jay Arthanareeswaran CLA 2010-10-27 00:59:06 EDT
Released in HEAD for 3.7M3
Comment 18 Dani Megert CLA 2010-10-28 02:36:31 EDT
Verified in I20101028-1800.
Comment 19 Dani Megert CLA 2011-03-15 02:51:34 EDT
*** Bug 337500 has been marked as a duplicate of this bug. ***