• Keine Ergebnisse gefunden

Exercise2ConfinedTypes Exercise1MemoryManagement PracticeSheet8:FortgeschritteneAspekteobjektorientierterProgrammierung(SS2008)

N/A
N/A
Protected

Academic year: 2022

Aktie "Exercise2ConfinedTypes Exercise1MemoryManagement PracticeSheet8:FortgeschritteneAspekteobjektorientierterProgrammierung(SS2008)"

Copied!
1
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. A. Poetzsch-Heffter Dipl.-Inform. Markus Reitz

Technische Universität Kaiserslautern Fachbereich Informatik AG Softwaretechnik

Practice Sheet 8: Fortgeschrittene Aspekte objektorientierter Programmierung (SS 2008)

Date of Issue: 03. Juni 2008 Deadline: 09. Juni 2008 (until 10 a.m. as PDF via E-Mail)

Exercise 1 Memory Management

i m p o r t j a v a . u t i l .; i m p o r t j a v a . i o .;

p u b l i c c l a s s MemoryProblem {

p r o t e c t e d S t r i n g g e t L a r g e S t r i n g ( ) { t r y {

b y t e[ ] b u f f e r=new b y t e[ 5 0 0 0 0 0 0 ] ; new Random ( ) . n e x t B y t e s ( b u f f e r ) ;

r e t u r n new S t r i n g ( b u f f e r , " ISO−8859−1 " ) ; }

c a t c h( U n s u p p o r t e d E n c o d i n g E x c e p t i o n ex ) { throw new E r r o r ( ex ) ;

} }

p u b l i c S t r i n g g e t F r a g m e n t O f L a r g e S t r i n g ( ) { r e t u r n g e t L a r g e S t r i n g ( ) . s u b s t r i n g ( 2 3 , 4 2 ) ; }

p u b l i c s t a t i c v o i d main ( S t r i n g . . . a r g s ) { L i s t<S t r i n g> r e s u l t=new A r r a y L i s t<S t r i n g>( ) ; f o r(i n t i=0 ; i<1 0 0 0 ; i++) {

S y s t e m . o u t . p r i n t ( " . " ) ;

r e s u l t . add (new MemoryProblem ( ) . g e t F r a g m e n t O f L a r g e S t r i n g ( ) ) ; }

S y s t e m . o u t . p r i n t l n ( r e s u l t . s i z e ( ) ) ; }

}

a) Why does the given code fragment produce ajava.lang.OutOfMemoryError?

b) Fix the fragment so it is executed as expected, i.e. the memory error does not occur and the list whose reference is stored in the variableresult is populated with the fragments according to the given source code.You are not allowed to alter the implementation ofgetLargeStringandgetFragmentOfLargeString. These methods have to be used by the reworked version, too.

c) What is the design rationale for the trouble-causing API method?

Exercise 2 Confined Types

Apache Ant(Another Neat Tool) is a build tool written in the Java programming language. The current version’s source code is available athttp://ant.apache.org. In this exercise, the packageorg.apache.tools.ant.taskdefs.email has to be analysed with respect to confinedness.

a) Which classes are potential candidates for confinedness and which classes can be definitely excluded from a confinedness analysis?

b) Pick two items out of the set of identified classes and check for violation or fulfillment of the criteria C1 - C8. If necessary, adapt the criteria for inner classes.

Referenzen

ÄHNLICHE DOKUMENTE

We use Erd¨ os’ probabilistic method: if one wants to prove that a structure with certain desired properties exists, one defines an appropriate probability space of structures and

The following theorem (also from Chapter 2 of slides) has an analogous formulation..

These chapters are particularly interesting because of the zoogeo- graphic situation of Cyprus as one of the big Mediterra- nean islands which had a rich endemic megafauna in the

a certain graph, is shown, and he wants to understand what it means — this corre- sponds to reception, though it involves the understanding of a non-linguistic sign;

We read with great interest the report about the late outcome of de- cellularized aortic homografts (DAH) used for aortic valve replace- ment (AVR) in middle-aged adults, one-quarter

Find the maximum common substructure of the following compounds by visual inspection and report the corresponding SMILES string that would match all compounds!. Which of the

Find the maximum common substructure of the following compounds by visual inspection and report the corresponding SMILES string that would match all compounds!. Which of the

Evidence, albeit dated, on the greater relative impact on the economy of reductions in sales taxes compared to income taxes was provided at a seminar held at the Department of