File tree Expand file tree Collapse file tree
celements-xwiki-core/src/main/java/com/xpn/xwiki/doc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -177,8 +177,7 @@ public int getContentSize(XWikiContext context) throws XWikiException {
177177 if (this .attachment_content == null ) {
178178 this .doc .loadAttachmentContent (this , context );
179179 }
180-
181- return (int ) this .attachment_content .getSize ();
180+ return this .attachment_content .getSize ();
182181 }
183182
184183 public String getFilename () {
@@ -620,7 +619,7 @@ public void setContent(byte[] data) {
620619 try (InputStream is = new ByteArrayInputStream (data )) {
621620 setContent (is );
622621 } catch (IOException e ) {
623- throw new RuntimeException ("This should never happen " , e );
622+ throw new RuntimeException ("Failed to set attachment content from byte array " , e );
624623 }
625624 }
626625
Original file line number Diff line number Diff line change @@ -229,14 +229,19 @@ public void setContent(InputStream is) throws IOException {
229229 this .newFileItem ();
230230 IOUtils .copy (is , this .file .getOutputStream ());
231231 this .setContentDirty (true );
232- this .attachment .setFilesize (( int ) this .getSize ());
232+ this .attachment .setFilesize (this .getSize ());
233233 }
234234
235235 /**
236236 * @return the true size of the content of the attachment.
237237 * @since 2.3M2
238238 */
239- public long getSize () {
240- return this .file .getSize ();
239+ public int getSize () {
240+ long size = file .getSize ();
241+ if (size <= Integer .MAX_VALUE ) {
242+ return (int ) size ;
243+ } else {
244+ throw new IllegalStateException ("Attachment size " + size + " exceeds max value" );
245+ }
241246 }
242247}
You can’t perform that action at this time.
0 commit comments